From ba23c6b060125b35f75ad6c1e5533cf349878ef8 Mon Sep 17 00:00:00 2001 From: Rustem Mussabekov Date: Tue, 24 Dec 2024 15:25:16 +0300 Subject: [PATCH] Fix hash handling for highlights --- package.json | 2 +- src/modules/format/url/normalizeURL.js | 4 ++-- src/target/extension/background/links.js | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 47b4f63b..73666fac 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "app", - "version": "5.6.65", + "version": "5.6.66", "description": "All-in-one bookmark manager", "author": "Rustem Mussabekov", "license": "MIT", diff --git a/src/modules/format/url/normalizeURL.js b/src/modules/format/url/normalizeURL.js index 40c15905..0017511b 100644 --- a/src/modules/format/url/normalizeURL.js +++ b/src/modules/format/url/normalizeURL.js @@ -1,8 +1,8 @@ import _normalizeURL from 'normalize-url' -export function normalizeURL(str) { +export function normalizeURL(str, options) { try{ - return _normalizeURL(str) + return _normalizeURL(str, options) } catch(e) { return str } diff --git a/src/target/extension/background/links.js b/src/target/extension/background/links.js index 1305bf34..14b15009 100644 --- a/src/target/extension/background/links.js +++ b/src/target/extension/background/links.js @@ -12,9 +12,22 @@ const options = { var items = new Map() var loading = false +function simplifyURL(url) { + return normalizeURL(url, { + stripHash: !new URL(url).hash.includes('/'), //do not strip hash when it seems an SPA + stripWWW: true, + removeQueryParameters: [ + //tracking + /^utm_\w+/i, 'ref', 'ref_src', 'source', + //youtube specific + ...(/youtube|youtu\.be/i.test(url) ? ['t'] : []), + ] + }) +} + //has export function has(url) { - return items.has(normalizeURL(url)) + return items.has(simplifyURL(url)) } export function add(url, id) { @@ -23,7 +36,7 @@ export function add(url, id) { //getId export function getId(url) { - return items.get(normalizeURL(url)) + return items.get(simplifyURL(url)) } //reload @@ -60,7 +73,7 @@ export async function reload(force=false) { text.split('\n').forEach(line=>{ const [_id, href] = line.split(options.divider) - const url = normalizeURL( + const url = simplifyURL( decodeURIComponent( href||'' )