-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
55 lines (52 loc) · 1.78 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
const button = document.querySelector('button')
const chaosText = ['Stop the Chaos', 'Unleash Chaos']
// iPhone's popup looks different than the iPad one
if (navigator.platform.match(/iPhone/i)) {
document.body.classList.add('iphone')
}
update()
function update() {
chrome.storage.local.get(['chaos'], (res) => {
if (res.chaos) {
button.innerHTML = chaosText[0]
document.body.classList.add('chaos')
}
else {
button.innerHTML = chaosText[1]
document.body.classList.remove('chaos')
}
})
}
button.addEventListener('click', e => {
chrome.storage.local.get('chaos', res => {
let value = true
if (res.chaos) value = false
chrome.storage.local.set({chaos: value}, () => {
// Reload all the tabs
chrome.windows.getAll({}, async (windows) => {
for (let i in windows) {
let tabs
// FireFox
try {
tabs = await browser.tabs.query({currentWindow: true})
}
// Brave / Chrome
catch {
tabs = await (() => {
return new Promise(res => {
chrome.tabs.query({currentWindow: true}, (val) => res(val))
})
})()
}
for (let i in tabs) {
let tab = tabs[i]
if (tab.url.includes('youtube') || tab.url.includes('youtu.be')) {
chrome.tabs.update(tab.id, {url: tab.url})
}
}
}
})
update()
})
})
})