-
Notifications
You must be signed in to change notification settings - Fork 1
/
trader_tool.user.js
142 lines (133 loc) · 4.84 KB
/
trader_tool.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// ==UserScript==
// @name Asylamba Trader Tools
// @namespace Akulen
// @include http://game.asylamba.com/s*/profil*
// @include http://game.asylamba.com/s*/bases/view-spatioport/mode-search*
// @include http://game.asylamba.com/s*/bases/view-spatioport/mode-search/show-result*
// @include http://s*.asylamba.com/profil*
// @include http://s*.asylamba.com/bases/view-spatioport/mode-search*
// @include http://s*.asylamba.com/bases/view-spatioport/mode-search/show-result*
// @version 0.4.1
// @updateURL https://github.com/Akulen/Asylamba-User-Script/raw/master/trader_tool.user.js
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @grant GM_xmlhttpRequest
// @author Akulen
// ==/UserScript==
var server = /\/s([0-9]*)\./.exec(window.location.href)[1];
var page = /asylamba\.com\/(.*)$/.exec(window.location.href)[1];
var dataurl = "";
switch(server)
{
case "11":
dataurl = "https://api.myjson.com/bins/1hzv3";
break;
case "12":
dataurl = "https://api.myjson.com/bins/4l6no";
break;
case "14":
dataurl = "https://api.myjson.com/bins/13j0o9";
break;
}
function main ()
{
$.get(dataurl, function(data, textStatus, jqXHR) {
if(page == "profil")
update(data);
else if(page == "bases/view-spatioport/mode-search")
config();
else if(page == "bases/view-spatioport/mode-search/show-result")
{
config();
addInfo(data);
}
});
}
window.setInterval(main, 5000);
main();
function update(data)
{
var player = /Profil — ([^—]*)—/.exec($("title").html())[1];
player = player.slice(0, -1);
if(typeof data.players == "undefined")
data.players = [];
var playerId = data.players.length;
for(var i = 0; i < playerId; ++i)
if(data.players[i].name == player)
playerId = i;
if(playerId == data.players.length)
data.players.push({"name":player, "planets":[]});
$("div[class='component hasMover']").map(function() {
var planetName = $(this).children().first().children().first().next().html();
if($(this).children().last().children().first().children().last().prev().html() == "Spatioport")
{
var roads = $(this).children().last().children().first().children().last().children().first().next().html();
var usedRoads = parseInt(/^[0-9]*/.exec(roads));
var totalRoads = parseInt(/[0-9]*$/.exec(roads));
var availRoads = totalRoads - usedRoads;
var planetId = data.players[playerId].planets.length;
for(var i = 0; i < planetId; ++i)
if(data.players[playerId].planets[i].name == planetName)
planetId = i;
if(planetId == data.players[playerId].planets.length)
data.players[playerId].planets.push({"name":planetName, "roads":0});
data.players[playerId].planets[planetId].roads = availRoads;
}
});
$.ajax({
url:dataurl,
type:"PUT",
data:JSON.stringify(data),
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(data, textStatus, jqXHR){
console.log("coin");
}
});
}
function config()
{
$("#search-rc-min-dist").attr("value", "100");
switch(server)
{
case "11":
$("#ckb-faction-1").attr("checked", "");
$("#ckb-faction-4").attr("checked", "");
$("#ckb-faction-8").removeAttr("checked");
$("#ckb-faction-9").removeAttr("checked");
break;
case "12":
$("#ckb-faction-4").attr("checked", "");
$("#ckb-faction-8").attr("checked", "");
$("#ckb-faction-10").attr("checked", "");
$("#ckb-faction-11").attr("checked", "");
$("#ckb-faction-12").attr("checked", "");
break;
}
}
function addInfo(data)
{
$("a.player").map(function() {
var playerName = $(this).children().first().next().html();
var planetName = $(this).children().last().prev().html();
var playerId = data.players.length;
for(var i = 0; i < playerId; ++i)
if(data.players[i].name == playerName)
playerId = i;
if(playerId < data.players.length)
{
var planetId = data.players[playerId].planets.length;
for(var i = 0; i < planetId; ++i)
if(data.players[playerId].planets[i].name == planetName)
planetId = i;
if(planetId < data.players[playerId].planets.length)
{
$(this).prepend('<span class="picto color1" style=" position: absolute; top: 11px; right: 10px; height: 35px; width: 35px; line-height: 35px; padding: 5px; border-radius: 100%; font-size: 1pc; text-align: center; color: #fff; text-decoration: none; background: #510816;" href="#">' + data.players[playerId].planets[planetId].roads + '</span>');
}
}
if($(this).children().last().html()[$("a.player").children().last().html().length - 1] == '.')
{
var cout = 8000 * parseInt(/[0-9]*/.exec($(this).children().last().html()));
$(this).children().last().html($(this).children().last().html() + ' → ' + cout.toString() + ' <img src="http://s' + server + '.asylamba.com/public/media/resources/credit.png" alt="" class="icon-color" name="done">');
}
});
}