-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_scripts.js
More file actions
37 lines (36 loc) · 1.15 KB
/
content_scripts.js
File metadata and controls
37 lines (36 loc) · 1.15 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
document.addEventListener("DOMContentLoaded", function () {
// get initial val
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { cmd: "check" }, function (msg) {
if (msg === "on") {
document.getElementById("toggle-val").checked = true;
} else {
document.getElementById("toggle-val").checked = false;
}
});
});
// add event listener at toggle
document.getElementById("toggle-val").addEventListener("change", function () {
if (this.checked) {
// on
localStorage.setItem("enableBluebird", "on");
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ cmd: "replace", replace: true },
function (msg) {}
);
});
} else {
// off
localStorage.setItem("enableBluebird", "off");
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ cmd: "replace", replace: false },
function (msg) {}
);
});
}
});
});