-
Notifications
You must be signed in to change notification settings - Fork 0
/
QFFFFF.js
96 lines (91 loc) · 2.59 KB
/
QFFFFF.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
//
//
//https://github.com/zengfr/chrome-plugin-script-automation-framework
class QFFFFF {
constructor() {
var that = this;
that.log('start')
that.delay = (function() {
var timer = 0;
return function(callback, ms) {
clearTimeout(timer);
ms = that.rand(ms, ms * 2);
that.log('delay :' + ms);
timer = setTimeout(callback, ms);
};
})();
}
init(callback) {
var that = this;
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.4/jquery.min.js';
script.onload = function() {
that.log('load script');
that.delay(function() {
that.log('$1 ' + (typeof $));
that.log('$2 ' + (typeof jQuery));
that.log('$3 ' + (typeof window.$));
that.log('$4 ' + (typeof window.jQuery));
callback();
}, 1000 * 3);
};
that.log('init script');
document.head.appendChild(script);
}
rand(minNum, maxNum) {
switch (arguments.length) {
case 1:
return parseInt(Math.random() * minNum + 1, 10);
break;
case 2:
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
break;
default:
return 0;
break;
}
}
sleep_rnd_sync(ms, callback) {
var that = this;
var s = that.rand(ms, ms * 2);
that.log('sleep: ' + s);
setTimeout(callback, s)
}
async sleep_rnd_async(ms) {
var that = this;
var s = that.rand(ms, ms * 2);
await that.sleep(s);
}
sleep(ms) {
var that = this;
that.log('sleep: ' + ms);
return new Promise(resolve => setTimeout(resolve, ms))
}
scrollTo(ele,p) {
try {
var sd = 2000;
var so = -80;
if (p) {
sd = p.scroll_duration;
so = p.scroll_offset;
}
$(window).scrollTo(ele, sd, {
offset: so
});
} catch (ex) {
that.log(ex.message)
console.error(ex)
}
}
click(ele, p) {
var that = this;
that.scrollTo(ele,p)
that.log('click: ' + ele);
ele.click()
that.scrollTo(ele,p)
}
log(str) {
console.info(new Date().toLocaleTimeString() + " app-> " + str);
}
}
//------------------------------//