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 --- content/main.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'content') diff --git a/content/main.js b/content/main.js index 8525961..65ac008 100644 --- a/content/main.js +++ b/content/main.js @@ -9,6 +9,7 @@ * IMPORTS_START * IMPORT handle_page_actions * IMPORT url_item + * IMPORT url_extract_target * IMPORT gen_unique * IMPORT csp_rule * IMPORT sanitize_attributes @@ -39,18 +40,14 @@ function needs_blocking() if (url.startsWith("https://") || url.startsWith("http://")) return false; - let url_re = /^([^#]*)((#[^#]*)(#.*)?)?$/; - let match = url_re.exec(document.URL); - let base_url = match[1]; - let first_target = match[3]; - let second_target = match[4]; + const parsed_url = url_extract_target(document.URL); - if (first_target !== undefined && - first_target === '#' + unique) { - if (second_target !== undefined) - window.location.href = base_url + second_target; + if (parsed_url.target !== undefined && + parsed_url.target === '#' + unique) { + if (parsed_url.target2 !== undefined) + window.location.href = parsed_url.base_url + parsed_url.target2; else - history.replaceState(null, "", base_url); + history.replaceState(null, "", parsed_url.base_url); console.log(["allowing whitelisted", document.URL]); return false; -- cgit v1.2.3