1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-11-10 15:18:52 +01:00
CanvasBlocker/browserAction/browserAction.js

92 lines
2.7 KiB
JavaScript
Raw Normal View History

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");
require("../lib/theme").init();
2018-07-29 21:43:40 +02:00
logging.message("Opened browser action");
settings.onloaded(function(){
2019-11-28 01:26:35 +01:00
const actions = document.getElementById("actions");
2018-07-29 21:43:40 +02:00
[
{
label: "settings",
icon: browser.extension.getURL("icons/pageAction-showOptions.svg"),
action: function(){
if (browser.runtime && browser.runtime.openOptionsPage){
browser.runtime.openOptionsPage();
}
else {
window.open(browser.extension.getURL("options/options.html"), "_blank");
}
}
},
{
label: "test",
advanced: true,
icon: browser.extension.getURL("icons/browserAction-test.svg"),
action: function(){
window.open("https://canvasblocker.kkapsner.de/test", "_blank");
}
},
2018-07-31 14:17:39 +02:00
{
label: "review",
icon: browser.extension.getURL("icons/browserAction-review.svg"),
action: function(){
window.open("https://addons.mozilla.org/firefox/addon/canvasblocker/reviews/", "_blank");
2018-07-31 14:17:39 +02:00
}
},
2018-07-29 21:43:40 +02:00
{
label: "reportIssue",
icon: browser.extension.getURL("icons/browserAction-reportIssue.svg"),
action: function(){
window.open("https://github.com/kkapsner/CanvasBlocker/issues", "_blank");
}
},
].forEach(function(action){
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");
icon.className = "icon";
icon.style.maskImage = "url(" + action.icon + ")";
2018-07-29 21:43:40 +02:00
actionButton.appendChild(icon);
actionButton.appendChild(
document.createTextNode(
2019-04-09 08:29:52 +02:00
extension.getTranslation("browserAction_" + action.label) || action.label
2018-07-29 21:43:40 +02:00
)
);
actionButton.addEventListener("click", action.action);
actions.appendChild(actionButton);
});
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");
search.className = "search action";
actions.appendChild(search);
search.focus();
search.addEventListener("keypress", function(event){
if ([10, 13].indexOf(event.keyCode) !== -1){
window.open(browser.extension.getURL(
"options/options.html" +
"?search=" +
encodeURIComponent(this.value)
));
window.close();
}
});
2018-07-29 21:43:40 +02:00
});
}());