-
Notifications
You must be signed in to change notification settings - Fork 2
/
evolve_listener.user.js
390 lines (338 loc) · 17.1 KB
/
evolve_listener.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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
// ==UserScript==
// @name 数据监听
// @namespace http://tampermonkey.net/
// @version 1.1.1.1
// @description try to take over the world!
// @downloadURL https://github.com/DSLM/evolve-script/raw/master/evolve_listener.user.js
// @author DSLM
// @match https://g8hh.github.io/evolve/
// @match https://pmotschmann.github.io/Evolve/
// @grant none
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @require https://code.jquery.com/ui/1.12.1/jquery-ui.min.js
// ==/UserScript==
(function($) {
'use strict';
var LM_times = 0;
var LM;
var currStytle = {};
var evalList = {default:{name:"默认求值", desc:"输入js代码求值", func:(str) => {try{return eval(str);}catch(e){return e;}}},
mainScriptCur:{name:"脚本设置当前值", desc:"需搭配修改版脚本", func:(str) => {try{return window.currentScriptSetting[str];}catch(e){return e;}}}
};
var dataMap = {note:0, type:1, eval:2};
var nowOverrides = [];
//手动CSS颜色
let cssData = {
dark:{background_color:"#1f2424", alt_color:"#0f1414", primary_border:"#ccc", primary_color:"#fff"},
light:{background_color:"#fff", alt_color:"#ddd", primary_border:"#000", primary_color:"#000"},
night:{background_color:"#000", alt_color:"#1b1b1b", primary_border:"#ccc", primary_color:"#fff"},
darkNight:{background_color:"#000", alt_color:"#1b1b1b", primary_border:"#ccc", primary_color:"#b8b8b8"},
redgreen:{background_color:"#000", alt_color:"#1b1b1b", primary_border:"#ccc", primary_color:"#fff"},
gruvboxLight:{background_color:"#fbf1c7", alt_color:"#f9f5d7", primary_border:"#3c3836", primary_color:"#3c3836"},
gruvboxDark:{background_color:"#282828", alt_color:"#1d2021", primary_border:"#3c3836", primary_color:"#ebdbb2"},
orangeSoda:{background_color:"#131516", alt_color:"#292929", primary_border:"#313638", primary_color:"#EBDBB2"},
dracula:{background_color:"#282a36", alt_color:"#1d2021", primary_border:"#44475a", primary_color:"#f8f8f2"}
};
//全局CSS
const padTB = "0.5em";
const padLR = "0.75em";
let styleLines = `#sideWindow>div:not(#titleListWindow) {padding: ${padTB} ${padLR};} #sideWindow>div>div.has-text-caution.has-text-warning{background-color:#7957d5;color:#fff !important;}`;
Object.keys(cssData).forEach((theme) => {
styleLines += `html.${theme} #sideWindow>div:not(#titleListWindow) {background-color:${cssData[theme].alt_color}; border: ${cssData[theme].primary_border} solid 1px;}`;
styleLines += `html.${theme} #titleListWindow>div {background-color:${cssData[theme].alt_color};}`;
});
let styles = $(`<style type='text/css' id='sideWindowCSS'>${styleLines}</style>`);
if($("#sideWindowCSS"))
{
$("#sideWindowCSS").remove();
}
$("head").append(styles);
//各种统计的的CSS
let bodyStytle = document.body.currentStyle ? document.body.currentStyle : window.getComputedStyle(document.body, null);
let listenerColor = "";
Object.keys(cssData).forEach((theme) => {
//表格表头的CSS
listenerColor += `html.${theme} .has-text-plain th {
color: ${cssData[theme].primary_color};
font-weight: ${bodyStytle["font-weight"]};
font-size: ${bodyStytle["font-size"]};
padding: 0.5em 0.75em;
}`;
});
styles = $(`<style type='text/css' id='listenerCSS'>
${listenerColor}
#listenerWindow>div>div.has-text-advanced.has-text-success {
background-color:#7957d5;
color:#fff !important;
}
</style>`);
if($("#listenerCSS"))
{
$("#listenerCSS").remove();
}
$("head").append(styles);
LM = window.setInterval(listenerMainFunc, 250);
function listenerMainFunc()
{
LM_times = LM_times + 1;
//判断是否需要初始化
if(LM_times > 500)
{
var LM_temp = LM
LM_times = 0;
LM = window.setInterval(listenerMainFunc, 250);
clearInterval(LM_temp)
return;
}
//未完全加载
if(evolve.global == undefined) return;
//共用窗口
let sideWindow = $("#sideWindow");
if(sideWindow.length === 0)
{
sideWindow = $("<div id='sideWindow' style='position: absolute; top: 20%; height: 60%; right: 0px; display:flex; flex-direction: row; justify-content: flex-end; align-items: flex-end;'><div id='titleListWindow' style='display:flex; flex-direction: column; justify-content: flex-end; align-items: flex-end;'></div></div>");
$("body").append(sideWindow);
}
//独有窗口
let smallListenerTitle = $("#smallListenerTitle");
let listenerContent = $("#listenerContent");
let listenerWindow = $("#listenerWindow");
if(smallListenerTitle.length === 0)
{
smallListenerTitle = $("<div id='smallListenerTitle' class='has-text-caution' onclick='(function (){$(\"#titleListWindow\").children().removeClass(\"has-text-warning\");if($(\"#listenerContent\").css(\"display\") == \"none\"){$(\".sideContentWindow\").hide();$(\"#listenerContent\").show();$(\"#smallListenerTitle\").addClass(\"has-text-warning\");}else{$(\"#listenerContent\").hide();}})()'>监听</div>");
listenerContent = $(`<div id='listenerContent' class='sideContentWindow' style='height: 100%; display: none;'><div id='listenerFlexContent' style='height: 100%;display:flex;flex-direction: column;justify-content: space-between;'><div class='has-text-caution' style='text-align: center; padding-bottom: ${padTB};'>数据监听</div></div></div>`);
listenerWindow = $(`<div id='listenerWindow' style='height: 0; display:flex; flex-direction: row; justify-content: flex-end; align-items: flex-end; flex-grow: 1;'><div id='listenerTitleListWindow' style='height: 100%; display: flex; flex-direction: column; justify-content: flex-end; padding-left: ${padLR};' align='right'></div></div>`);
listenerContent.children().eq(0).append(listenerWindow);
sideWindow.prepend(listenerContent);
$("#titleListWindow").append(smallListenerTitle);
}
mainListener();
overrideListener();
}
function overrideListener()
{
let settings = JSON.parse(localStorage.getItem("settings"));
if(settings == null)
{
return;
}
let smallOverrideListenerTitle = $("#smallOverrideListenerTitle");
let overrideListenerButton = $("#overrideListenerButton");
let overrideListenerTable = $("#overrideListenerTable");
let overrideListenerTableBody = $("#overrideListenerTableBody");
//还没有
if($("#smallOverrideListenerTitle").length == 0)
{
let smallOverrideListenerTitle = $("<div id='smallOverrideListenerTitle' class='has-text-advanced' onclick='(function (){$(\"#listenerTitleListWindow\").children().removeClass(\"has-text-success\");if($(\"#overrideListenerContent\").css(\"display\") == \"none\"){$(\".sideListenerWindow\").hide();$(\"#overrideListenerContent\").show();$(\"#smallOverrideListenerTitle\").addClass(\"has-text-success\");}else{$(\"#overrideListenerContent\").hide();}})()'>脚本高级设置</div>");
let overrideListenerContent = $("<div id='overrideListenerContent' class='vscroll sideListenerWindow' style='height: 100%; display: none;'></div>");
overrideListenerButton = $('<div id="overrideListenerButton" style="float: top; display:flex; flex-direction: row; justify-content: flex-start; align-items: center;"></div>');
overrideListenerTable = $(`<table><thead class="has-text-plain"><tr><th>内部名</th><th>定位</th></tr></thead><tbody id="overrideListenerTableBody"></tbody></table>`);
overrideListenerContent.append(overrideListenerTable);
$("#listenerWindow").prepend(overrideListenerContent);
$("#listenerTitleListWindow").append(smallOverrideListenerTitle);
overrideListenerTableBody = $("#overrideListenerTableBody");
}
//列表是否更新
let overrideListenerList = settings.overrides;
if(nowOverrides.toString() == Object.keys(overrideListenerList).toString())
{
return;
}
else
{
nowOverrides = Object.keys(overrideListenerList);
}
//监听
$("#overrideListenerTableBody button").unbind();
overrideListenerTableBody.empty();
Object.keys(overrideListenerList).forEach((item) => {
let tempTR = $(`<tr><td>${item}</td></tr>`);
let tempTD, tempInput, tempSelect, tempButton;
tempTD = $(`<td></td>`);
tempButton = $(`<button id="listenerHide" class="button">定位</button>`);
tempButton.click(function () {
for (var i = 0; i < $(`#script_settings`).children().length; i++)
{
let tab = $(`#script_settings>div:nth-child(${i})>div:nth-child(2)`);
let target = $(`#script_settings>div:nth-child(${i})>div:nth-child(2) .script_${item}`);
if(target.length > 0 && tab.css("display") != "block")
{
$(`#script_settings>div:nth-child(${i})>h3:nth-child(1)`).click();
break;
}
tab = null;
target = null;
}
let results = document.getElementsByClassName(`script_${item}`);
let result = results[results.length - 1];
document.querySelector("#\\31 7-label").click();
$("#mainColumn > div > div > section > div").hide();
$("#settings").show();
result.scrollIntoView();
highlight(3, result, item);
results = null;
result = null;
});
tempTD.append(tempButton);
tempTR.append(tempTD);
overrideListenerTableBody.append(tempTR);
});
}
function highlight(times, element, info)
{
let toolTip = $(`<div style="color:red; background-color:orange;">${info} 在这里</div>`);
Popper.createPopper(element, toolTip[0], {
placement: "right",
});
$("body").append(toolTip);
let timer = setInterval(function(){
toolTip.remove();
toolTip = null;
clearInterval(timer);
return;
},1000 * times);
}
function mainListener()
{
let smallMainListenerTitle = $("#smallMainListenerTitle");
let mainListenerButton = $("#mainListenerButton");
let mainListenerSave = $("#mainListenerSave");
let mainListenerAdd = $("#mainListenerAdd");
let mainListenerTable = $("#mainListenerTable");
let mainListenerTableBody = $("#mainListenerTableBody");
//还没有
if($("#smallMainListenerTitle").length == 0)
{
let smallMainListenerTitle = $("<div id='smallMainListenerTitle' class='has-text-advanced' onclick='(function (){$(\"#listenerTitleListWindow\").children().removeClass(\"has-text-success\");if($(\"#mainListenerContent\").css(\"display\") == \"none\"){$(\".sideListenerWindow\").hide();$(\"#mainListenerContent\").show();$(\"#smallMainListenerTitle\").addClass(\"has-text-success\");}else{$(\"#mainListenerContent\").hide();}})()'>数据监听</div>");
let mainListenerContent = $("<div id='mainListenerContent' class='vscroll sideListenerWindow' style='height: 100%; display: none;'></div>");
mainListenerButton = $('<div id="mainListenerButton" style="float: top; display:flex; flex-direction: row; justify-content: flex-start; align-items: center;"></div>');
mainListenerSave = $('<button id="mainListenerSave" class="button">保存监听项目</button>');
mainListenerAdd = $('<button id="mainListenerAdd" class="button">添加</button>');
mainListenerTable = $(`<table><thead class="has-text-plain"><tr><th>备注</th><th>类型</th><th>数据</th><th>结果</th><th>删除</th></tr></thead><tbody id="mainListenerTableBody" class="ui-sortable"></tbody></table>`);
mainListenerSave.click(saveListenerList);
mainListenerAdd.click(function(){addNewListener({note:"", type:"default", eval:""})});
mainListenerButton.append(mainListenerSave);
mainListenerButton.append(mainListenerAdd);
mainListenerContent.append(mainListenerButton);
mainListenerContent.append(mainListenerTable);
$("#listenerWindow").prepend(mainListenerContent);
$("#listenerTitleListWindow").append(smallMainListenerTitle);
let mainListenerList = JSON.parse(localStorage.getItem("listenerList"));
if(mainListenerList == null)
{
mainListenerList = [];
}
mainListenerTableBody = $("#mainListenerTableBody");
for (let i = 0; i < mainListenerList.length; i++)
{
addNewListener(mainListenerList[i]);
}
mainListenerTableBody.sortable({
items: "tr:not(.unsortable)",
helper: sorterHelper,
});
}
//监听
$("#mainListenerTableBody").children().each(function(index, value) {
let line = {};
let resultIndex = 3;
for (let i of Object.keys(dataMap))
{
if($(value).children().eq(dataMap[i]).children().eq(0).data("value"))
{
line[i] = $(value).children().eq(dataMap[i]).children().eq(0).data("value");
}
else
{
line[i] = $(value).children().eq(dataMap[i]).children().eq(0).val();
}
}
if(evalList[line.type])
$(value).children().eq(resultIndex).html(line.note + evalList[line.type].func(line.eval));
});
}
function sorterHelper(event, ui)
{
let clone = $(ui).clone();
ui.children().each((index, element) => {
if($(element).children().data("value"))
{
let copyVal = $(element).children().data("value");
if(copyVal != undefined && copyVal.length > 0)
{
clone.children().eq(index).children().val(copyVal);
}
}
else
{
let copyVal = $(element).children().val();
if(copyVal != undefined && copyVal.length > 0)
{
clone.children().eq(index).children().val(copyVal);
}
}
});
clone.css('position','absolute');
return clone.get(0);
}
function saveListenerList()
{
let listenerList = [];
$("#mainListenerTableBody").children().each(function(index, value) {
let line = {};
for (let i of Object.keys(dataMap))
{
if($(value).children().eq(dataMap[i]).children().eq(0).data("value"))
{
line[i] = $(value).children().eq(dataMap[i]).children().eq(0).data("value").trim();
}
else
{
line[i] = $(value).children().eq(dataMap[i]).children().eq(0).val().trim();
}
line[i] = `${line[i]}`;
}
listenerList.push(line);
});
localStorage.setItem("listenerList", JSON.stringify(listenerList));
}
function addNewListener(values)
{
let mainListenerTableBody = $("#mainListenerTableBody");
let tempTR = $(`<tr class="ui-sortable-handle"></tr>`);
let tempTD, tempInput, tempSelect, tempButton;
//备注
tempTD = $(`<td></td>`);
tempInput = $(`<input type="text" style="width: 100px;" value="${values['note']}">`);
tempTD.append(tempInput);
tempTR.append(tempTD);
//类型
tempTD = $(`<td></td>`);
tempSelect = $(`<select class="typeSelect"></select>`);
for (let key of Object.keys(evalList))
{
tempSelect.append($(`<option value="${key}" title="${evalList[key].desc}">${evalList[key].name}</option>`));
}
tempTD.append(tempSelect);
tempTR.append(tempTD);
//公式
tempTD = $(`<td></td>`);
tempInput = $(`<input type="text" style="width: 100px;" value="${values["eval"].replaceAll('"', '"')}">`);
tempTD.append(tempInput);
tempTR.append(tempTD);
//状态
tempTD = $(`<td></td>`);
tempTR.append(tempTD);
//删除
tempTD = $(`<td></td>`);
tempButton = $(`<button id="listenerHide" class="button">删除</button>`);
tempButton.click(function () {
var pare = $(this).parent().parent();
pare.remove();
});
tempTD.append(tempButton);
tempTR.append(tempTD);
mainListenerTableBody.append(tempTR);
tempTR.find(".typeSelect").val(values["type"]);
}
})(jQuery);