-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.js
More file actions
89 lines (81 loc) · 2.42 KB
/
logic.js
File metadata and controls
89 lines (81 loc) · 2.42 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
document.getElementById("startButtonMBB").addEventListener("click", startTheBot);
document.getElementById("stopButtonMBB").addEventListener("click", stopTheBot);
document.getElementById("updateButtonMBB").addEventListener("click", updateTheBot);
function updateTheBot() {
const checkbox = document.getElementById('inputHumanMBB').checked;
humanBehaviour = checkbox;
chrome.storage.sync.set({
'humanBehaviour': humanBehaviour
}, function() {});
const updateTime = document.getElementById('inputTimeMBB').value;
const isnum = /^\d+$/.test(updateTime);
if (isnum) {
chrome.storage.sync.set({
'time': updateTime
}, function() {});
}
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
humanBehaviour: humanBehaviour,
time: updateTime,
play: false
});
});
}
let humanBehaviour;
let time;
chrome.storage.sync.get(['humanBehaviour'], function(result) {
humanBehaviour = result.humanBehaviour;
if (typeof humanBehaviour === 'undefined') {
humanBehaviour = true;
chrome.storage.sync.set({
'humanBehaviour': true
}, function() {});
}
document.getElementById('inputHumanMBB').checked = humanBehaviour;
});
chrome.storage.sync.get(['time'], function(result) {
time = result.time;
if (typeof time === 'undefined') {
time = 500;
chrome.storage.sync.set({
'time': 500
}, function() {});
}
document.getElementById('inputTimeMBB').value = time;
});
function startTheBot() {
chrome.storage.sync.get(['humanBehaviour'], function(result) {
chrome.storage.sync.get(['time'], function(result2) {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
humanBehaviour: result.humanBehaviour,
time: result2.time,
play: true
});
});
});
});
}
function stopTheBot() {
chrome.storage.sync.get(['humanBehaviour'], function(result) {
chrome.storage.sync.get(['time'], function(result2) {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
humanBehaviour: result.humanBehaviour,
time: result2.time,
play: false
});
});
});
});
}