From 8a3332b66e054c65d4981663fa86e87f02ddce64 Mon Sep 17 00:00:00 2001 From: blankie Date: Mon, 14 Aug 2023 08:33:28 +1000 Subject: [PATCH] Update Wayback Machine Toolbar Toggler to 1.1.1 - Remove unneeded event.preventDefault(); - Don't save toolbar state if the state was retrieved by something else --- Wayback Machine Toolbar Toggler.user.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) 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); } }); }