2018-07-29 21:43:40 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-09 08:29:52 +02:00
|
|
|
const extension = require("../lib/extension");
|
2019-04-08 00:02:29 +02:00
|
|
|
const logging = require("../lib/logging");
|
|
|
|
const settings = require("../lib/settings");
|
2021-05-25 16:44:20 +02:00
|
|
|
const settingContainers = require("../lib/settingContainers");
|
|
|
|
const lists = require("../lib/lists");
|
2019-05-03 23:17:35 +02:00
|
|
|
require("../lib/theme").init();
|
2018-07-29 21:43:40 +02:00
|
|
|
logging.message("Opened browser action");
|
|
|
|
|
2021-05-25 16:44:20 +02:00
|
|
|
|
2023-04-07 09:22:03 +02:00
|
|
|
browser.tabs.query({active: true, currentWindow: true}).then(async function([currentTab]){
|
2021-05-25 16:44:20 +02:00
|
|
|
function isWhitelisted(url){
|
|
|
|
if (!(url instanceof URL)){
|
|
|
|
url = new URL(url);
|
|
|
|
}
|
|
|
|
return lists.get("white").match(url) ||
|
|
|
|
settings.get("blockMode", url).startsWith("allow");
|
|
|
|
}
|
2018-07-29 21:43:40 +02:00
|
|
|
|
2021-05-25 16:44:20 +02:00
|
|
|
const currentURL = new URL(currentTab.url);
|
2021-06-12 00:49:10 +02:00
|
|
|
const reloadButton = document.getElementById("reload");
|
|
|
|
reloadButton.addEventListener("click", async function(){
|
2024-03-28 14:26:20 +01:00
|
|
|
await browser.tabs.reload(currentTab.id, {bypassCache: true});
|
2021-06-12 00:49:10 +02:00
|
|
|
window.close();
|
|
|
|
});
|
2021-05-25 16:44:20 +02:00
|
|
|
const addonStatus = document.getElementById("addonStatus");
|
|
|
|
addonStatus.addEventListener("click", async function(){
|
2021-06-12 00:49:10 +02:00
|
|
|
reloadButton.classList.toggle("hidden");
|
2021-05-25 16:44:20 +02:00
|
|
|
if (isWhitelisted(currentURL)){
|
|
|
|
settingContainers.resetUrlValue("blockMode", currentURL);
|
|
|
|
if (settings.get("blockMode").startsWith("allow")){
|
|
|
|
settings.set("blockMode", "fake", currentURL.host);
|
2018-07-29 21:43:40 +02:00
|
|
|
}
|
2024-03-28 14:40:08 +01:00
|
|
|
if (settings.get("blockDataURLs")){
|
|
|
|
settingContainers.resetUrlValue("blockDataURLs", currentURL);
|
|
|
|
}
|
2021-05-25 16:44:20 +02:00
|
|
|
const entries = lists.get("white").filter(e => e.match(currentURL)).map(e => e.value);
|
|
|
|
await Promise.all([
|
|
|
|
lists.removeFrom("white", entries),
|
|
|
|
lists.removeFrom("sessionWhite", entries)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
else {
|
2021-06-08 15:31:37 +02:00
|
|
|
settings.set("blockMode", "allowEverything", currentURL.hostname);
|
2024-03-28 14:40:08 +01:00
|
|
|
if (settings.get("blockDataURLs")){
|
|
|
|
settings.set("blockDataURLs", false, currentURL.hostname);
|
|
|
|
}
|
2021-05-25 16:44:20 +02:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
});
|
|
|
|
function update(){
|
|
|
|
if (isWhitelisted(currentURL)){
|
|
|
|
addonStatus.className = "off";
|
|
|
|
addonStatus.title = extension.getTranslation("browserAction_status_off");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addonStatus.className = "on";
|
|
|
|
addonStatus.title = extension.getTranslation("browserAction_status_on");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return settings.onloaded(update);
|
|
|
|
}).catch(function(){});
|
|
|
|
|
|
|
|
const actionDefinitions = [
|
|
|
|
{
|
|
|
|
label: "settings",
|
2021-11-01 13:18:38 +01:00
|
|
|
icon: extension.getURL("icons/pageAction-showOptions.svg"),
|
2021-05-25 16:44:20 +02:00
|
|
|
action: function(){
|
|
|
|
if (browser.runtime && browser.runtime.openOptionsPage){
|
|
|
|
browser.runtime.openOptionsPage();
|
2018-07-31 14:17:39 +02:00
|
|
|
}
|
2021-05-25 16:44:20 +02:00
|
|
|
else {
|
2023-05-30 00:20:54 +02:00
|
|
|
browser.tabs.create({url: extension.getURL("options/options.html")});
|
2018-07-29 21:43:40 +02:00
|
|
|
}
|
2021-08-17 19:01:44 +02:00
|
|
|
window.close();
|
2021-05-25 16:44:20 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "faq",
|
2021-11-01 13:18:38 +01:00
|
|
|
icon: extension.getURL("icons/browserAction-faq.svg"),
|
2021-05-25 16:44:20 +02:00
|
|
|
action: function(){
|
2023-05-30 00:20:54 +02:00
|
|
|
browser.tabs.create({url: "https://canvasblocker.kkapsner.de/faq/"});
|
2021-08-17 19:01:44 +02:00
|
|
|
window.close();
|
2021-05-25 16:44:20 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "test",
|
|
|
|
advanced: true,
|
2021-11-01 13:18:38 +01:00
|
|
|
icon: extension.getURL("icons/browserAction-test.svg"),
|
2021-05-25 16:44:20 +02:00
|
|
|
action: function(){
|
2023-05-30 00:20:54 +02:00
|
|
|
browser.tabs.create({url: "https://canvasblocker.kkapsner.de/test"});
|
2021-08-17 19:01:44 +02:00
|
|
|
window.close();
|
2021-05-25 16:44:20 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "review",
|
2021-11-01 13:18:38 +01:00
|
|
|
icon: extension.getURL("icons/browserAction-review.svg"),
|
2021-05-25 16:44:20 +02:00
|
|
|
action: function(){
|
2023-05-30 00:20:54 +02:00
|
|
|
browser.tabs.create({url: "https://addons.mozilla.org/firefox/addon/canvasblocker/reviews/"});
|
2021-08-17 19:01:44 +02:00
|
|
|
window.close();
|
2021-05-25 16:44:20 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "reportIssue",
|
2021-11-01 13:18:38 +01:00
|
|
|
icon: extension.getURL("icons/browserAction-reportIssue.svg"),
|
2021-05-25 16:44:20 +02:00
|
|
|
action: function(){
|
2023-05-30 00:20:54 +02:00
|
|
|
browser.tabs.create({url: "https://github.com/kkapsner/CanvasBlocker/issues"});
|
2021-08-17 19:01:44 +02:00
|
|
|
window.close();
|
2021-05-25 16:44:20 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
settings.onloaded(async function(){
|
|
|
|
const actions = document.getElementById("actions");
|
|
|
|
actionDefinitions.forEach(function(action){
|
2018-07-29 21:43:40 +02:00
|
|
|
logging.verbose("Action", action);
|
|
|
|
if (action.advanced && !settings.displayAdvancedSettings){
|
|
|
|
logging.verbose("Hiding advanced action");
|
|
|
|
return;
|
|
|
|
}
|
2019-11-28 01:26:35 +01:00
|
|
|
const actionButton = document.createElement("button");
|
2018-07-29 21:43:40 +02:00
|
|
|
actionButton.className = "action";
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const icon = document.createElement("span");
|
2018-08-21 21:53:13 +02:00
|
|
|
icon.className = "icon";
|
2021-05-25 16:44:20 +02:00
|
|
|
function setIcon(url){
|
|
|
|
icon.style.maskImage = "url(" + url + ")";
|
|
|
|
}
|
|
|
|
setIcon(action.icon);
|
2018-07-29 21:43:40 +02:00
|
|
|
|
|
|
|
actionButton.appendChild(icon);
|
|
|
|
|
2021-05-25 16:44:20 +02:00
|
|
|
const textNode = document.createTextNode("");
|
|
|
|
function setLabel(label){
|
|
|
|
textNode.nodeValue = extension.getTranslation("browserAction_" + label) || label;
|
|
|
|
}
|
|
|
|
setLabel(action.label);
|
|
|
|
|
|
|
|
actionButton.appendChild(textNode);
|
|
|
|
actionButton.addEventListener("click", function(){
|
|
|
|
action.action.call(this, {setIcon, setLabel});
|
|
|
|
});
|
2018-07-29 21:43:40 +02:00
|
|
|
actions.appendChild(actionButton);
|
|
|
|
});
|
2018-10-09 12:59:53 +02:00
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const search = document.createElement("input");
|
2019-04-09 08:29:52 +02:00
|
|
|
search.placeholder = extension.getTranslation("search");
|
2018-10-09 12:59:53 +02:00
|
|
|
search.className = "search action";
|
|
|
|
actions.appendChild(search);
|
|
|
|
search.focus();
|
|
|
|
|
2018-10-09 20:44:13 +02:00
|
|
|
search.addEventListener("keypress", function(event){
|
2018-10-09 12:59:53 +02:00
|
|
|
if ([10, 13].indexOf(event.keyCode) !== -1){
|
2023-05-30 00:20:54 +02:00
|
|
|
browser.tabs.create({url: extension.getURL(
|
2018-10-09 12:59:53 +02:00
|
|
|
"options/options.html" +
|
|
|
|
"?search=" +
|
|
|
|
encodeURIComponent(this.value)
|
2023-05-30 00:20:54 +02:00
|
|
|
)});
|
2018-10-09 20:44:13 +02:00
|
|
|
window.close();
|
2018-10-09 12:59:53 +02:00
|
|
|
}
|
|
|
|
});
|
2018-07-29 21:43:40 +02:00
|
|
|
});
|
2024-03-28 14:43:53 +01:00
|
|
|
|
|
|
|
window.addEventListener("load", async function(){
|
|
|
|
extension.displayVersion("version", 250);
|
|
|
|
});
|
2018-07-29 21:43:40 +02:00
|
|
|
}());
|