From b7e2870ff58ef85370781aa04e9e0126988e39fd Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 6 Jul 2021 18:25:34 +0200 Subject: show some settings of the current page in the popup --- common/misc.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'common/misc.js') diff --git a/common/misc.js b/common/misc.js index 0a3a425..8b56e79 100644 --- a/common/misc.js +++ b/common/misc.js @@ -10,6 +10,7 @@ * IMPORT sha256 * IMPORT browser * IMPORT is_chrome + * IMPORT TYPE_NAME * IMPORTS_END */ @@ -71,11 +72,37 @@ function csp_rule(nonce) return rule; } +/* + * Print item together with type, e.g. + * nice_name("s", "hello") → "hello (script)" + */ +function nice_name(prefix, name) +{ + return `${name} (${TYPE_NAME[prefix]})`; +} + +/* Open settings tab with given item's editing already on. */ +function open_in_settings(prefix, name) +{ + name = encodeURIComponent(name); + const url = browser.runtime.getURL("html/options.html#" + prefix + name); + window.open(url, "_blank"); +} + +/* Check if url corresponds to a browser's special page */ +function is_privileged_url(url) +{ + return !!/^(chrome(-extension)?|moz-extension):\/\/|^about:/i.exec(url); +} + /* * EXPORTS_START * EXPORT gen_unique * EXPORT url_item * EXPORT url_extract_target * EXPORT csp_rule + * EXPORT nice_name + * EXPORT open_in_settings + * EXPORT is_privileged_url * EXPORTS_END */ -- cgit v1.2.3