diff --git a/Wayback Machine Toolbar Toggler.user.js b/Wayback Machine Toolbar Toggler.user.js index 124185f..ca1cf21 100644 --- a/Wayback Machine Toolbar Toggler.user.js +++ b/Wayback Machine Toolbar Toggler.user.js @@ -5,7 +5,7 @@ // @grant GM.getValue // @grant GM.setValue // @grant GM_addValueChangeListener -// @version 1.1.0 +// @version 1.1.1 // @author blankie // @description Replaces the "close this toolbar" button with one that lets you reopen the toolbar; its collapsed state is also saved // @inject-into page @@ -17,7 +17,7 @@ let wmIppBase = null; let wmIpp = null; -function hideToolbar() { +function hideToolbar(save = true) { wmIpp.querySelector("#wm-ipp-inside").style.display = "none"; let openA = wmIpp.querySelector("#wmtt-open-toolbar"); @@ -26,15 +26,21 @@ function hideToolbar() { openA.style.display = ""; + if (!save) { + return; + } GM.setValue("autoHideToolbar", true).catch(function(error) { console.error("Failed to set autoHideToolbar to true:", error); }); } -function showToolbar() { +function showToolbar(save = true) { wmIpp.querySelector("#wm-ipp-inside").style.display = ""; wmIppBase.style.height = ""; wmIpp.querySelector("#wmtt-open-toolbar").style.display = "none"; + if (!save) { + return; + } GM.setValue("autoHideToolbar", false).catch(function(error) { console.error("Failed to set autoHideToolbar to false:", error); }); @@ -60,10 +66,9 @@ function handleWmIpp() { let openA = document.createElement("a"); openA.id = "wmtt-open-toolbar"; openA.className = "wm-btn wm-closed"; - openA.addEventListener("click", function(event) { - event.preventDefault(); + openA.addEventListener("click", function() { showToolbar(); - }); + }, {passive: true}); // hide by default openA.style.display = "none"; // copy of #wm-expand to avoid duplicate ids @@ -90,7 +95,7 @@ function handleWmIpp() { // Automatically hide toolbar on startup GM.getValue("autoHideToolbar", false).then(function(autoHideToolbar) { if (autoHideToolbar) { - hideToolbar(); + hideToolbar(false); } }).catch(function(error) { console.error("Failed to fetch autoHideToolbar:", error); @@ -101,9 +106,9 @@ function handleWmIpp() { } if (autoHideToolbar) { - hideToolbar(); + hideToolbar(false); } else { - showToolbar(); + showToolbar(false); } }); }