From 37221989f6ee2353e7c7bd791c945613e8bbcb83 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Sat, 30 Jul 2022 22:29:49 +0100 Subject: [PATCH] . --- index.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 5c9cf0c..f184e0e 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,6 @@ var SortOrderBStateI = true var SortOrderEnabled = false var SortValue = "" var OrderValue = "" -var ReplaceNeeded = true function SetupJS() { SetupIndexArray() SetupJSTheme() @@ -75,22 +74,31 @@ function SetupJSTheme() { th.onclick = ToggleTheme } } +function cReplaceHistory() { + ReplaceHistory(window.location.href) +} +function ReplaceHistory(url) { + if (window.history) { + if (window.history.replaceState) { + window.history.replaceState({ + light: !!document.getElementById("so-theme"), + order: document.getElementById("so-order").value, + sort: document.getElementById("so-sort").value + }, "", url); + console.log("REPLACE") + } + } +} function PushHistory(url) { var s = true if (window.history) { if (window.history.pushState) { - var objectData = { + window.history.pushState({ light: !!document.getElementById("so-theme"), order: document.getElementById("so-order").value, sort: document.getElementById("so-sort").value - }; - if (ReplaceNeeded) { - window.history.replaceState(objectData, "", url); - ReplaceNeeded = false - } - window.history.pushState(objectData, "", url); + }, "", url); console.log("PUSH") - console.log(objectData) s = false } } @@ -134,6 +142,7 @@ function ToggleTheme() { function SetupJSHPL(){ if (window.history) { if (window.history.pushState) { + window.addEventListener("load", cReplaceHistory) window.addEventListener("popstate", HandleHistoryPop) } }