-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdouyu-assistant.user.js
108 lines (107 loc) · 4.32 KB
/
douyu-assistant.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
// ==UserScript==
// @name 斗鱼助手
// @namespace https://github.com/EternalPhane/UserScripts/
// @version 0.5.2
// @description 自动领取鱼丸(需要手动输入验证码)、自动打开宝箱
// @author EternalPhane
// @include /^https?:\/\/(www|yuxiu)\.douyu\.com\/(t(opic)?\/)?\w+$/
// @resource css https://raw.githubusercontent.com/EternalPhane/UserScripts/master/Douyu%20Assistant/douyu-assistant.css
// @resource html https://raw.githubusercontent.com/EternalPhane/UserScripts/master/Douyu%20Assistant/douyu-assistant.html
// @require https://code.jquery.com/jquery-3.3.1.min.js
// @grant GM_addStyle
// @grant GM_getResourceText
// ==/UserScript==
$.noConflict();
(($) => {
'use strict';
const attach = () => {
GM_addStyle(GM_getResourceText('css'));
$('div.ToolbarActivityArea').after(GM_getResourceText('html'));
let chestId = null;
let yuwanId = null;
const getYuwan = () => {
const time = $('span.RewardModule-countdown').text();
const wait = () => {
if ($('div.geetest_wait').length) {
$('div.geetest_btn')
.mouseenter()
.click();
getYuwan();
} else {
setTimeout(wait, 100);
}
};
switch (time) {
case '领 取':
if ($('div.geetest_holder:visible').length) {
break;
}
if (!$('div.RewardModal.super').length) {
$('div.RewardModule-toggle')
.mouseenter()
.click()
};
$('span.RewardM-text.enable')
.mouseenter()
.click();
setTimeout(wait, 100);
return;
case '完 成':
return;
case '':
break;
default:
const [minute, second] = time.split(':');
const ms = (Number(minute) * 60 + Number(second)) * 1000;
yuwanId = setTimeout(getYuwan, ms);
return;
}
yuwanId = setTimeout(getYuwan, 1000);
};
$('input#chest-switch').change((e) => {
localStorage.setItem('chest', String(e.currentTarget.checked));
e.currentTarget.checked
? (chestId = setInterval(() => {
if ($('div.TreasureGee:visible').length) {
return;
}
const treasure = $('div.Treasure.is-finish div.TreasureStatus-text');
treasure.length &&
'领取' === treasure.text() &&
// [not working]
// treasure.mouseenter().click();
//
// [not working]
// treasure[0].dispatchEvent(new MouseEvent("click", {
// bubbles: true,
// cancelable: true,
// composed: true,
// detail: 1,
// screenX: 1795,
// screenY: 765,
// clientX: 1796,
// clientY: 664,
// buttons: 1
// }));
//
// isTrusted?
null;
}, 100))
: clearInterval(chestId);
});
$('input#yuwan-switch').change(
(e) => {
localStorage.setItem('yuwan', String(e.currentTarget.checked));
e.currentTarget.checked ? getYuwan() : clearTimeout(yuwanId);
}
);
$('input#chest-switch').prop('checked', 'true' == localStorage.getItem('chest')).change();
$('input#yuwan-switch').prop('checked', 'true' == localStorage.getItem('yuwan')).change();
};
const wait = setInterval(() => {
if ($('div.ToolbarActivityArea').length) {
clearInterval(wait);
attach();
}
}, 100);
})(jQuery);