From 8708ddd3fc564c0af3d66b50ead77e211a911254 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 2 Jul 2021 11:54:34 +0200 Subject: move parsing of url with targets to misc.js --- common/misc.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'common') diff --git a/common/misc.js b/common/misc.js index 5754bd0..0a3a425 100644 --- a/common/misc.js +++ b/common/misc.js @@ -41,6 +41,27 @@ function url_item(url) return match[1]; } +/* + * Assume a url like: https://example.com/green?illuminati=confirmed#tinky#winky + * This function will make it into an object like: + * { + * "base_url" : "https://example.com/green?illuminati=confirmed", + * "target" : "#tinky", + * "target2" : "#winky" + * } + * In case url doesn't have 2 #'s, target2 and target can be set to undefined. + */ +function url_extract_target(url) +{ + let url_re = /^([^#]*)((#[^#]*)(#.*)?)?$/; + let match = url_re.exec(url); + return { + base_url : match[1], + target : match[3], + target2 : match[4] + }; +} + /* csp rule that blocks all scripts except for those injected by us */ function csp_rule(nonce) { @@ -54,6 +75,7 @@ function csp_rule(nonce) * EXPORTS_START * EXPORT gen_unique * EXPORT url_item + * EXPORT url_extract_target * EXPORT csp_rule * EXPORTS_END */ -- cgit v1.2.3