From 299864ee0901df8db2314cc7c07d6c481927c8aa Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 13 Jan 2022 16:47:07 +0100 Subject: facilitate managing script blocking with a list of edtable entries --- common/patterns.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'common') 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 -- cgit v1.2.3