-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
78 lines (66 loc) · 2.34 KB
/
popup.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
const actualSiteLabel = document.getElementById('actual-site');
const actualCookieValueLabel = document.getElementById('actual-cookie-value');
const buttonContainer = document.getElementById('button-container');
const COOKIENAME = "slot";
const COOKIEURL = "https://segugioassicurazionip.gruppomol.lcl/";
// The async IIFE is necessary because Chrome <89 does not support top level await.
(async function initPopupWindow() {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (tab?.url) {
try {
let url = new URL(tab.url);
actualSiteLabel.innerHTML = url;
chrome.cookies.get(
{"name": COOKIENAME, "url": COOKIEURL},
(cookie) => {
if (cookie) {
actualCookieValueLabel.innerHTML = cookie.value;
} else {
actualCookieValueLabel.innerHTML = "cookie non presente";
}
}
)
} catch {}
}
})();
const config = [
'Sprint',
'Fast01',
'Fast02'
]
function createButton(container, buttonLabel) {
// create a new div element
const newButton = document.createElement("button");
// and give it some content
const newContent = document.createTextNode(buttonLabel);
// add the text node to the newly created div
newButton.appendChild(newContent);
// add the newly created element and its content into the DOM
document.body.insertBefore(newButton, container);
}
window.addEventListener('load', () => {
// creo i bottoni in base alla config
config.map(button => {
createButton(buttonContainer, button)
})
})
window.addEventListener('click', (e) => {
if (e.target.nodeName === 'BUTTON') {
const cookieContentToSet = e.target.innerHTML;
chrome.cookies.get(
{"name": COOKIENAME, "url": COOKIEURL},
(cookie) => {
console.log(cookie);
if (cookie) {
chrome.cookies.set({
url: COOKIEURL,
domain: cookie.domain,
name: cookie.name,
expirationDate: cookie.expirationDate,
value: cookieContentToSet
})
}
}
)
}
})