2017-10-14 18:52:56 +00:00
|
|
|
/*jslint es6: true*/
|
|
|
|
/*global window*/
|
2017-10-14 05:41:49 +00:00
|
|
|
(function () {
|
2017-10-14 20:24:18 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-14 05:41:49 +00:00
|
|
|
const rootObject = window.browser || window.chrome;
|
2017-10-14 20:24:18 +00:00
|
|
|
const doc = window.document;
|
2017-10-14 22:26:02 +00:00
|
|
|
|
2017-10-14 20:24:18 +00:00
|
|
|
const configureButton = doc.getElementById("config-page-link");
|
2017-10-14 22:26:02 +00:00
|
|
|
const listGroupElm = doc.querySelector("ul.list-group");
|
|
|
|
|
2017-10-23 08:29:59 +00:00
|
|
|
const addRuleToList = function (hostToRuleMapping, listElm, aHostName) {
|
2017-10-14 22:26:02 +00:00
|
|
|
|
|
|
|
const domainRule = hostToRuleMapping[aHostName];
|
|
|
|
|
|
|
|
const liElm = doc.createElement("li");
|
|
|
|
liElm.className = "list-group-item";
|
|
|
|
|
|
|
|
if (domainRule !== "(default)") {
|
|
|
|
liElm.className += " list-group-item-success";
|
|
|
|
}
|
|
|
|
|
|
|
|
const spanElm = doc.createElement("span");
|
|
|
|
spanElm.className = "badge";
|
|
|
|
|
|
|
|
const badgeText = doc.createTextNode(domainRule);
|
|
|
|
spanElm.appendChild(badgeText);
|
|
|
|
liElm.appendChild(spanElm);
|
|
|
|
|
|
|
|
const textElm = doc.createTextNode(aHostName);
|
|
|
|
liElm.appendChild(textElm);
|
|
|
|
listElm.appendChild(liElm);
|
|
|
|
};
|
2017-10-14 18:52:56 +00:00
|
|
|
|
|
|
|
configureButton.addEventListener("click", function (event) {
|
|
|
|
rootObject.runtime.openOptionsPage();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
}, false);
|
2017-10-14 05:41:49 +00:00
|
|
|
|
|
|
|
rootObject.tabs.executeScript(
|
|
|
|
{
|
|
|
|
allFrames: true,
|
|
|
|
code: "window.location.host"
|
|
|
|
},
|
|
|
|
function (response) {
|
|
|
|
|
|
|
|
const uniqueDomains = Array.from(new Set(response)).sort();
|
|
|
|
const message = ["rulesForDomains", uniqueDomains];
|
|
|
|
|
2017-10-14 22:26:02 +00:00
|
|
|
rootObject.runtime.sendMessage(message, function (response) {
|
2017-10-14 05:41:49 +00:00
|
|
|
|
2017-10-14 22:26:02 +00:00
|
|
|
doc.body.className = "loaded";
|
2017-10-14 18:52:56 +00:00
|
|
|
|
2017-10-14 22:26:02 +00:00
|
|
|
const domainNames = Object.keys(response);
|
2017-10-23 08:29:59 +00:00
|
|
|
const addRuleToListBound = addRuleToList.bind(undefined, response, listGroupElm);
|
2017-10-14 05:41:49 +00:00
|
|
|
|
2017-10-23 08:29:59 +00:00
|
|
|
domainNames.forEach(addRuleToListBound);
|
2017-10-14 05:41:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2017-10-23 08:29:59 +00:00
|
|
|
}());
|