aboutsummaryrefslogtreecommitdiff
path: root/common/misc.js
diff options
context:
space:
mode:
Diffstat (limited to 'common/misc.js')
-rw-r--r--common/misc.js27
1 files changed, 27 insertions, 0 deletions
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
*/
@@ -72,10 +73,36 @@ function csp_rule(nonce)
}
/*
+ * 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
*/