forked from ericu/jv-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
35 lines (33 loc) · 1.26 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
function onReadEnables(enables) {
document.getElementById("local").checked = enables.local;
document.getElementById("global").checked = enables.global;
}
// We just fire off a request to the tab, and accept the answer from any
// script that answers. If there's more than on iframe, whoever answers
// first wins. Or maybe Chrome just picks one to talk to; I don't know.
function setUpCheckboxes() {
document.getElementById("global").addEventListener("click",
function () {
onButtonClicked("global");
});
document.getElementById("local").addEventListener("click",
function () {
onButtonClicked("local");
});
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id,
{"message" : "read_enables"},
onReadEnables);
});
}
// This request proxies through the background page, so that it'll reach
// all iframes in the tab.
function onButtonClicked(which) {
chrome.tabs.getSelected(null, function(tab) {
chrome.extension.sendRequest({"message" : "toggle_enable",
"data" : which,
"tabId" : tab.id} );
window.close();
});
}
document.addEventListener('DOMContentLoaded', setUpCheckboxes);