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
This commit is contained in:
blankie 2023-08-14 08:33:28 +10:00
parent 62cbadd1ae
commit 8a3332b66e
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 14 additions and 9 deletions

View File

@ -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);
}
});
}