var icons = {google:"google",amazon:"amazon",facebook:"facebook-official",apple:"apple",microsoft:"windows",cloudflare:"cloud"}
browser.storage.local.get(["excludedDomains","siteExceptions"]).then(function(data) {
if(!data.excludedDomains) data.excludedDomains = [];
if(!data.siteExceptions) data.siteExceptions = {};
console.log(data);
for(var i=0;i<data.excludedDomains.length;i++) {
$("#ignorelist").append(
$("<div>").css("line-height","25px").data("domain",data.excludedDomains[i]).append(
$("<button>").addClass("btn").addClass("btn-sm").addClass("btn-outline-danger").css("margin","3px").append(
$("<i>").addClass("fa").addClass("fa-trash")).click(function() {
browser.runtime.sendMessage({
type:"removeFromExcludes",
subtype:"fromRules",
domainname:$(this).parent().data("domain")
},resp => {
if(resp === "Removed from Excludes") {
$(this).parent().remove();
}
});
})).append(
$("<kbd>").css("white-space","nowrap").text(data.excludedDomains[i])));
}
for(var key in data.siteExceptions) {
var cloudButtons = new Array;
for(var cloud in data.siteExceptions[key]) {
if(data.siteExceptions[key][cloud]) var buttonClass = "btn-primary";
else var buttonClass = "btn-outline-primary";
var cloudButton = $("<button>").data("cloud",cloud).addClass("btn").addClass("btn-sm").addClass(buttonClass).css("margin","3px").append(
$("<i>").addClass("fa").addClass("fa-"+icons[cloud])).click(function() {
browser.runtime.sendMessage({
type:"toggleSetting",
subtype:"fromRules",
domainname:$(this).parent().data("domain"),
company:$(this).data("cloud")
},resp => {
console.log(this);
$(this).toggleClass("btn-primary").toggleClass("btn-outline-primary");
});
});
cloudButtons.push(cloudButton);
}
$("#rulelist").append(
$("<div>").css("line-height","25px").data("domain",key).append(
$("<button>").addClass("btn").addClass("btn-sm").addClass("btn-outline-danger").css("margin","3px").append(
$("<i>").addClass("fa").addClass("fa-trash")).click(function() {
browser.runtime.sendMessage({
type:"toggleSetting",
subtype:"fromRules",
domainname:$(this).parent().data("domain"),
command:"resetDefault"
},resp => {
if(resp === "Removed Exception") {
$(this).parent().remove();
}
});
})).append(cloudButtons).append(
$("<kbd>").css("white-space","nowrap").text(key)));
}
});
