-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
38 lines (30 loc) · 1.07 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
import { setEnableStatus, getEnableStatus } from "./StorageOperations.js";
//Input, type: checkbox
const enableSwitch = document.getElementById("toggleButton");
async function init() {
const savedValue = await getEnableStatus();
enableSwitch.checked = savedValue;
enableSwitch.addEventListener("change", setEnableStatusListener);
}
function setEnableStatusListener(event) {
setEnableStatus(event.target.checked)
if (event.target.checked === false) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { stopRuntime: true });
});
}
}
//Create new tab if tag was <a> clicked.
document.addEventListener('DOMContentLoaded', function () {
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
(function () {
var ln = links[i];
var location = ln.href;
ln.onclick = function () {
chrome.tabs.create({ active: true, url: location });
};
})();
}
});
init();