-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEstiah2Script_cn.user.js
More file actions
252 lines (223 loc) · 9.86 KB
/
Copy pathEstiah2Script_cn.user.js
File metadata and controls
252 lines (223 loc) · 9.86 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// ==UserScript==
// @name Estiah2Script_cn
// @namespace https://github.com/wxyz202
// @description the greasemonkey script for estiah2
// @include /^https?://cn\.estiah2\.com/zh/.*/
// @include /^https?://www\.estiah2\.com/zh/.*/
// @version 0.2
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @require http://code.jquery.com/jquery-1.11.0.min.js
// ==/UserScript==
var JQ = jQuery.noConflict();
// global function
var getCharacterName = function(){
JQ(".wf-dashboard .resume .name").text();
};
var setCharacterValue = function(key, value){
GM_setValue(getCharacterName() + ":" + key, value);
};
var getCharacterValue = function(key, defaultValue){
return GM_getValue(getCharacterName() + ":" + key, defaultValue);
};
var PageHandler = function(pattern, init_func){
this.pattern = pattern;
this.init_func = init_func;
};
PageHandler.prototype.match = function() {
var pathname = JQ(location).attr('pathname');
return this.pattern.test(pathname);
};
PageHandler.prototype.init = function() {
this.init_func();
};
// Deck
var Deck = new PageHandler(/^\/zh\/character\/deck/, function(){
var do_with_all_card = function(func){
var count_button = JQ(".dataview .dataview-footbar .dataview-count-enabled");
var current_count = count_button.text();
count_button.text("10000");
count_button.attr("data-count", "10000");
count_button.click();
func();
count_button.text(current_count);
count_button.attr("data-count", current_count);
count_button.click();
JQ('html, body').animate({
scrollTop: JQ(".deck-floater .s-title").offset().top
}, 0);
//window.scrollTo(0, 0);
};
var extra_gear_init = function(){
JQ(".deck-floater").append(JQ("<div><textarea id='estiah2-script-deck-textarea'></textarea><button id='estiah2-script-deck-export'>导出</button><button id='estiah2-script-deck-import'>导入</button><span id='estiah2-script-deck-info'></span></div>"));
JQ("#estiah2-script-deck-export").click(function(){
JQ("#estiah2-script-deck-info").text("正在导出");
var scard_list = [];
JQ(".deck-floater .deck-scards .scard").each(function(index, element){
scard_list.push(JQ(element).attr("data-id"));
});
var card_list = {};
JQ(".deck-floater .deck-cards .card").each(function(index, element){
var card_id = JQ(element).attr("data-id");
var card_count = JQ(element).find(".count").text();
card_list[card_id] = card_count;
});
var deck_text = JSON.stringify({"scards": scard_list, "cards": card_list});
JQ("#estiah2-script-deck-textarea").val(deck_text);
JQ("#estiah2-script-deck-info").text("导出成功");
});
JQ("#estiah2-script-deck-import").click(function(){
JQ("#estiah2-script-deck-info").text("正在导入");
JQ(".deck-floater .deck-clear").click();
var deck_text = JQ("#estiah2-script-deck-textarea").val().trim();
var deck;
try {
deck = JSON.parse(deck_text);
} catch (e) {
JQ("#estiah2-script-deck-info").text("装备解析错误");
}
do_with_all_card(function(){
var scard_list = deck["scards"];
if(!function(){
for (var i in scard_list) {
var scard = scard_list[i];
var found = false;
var element = JQ(".dataview .dataview-content .scard[data-id='" + scard + "']");
if (element.length) {
element.find(".add-scard").click();
found = true;
}
if (!found) {
JQ("#estiah2-script-deck-info").text("资源" + scard + "没找到");
return false;
}
}
return true;
}()) {
return;
}
var card_list = deck["cards"];
if(!function(){
for (var card in card_list) {
var count = card_list[card];
var found = false;
var element = JQ(".dataview .dataview-content .card[data-id='" + card + "']");
if (element.length) {
var max_count = element.find(".count").text().slice(-1);
if (parseInt(count) > parseInt(max_count)) {
JQ("#estiah2-script-deck-info").text("卡" + card + "超过上限");
return false;
} else {
for (var j = parseInt(count); j > 0; j--){
element.find(".add-card").click();
}
found = true;
}
}
if (!found) {
JQ("#estiah2-script-deck-info").text("卡" + card + "没找到");
return false;
}
}
return true;
}()) {
return;
}
});
JQ("#estiah2-script-deck-info").text("导入成功");
});
};
var external_deck_builder_init = function(){
do_with_all_card(function(){
var add_external_deck_builder_button = function(token){
JQ(".s-cr2z1 .s-title").append(JQ("<a style='border-style:solid;border-width:1px;border-color:#497ea0;font-size:16px;text-decoration:none' target='_blank' href='http://112.124.105.6/deck?token=" + token + "'><span style='padding:0 10px;height:20px;color:#8dd2ff;'>外部组卡器</span></a>"));
window.scrollTo(0, 0);
};
var scards = [];
JQ(".dataview .dataview-content .scard").each(function(index, element){
scards.push(parseInt(JQ(element).attr("data-id")));
});
var cards = [];
JQ(".dataview .dataview-content .card").each(function(index, element){
cards.push({
id: parseInt(JQ(element).attr("data-id")),
num: parseInt(JQ(element).find(".count").text().slice(-1))
});
});
var data = JSON.stringify({
cards: cards,
scards: scards
});
if (getCharacterValue("deck") == data && getCharacterValue("deckExpireTimestamp") > Date.now()){
add_external_deck_builder_button(getCharacterValue("deckToken"));
} else {
GM_xmlhttpRequest({
method: "POST",
url: "http://112.124.105.6/deck",
headers: {
"Content-Type": "application/json"
},
data: data,
onload: function(response){
var responseData = JSON.parse(response.responseText).data;
var token = responseData.token;
var expireTimestamp = responseData.expireTimestamp;
setCharacterValue("deck", data);
setCharacterValue("deckToken", token);
setCharacterValue("deckExpireTimestamp", expireTimestamp);
add_external_deck_builder_button(token);
}
});
}
});
};
extra_gear_init();
external_deck_builder_init();
});
// inventory
var Inventory = new PageHandler(/^\/zh\/character\/inventory/, function(){
var sell_common_item_init = function(){
JQ(".s-cr2z1 .s-title").append(JQ("<span style='border-style:solid;border-width:1px;border-color:#497ea0;font-size:16px'><span style='padding:0 10px;height:20px;color:#8dd2ff;cursor:pointer;' id='estiah2-script-inventory-sell-common'>出售所有普通物品</span></span>"));
JQ("#estiah2-script-inventory-sell-common").click(function(){
var common_item_list = [];
JQ(".s-cr2z1 .s-item .rarity-common").parent().each(function(index, element){
common_item_list.push(JQ(element).attr("data-uid"));
});
var current_index = common_item_list.length - 1;
var sell_item = function(item_id, callback){
var item_element = JQ(".s-cr2z1 .s-item[data-uid=\"" + item_id + "\"]");
item_element.get(0).dispatchEvent(new MouseEvent("mouseover"));
item_element.click();
item_element.get(0).dispatchEvent(new MouseEvent("mouseout"));
window.setTimeout(function(){
JQ(".s-cr2z2 .s-floater .locked-false .numeric-updown .numeric-set").click();
JQ(".s-cr2z2 .s-floater .locked-false .sell-form .ajaxform-submit").click();
callback();
}, 500);
};
var f = function(){
sell_item(common_item_list[current_index], function(){
if (current_index > 0) {
current_index--;
window.setTimeout(function(){
f();
}, 2500);
}
});
};
f();
});
};
sell_common_item_init();
});
// function list
var function_list = [Deck, Inventory];
JQ(document).ready(function(){
for (var i in function_list) {
var f = function_list[i]
if (f.match()) {
f.init();
}
}
});