52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
var background = (function () {
|
|
var tmp = {};
|
|
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
|
for (var id in tmp) {
|
|
if (tmp[id] && (typeof tmp[id] === "function")) {
|
|
if (request.path === "background-to-options") {
|
|
if (request.method === id) tmp[id](request.data);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
/* */
|
|
return {
|
|
"receive": function (id, callback) {tmp[id] = callback},
|
|
"send": function (id, data) {chrome.runtime.sendMessage({"path": "options-to-background", "method": id, "data": data})}
|
|
}
|
|
})();
|
|
|
|
var config = {
|
|
"handle": {
|
|
"click": function (e) {
|
|
var value = e.target.checked;
|
|
var id = e.target.getAttribute("id");
|
|
background.send("store", {"id": id, "value": value});
|
|
}
|
|
}
|
|
};
|
|
|
|
var load = function () {
|
|
var reload = document.getElementById("reload");
|
|
var support = document.getElementById("support");
|
|
var donation = document.getElementById("donation");
|
|
/* */
|
|
reload.addEventListener("click", function () {document.location.reload()}, false);
|
|
support.addEventListener("click", function () {background.send("support")}, false);
|
|
donation.addEventListener("click", function () {background.send("donation")}, false);
|
|
/* */
|
|
var elements = [...document.querySelectorAll("input[id*='_']")];
|
|
elements.map(function (e) {e.addEventListener("change", config.handle.click)});
|
|
/* */
|
|
background.send("load");
|
|
window.removeEventListener("load", load, false);
|
|
};
|
|
|
|
background.receive("storage", function (storage) {
|
|
for (var id in storage) {
|
|
var element = document.getElementById(id);
|
|
if (element) element.checked = storage[id];
|
|
}
|
|
});
|
|
|
|
window.addEventListener("load", load, false); |