Greasy Fork

Spirtum Sancti ZA BEST!

Spirtum Sancti troops count!

当前为 2020-05-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         Spirtum Sancti ZA BEST!
// @namespace    http://tampermonkey.net/
// @version      0.47
// @description  Spirtum Sancti troops count!
// @author       Big Papa
// @match        https://www.tampermonkey.net/index.php?version=4.9.6095&ext=fire&updated=true
// @include 			 https://en126.grepolis.com/*
// @exclude        forum.*.grepolis.*/*
// @exclude        wiki.*.grepolis.*/*
// @connect        spirtumzone.000webhostapp.com
// @grant          GM.xmlHttpRequest
// @require  https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// ==/UserScript==
setTimeout(function() {
'use strict';
var interest = ['archer', 'attack_ship', 'big_transporter', 'bireme', 'calydonian_boar', 'catapult', 'centaur', 'cerberus', 'chariot', 'colonize_ship', 'demolition_ship', 'fury', 'godsent', 'griffin', 'harpy', 'hoplite', 'manticore', 'medusa', 'minotaur', 'pegasus', 'rider', 'sea_monster', 'slinger', 'small_transporter', 'sword', 'trireme', 'zyklop'];
    let homeUnits = new Map();


function addToMap(key, value, map) {
    //if the list is already created for the "key", then uses it
    //else creates new list for the "key" to store multiple values in it.
    map[key] = map[key] || [];
    map[key].push(value);
}
var suma = new Map();

function doSum(map) {
    map.reduce(function(acc, val) { return acc + val; }, 0)
}

var allUnits = new Map();


/*   let collections = MM.getCollections();
console.log(collections.Units);
*/
let models = MM.getModels();
var name;

for (let v in models['Player'])
{
    name = models['Player'][v]['attributes']['name'];

}

/* console.log(models['Player']);
console.log(models['Units']);
console.log(models['TownIdList']);
*/



for (let v in models['Units'])
{
if( models['Units'][v]['attributes']['current_town_id'] == models['Units'][v]['attributes']['home_town_id'] && models['Units'][v]['attributes']['current_town_player_name'] == name)
 for (let homeU in models['Units'][v]['attributes'])
 {
     if (interest.indexOf(homeU) >= 0)
     addToMap(homeU, models['Units'][v]['attributes'][homeU],  homeUnits);
 }
}

  




var sumaAllUnits = new Map();
for (var it in homeUnits){
addToMap(it, homeUnits[it].reduce(function(acc, val) { return acc + val; }, 0), suma);
}

var townIds = new Map();
for (let v in models['TownIdList'])
{
    townIds = models['TownIdList'][v]['attributes']['town_ids'];
}


for (let v in models['Units'])
{
 for (let all in models['Units'][v]['attributes'])
 {
     if(townIds.indexOf(models['Units'][v]['attributes']['home_town_id']) >= 0)
     if (interest.indexOf(all) >= 0)
     addToMap(all, models['Units'][v]['attributes'][all],  allUnits);
 }
}




for (var at in allUnits){
addToMap(at, allUnits[at].reduce(function(acc, val) { return acc + val; }, 0), sumaAllUnits);
}










sumaAllUnits.forEach((value, key) => {
    var keys = key.split('.'),
        last = keys.pop();
    keys.reduce((r, a) => r[a] = r[a] || {}, object)[last] = value;
});


addToMap('name', name,  sumaAllUnits);
var seri = JSON.stringify(sumaAllUnits);


console.log(seri);
var server_url = 'https://spirtumzone.000webhostapp.com/units.php';



    GM.xmlHttpRequest ( {
    method:     "POST",
    url:        server_url,
    data:       seri,
    headers:    {
        "Content-Type": "application/json"
    },
    onload:     function (response) {

    },
    onerror:    function(reponse) {

    }
} );

}, 20000);