-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (51 loc) · 1.76 KB
/
index.js
File metadata and controls
61 lines (51 loc) · 1.76 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
// Code, that is executed on the currently opened website
// This file starts the extension's routine of declining the website's cookie banner
let foundRule = findMatchingRule();
if (foundRule) {
declineBanner(foundRule);
}
/* -------------------------------------------------------------------------- */
/* ---------------------------- Process Functions --------------------------- */
// These functions are a core part of the extension's routine
function findMatchingRule() {
for (let r of rules) {
if (window.location.host.match(r.host)) {
return r;
}
}
return undefined;
}
async function declineBanner(rule) {
for (action of rule.actions) {
switch (action.type) {
case Action.click:
await clickButton(action)
break;
case Action.clickAll:
await clickAllButtons(action.selector)
break;
}
}
}
/* -------------------------------------------------------------------------- */
/* ---------------------------- Library Functions --------------------------- */
// These functions fulfill specific, single purposes and are used by the process functions
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function getButton(selector) {
let button = undefined;
switch (selector.type) {
case Selector.class:
button = document.getElementsByClassName(selector.query)[0];
break;
case Selector.id:
button = document.getElementById(selector.query);
break;
case Selector.xpath:
// TODO: implement xPath selector
throw new Error("xPath selectors are not supported yet");
break;
}
return button;
}