From e8234015fc8c8677bb8786de4d8d5d90ad45e9bd Mon Sep 17 00:00:00 2001 From: Quentin Santos Date: Mon, 14 Oct 2024 19:10:15 +0200 Subject: [PATCH] Reduce noise in browser history on Chrome Closes #46 --- CHANGELOG.md | 4 ++++ main.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40ddcaf..27d5efc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v0.1.26 + +- Reduce noise in browser history on Chrome #46 + # v0.1.25 - Only annotate the first 10 links (the ones with matching number hotkeys) #43 diff --git a/main.js b/main.js index 243c211..198cf13 100644 --- a/main.js +++ b/main.js @@ -983,6 +983,11 @@ chrome.storage.sync.get((options) => { function gotoTop() { const l = document.location; + // NOTE: we use history.replaceState() instead of location.replace() to + // avoid a page reload, which would happen since the new URL does not + // have a hash. This will result in a new entry in the browser history, + // but this only happen for the top element, which limits the number of + // entries. history.replaceState(null, "", l.pathname + l.search); deactivateCurrentThing(); scrollTo(0, 0); @@ -995,7 +1000,11 @@ chrome.storage.sync.get((options) => { // user navigates through many things in a short amount of time clearTimeout(historyUpdateTimer); historyUpdateTimer = setTimeout(() => { - history.replaceState(null, "", `#${thing.id}`); + // NOTE: we use location.replace() instead of + // history.replaceState() here to avoid adding entries to the + // browser history for each navigation. Unfortunately, Firefox + // still add entries to the browser history. + location.replace(`#${thing.id}`); historyUpdateTimer = null; }, 50); // Immediately makes the change visible