forked from Akulen/Asylamba-User-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
better fleet_user_script.user.js
220 lines (135 loc) · 8.3 KB
/
better fleet_user_script.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// ==UserScript==
// @name better fleet
// @version 0.0.3
// @description better fleet
// @author ChickenStorm
// @match http://game.asylamba.com/beta/fleet/*
// @grant none
// ==/UserScript==
var d = document.getElementsByTagName("div");
var im = document.getElementsByTagName("img");
var text = "";
var j = null;
var jDoc = null;
var jIm = null;
////
//var textS = ""
function presetHTML(shipArray,imgSrc,name){
//shipArray : [[id,nombre],[id,nombre],...]
//var presetCode = ""
/*for (var i in shipArray){
presetCode += "squadronTransfer.move(\"btc\","+shipArray[i][0]+", "+shipArray[i][1]+");";
}
*/
var shipArrayText = ""
shipArrayText += "["
for (var i in shipArray){
shipArrayText += "[" +shipArray[i].join(",")+"],"
}
shipArrayText = shipArrayText.substring(0,shipArrayText.length-1) // remouve the last comma
shipArrayText += "]"
var presetCode = "var shipArrayIn = "+shipArrayText+";for (var i =0;i<=11;++i) {var shipSquadronQuantity = parseInt(squadronTransfer.obj.squadron.find(\"a:nth-child(\" + (i + 1) + \") .quantity\").text());var quantityOfShipToPlace = 0;for(var j in shipArrayIn){if (shipArrayIn[j][0] == i) {quantityOfShipToPlace = shipArrayIn[j][1];}}var shipDock = parseInt(squadronTransfer.obj.dock.find(\"a:nth-child(\" + (i + 1) + \") .quantity\").text());var shipQuantityToMove = Math.max(Math.min(quantityOfShipToPlace - shipSquadronQuantity,shipDock),-shipSquadronQuantity);if (shipQuantityToMove > 0 ) {squadronTransfer.move(\"btc\",i,shipQuantityToMove);}else if(shipQuantityToMove < 0){squadronTransfer.move(\"ctb\",i,-shipQuantityToMove);}}"
//var presetCode = "readableMoveFunction("+shipArrayText+");"
return "<a data-ship-id='0' onclick = '"+presetCode+"'href='#'><img alt='' src='"+imgSrc+"'></img><span class='text'><span class='quantity'>1</span><span>"+name+"</span></span>";
}
function initUserScript(){
for(var i in d){
if (d[i].className == "body") {
//alert(i)
j = i;
}
if (d[i].className == "list-ship dock") {
jDoc = i;
}
}
for(var i in im){
if (im[i].className == "right") {
//alert(i)
jIm = i;
}
}
var textP =d[jDoc].innerHTML
for(var i = 0; i< 12; i++){
var text = textP;
var pos = text.search("<span class=\"quantity\">");
var temp = text.substring(0,pos);
var tempT = text.substring(pos,text.length);
var pos2 = tempT.search("</span>");
var temp2 = tempT.substring(pos2+7,tempT.length);
textP = temp + "<span class='quantity'><input style='width:50px;' id='in"+i +"' ></span>" + temp2;
}
/*function shipMove(shipId){
var input = parseInt(document.getElementById("in"+shipId).value)
//alert(input)
if (!isNaN(input) && input!=0) {
if (input >0) {
squadronTransfer.move('btc', shipId, input);
}
else{
squadronTransfer.move('ctb', shipId, -input)
}
}
}*/
for(var i = 0; i< 12; i++){
var pos = textP.search(" data-ship-id=");
var Tleft = textP.substring(0,pos);
var Trigth = textP.substring(pos+1,textP.length);
var shipMoveCode = "var input = parseInt(document.getElementById(\"in\"+"+i+").value);if (!isNaN(input) && input!=0) {if (input >0) {squadronTransfer.move(\"btc\", "+i+", input);}else{squadronTransfer.move(\"ctb\", "+i+", -input)}}";
textP = Tleft + "onclick='"+shipMoveCode+"';" +Trigth;
textP = textP.replace("class=\"empty\"","");
}
/**
var presetEnderCode = "squadronTransfer.move(\"btc\", 0, 2);squadronTransfer.move(\"btc\", 2, 17);squadronTransfer.move(\"btc\", 7, 1);";
var presetChimer = "squadronTransfer.move(\"btc\", 2, 33)"
var presetPhenix = "squadronTransfer.move(\"btc\", 11, 1); squadronTransfer.move(\"btc\", 0, 2)"
var presetHydre = "squadronTransfer.move(\"btc\", 9, 1); squadronTransfer.move(\"btc\", 0, 4)"
var textPPreset = "<a data-ship-id='0' onclick = '"+presetEnderCode+"'href='#'><img alt='' src='https://dl.dropboxusercontent.com/u/110049848/user_script_ressouces/picture/ender.png'></img><span class='text'><span class='quantity'>1</span><span>Ender</span></span>";
textPPreset += "<a data-ship-id='0' onclick = '"+presetChimer+"'href='#'><img alt='' src='https://dl.dropboxusercontent.com/u/110049848/user_script_ressouces/picture/chimere.png'></img><span class='text'><span class='quantity'>1</span><span>33 chimeres</span></span>";
textPPreset += "<a data-ship-id='0' onclick = '"+presetPhenix+"'href='#'><img alt='' src='https://dl.dropboxusercontent.com/u/110049848/user_script_ressouces/picture/phenix.png'></img><span class='text'><span class='quantity'>1</span><span>phenix (pe)</span></span>";
textPPreset += "<a data-ship-id='0' onclick = '"+presetHydre+"'href='#'><img alt='' src='https://dl.dropboxusercontent.com/u/110049848/user_script_ressouces/picture/hydre.png'></img><span class='text'><span class='quantity'>1</span><span>hydre (pe)</span></span>";
*/
//image sources : hydre http://shannavi.centerblog.net/rub-hydres-.html
// endre : http://minecraft.gamepedia.com/Eye_of_Ender
// chimere new : http://idraemir.blogspot.ch/2011/05/la-chimere.html old:http://bibliotheque-imperiale.com/index.php?title=Chim%C3%A8re
// phenix : http://www.lemondededuralas.org/t460-le-phenix-enchaine-03
var textPPreset = ""
textPPreset += presetHTML([[]],"","vide");
textPPreset += presetHTML([[0,2],[2,17],[7,1]],"https://dl.dropboxusercontent.com/u/110049848/user_script_ressouces/picture/ender.png","Ender");
textPPreset += presetHTML([[2,33]],"https://dl.dropboxusercontent.com/u/110049848/user_script_ressouces/picture/chimere.png","33 ch");
textPPreset += presetHTML([[0,4],[9,1]],"https://dl.dropboxusercontent.com/u/110049848/user_script_ressouces/picture/hydre.png","hydre (pe)");
textPPreset += presetHTML([[0,2],[11,1]],"https://dl.dropboxusercontent.com/u/110049848/user_script_ressouces/picture/phenix.png","ph (pe)");
d[j].style.width = "600px"; // by defalut 300px
d[j].innerHTML += "<div class='list-ship test'> "+ textP+ "</div>";
d[j].innerHTML += "<div class='list-ship test'> "+ textPPreset+ "</div>";
im[jIm].style.left ='190px'; // sometimes not working ??? works for me but not in the form of user script but with "ardoise js" of firefox
render.column.number +=1;
squadronTransfer.init();
// document.getElementsByTagName('body')[0].innerHTML += '<script>'+shipMove+'</script>'
}
initUserScript()
//////
/*
var olQuantity = parseInt(this.obj.squadron.find('a:nth-child(' + (shipId + 1) + ') .quantity').text());
var orQuantity = parseInt(this.obj.dock.find('a:nth-child(' + (shipId + 1) + ') .quantity').text());
*/
function readableMoveFunction(shipArray){ // not used but "readable" verion of the preset Code
var shipArrayIn = shipArray; /* for convertion */
for (var i =0;i<=11;++i) {
var shipSquadronQuantity = parseInt(squadronTransfer.obj.squadron.find('a:nth-child(' + (i + 1) + ') .quantity').text());
var quantityOfShipToPlace = 0; /* if not found in shipArrayIn then equal to 0 */
for(var j in shipArrayIn){
if (shipArrayIn[j][0] == i) {
quantityOfShipToPlace = shipArrayIn[j][1];
}
}
var shipDock = parseInt(squadronTransfer.obj.dock.find('a:nth-child(' + (i + 1) + ') .quantity').text());
var shipQuantityToMove = Math.max(Math.min(quantityOfShipToPlace - shipSquadronQuantity,shipDock),-shipSquadronQuantity); /* btc */
if (shipQuantityToMove > 0 ) {
squadronTransfer.move('btc',i,shipQuantityToMove);
}
else if(shipQuantityToMove < 0){
squadronTransfer.move('ctb',i,-shipQuantityToMove);
}
//if 0 do nothing
}
}