-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitchclicker.js
75 lines (64 loc) · 2.8 KB
/
twitchclicker.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
// ==UserScript==
// @name Interval Get Twitch Channel Points
// @namespace https://greasyfork.org/pl/users/416294-patrykcholewa
// @version 1.2.1
// @description If stream time, clicks premium currency button anytime it appears. Is enabled between 19:00 and 1:00. Can be enabled manually.
// @author PatrykCholewa
// @include https://www.twitch.tv/*
// @exclude https://www.twitch.tv/*/videos*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var __twitchIntervalGetChannelPoints_EVENING_STREAM_TIME_LIMIT = 8;
var __twitchIntervalGetChannelPoints_MORNING_STREAM_TIME_LIMIT = 4;
document.__twitchIntervalGetChannelPoints_checkIsEnabled = function() {
return new Date().getHours() >= __twitchIntervalGetChannelPoints_EVENING_STREAM_TIME_LIMIT
|| new Date().getHours() <= __twitchIntervalGetChannelPoints_MORNING_STREAM_TIME_LIMIT;
}
document.__twitchIntervalGetChannelPoints_enable = function() {
document.__twitchIntervalGetChannelPoints_checkIsEnabled = function() {
return true;
}
}
document.__twitchIntervalGetChannelPoints_disable = function() {
document.__twitchIntervalGetChannelPoints_checkIsEnabled = function() {
return false;
}
}
var counter = 0;
setInterval(function() {
if (document.__twitchIntervalGetChannelPoints_checkIsEnabled()) {
setTimeout(function() {
var buttons = Array.from(document.querySelectorAll('button') || [])
.filter(but => Array.from(but.classList.entries()).map(ar => ar[1]).some(cl => cl.includes('ScCoreButtonSuccess-')));
if (buttons.length > 1) {
console.err('TOO MANY BUTTONS');
return;
}
var button = buttons[0];
if (button) {
console.debug('TRY CLICK');
try {
button.click();
counter = 0;
console.log('BUTTON CLICKED');
} catch (ex) {
console.error('ERROR CLICKED', ex);
}
button.click();
} else {
if (counter > 200) {
window.location.reload();
counter = 0;
console.debug('RELOAD');
}
counter++;
console.debug('WAIT BUTTON', 'COUNTER: ' + counter, new Date());
}
}, Math.random() * 4000);
} else {
console.debug('WAIT TILL STREAM', new Date());
}
}, 8000);
})();