]> git.ardis.lu - ardislu.dev/commitdiff
Don't record history for duplicate searches
authorArdis Lu <ardisglu@gmail.com>
Fri, 18 Nov 2022 05:16:56 +0000 (21:16 -0800)
committerArdis Lu <ardisglu@gmail.com>
Fri, 18 Nov 2022 05:16:56 +0000 (21:16 -0800)
script.js

index 3f9da55688666095077db730b22abcb2076ed429..5d933923ad353bbe40014e8328036830a73f3720 100644 (file)
--- a/script.js
+++ b/script.js
@@ -177,7 +177,9 @@ document.querySelector('form').addEventListener('submit', async event => {
   const query = data.get('query');
 
   // showPage flow is used for direct link. Manually set history here.
-  history.pushState({}, '', `/search?q=${query}`);
+  if (location.search !== `?q=${query}`) { // Don't update history if the query hasn't changed
+    history.pushState({}, '', `/search?q=${query}`);
+  }
   showSearch(query);
 });
 
This page took 0.038947 seconds and 4 git commands to generate.