summaryrefslogtreecommitdiff
path: root/common/patterns.js
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-01-13 16:47:07 +0100
committerWojtek Kosior <koszko@koszko.org>2022-01-13 16:47:07 +0100
commit299864ee0901df8db2314cc7c07d6c481927c8aa (patch)
treedcd1056c39fa6e90214cb2296e70f1060ad9583a /common/patterns.js
parent5acb2499c1df14d6275b1ad9e139f02d1280cb9c (diff)
downloadbrowser-extension-299864ee0901df8db2314cc7c07d6c481927c8aa.tar.gz
browser-extension-299864ee0901df8db2314cc7c07d6c481927c8aa.zip
facilitate managing script blocking with a list of edtable entries
Diffstat (limited to 'common/patterns.js')
-rw-r--r--common/patterns.js30
1 files changed, 28 insertions, 2 deletions
diff --git a/common/patterns.js b/common/patterns.js
index 1398961..6f5aa40 100644
--- a/common/patterns.js
+++ b/common/patterns.js
@@ -186,5 +186,31 @@ function* each_url_pattern(url)
}
#EXPORT each_url_pattern
-#EXPORT "https://hydrillabugs.koszko.org/projects/haketilo/wiki/URL_patterns" \
- AS patterns_doc_url
+const patterns_doc_url =
+ "https://hydrillabugs.koszko.org/projects/haketilo/wiki/URL_patterns";
+#EXPORT patterns_doc_url
+
+function reconstruct_url(deco)
+{
+ const domain = deco.domain.join(".");
+ const path = ["", ...deco.path].join("/");
+ const trail = deco.trailing_slash ? "/" : "";
+ return `${deco.proto}://${domain}${path}${trail}`;
+}
+#EXPORT reconstruct_url
+
+function validate_normalize_url_pattern(url_pattern)
+{
+ try {
+ return reconstruct_url(deconstruct_url(url_pattern));
+ } catch(e) {
+ const patterns_doc_link = document.createElement("a");
+ patterns_doc_link.href = patterns_doc_url;
+ patterns_doc_link.innerText = "here";
+ const msg = document.createElement("span");
+ msg.prepend(`'${url_pattern}' is not a valid URL pattern. See `,
+ patterns_doc_link, " for more details.");
+ throw msg;
+ }
+}
+#EXPORT validate_normalize_url_pattern