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:
parent
62cbadd1ae
commit
8a3332b66e
|
@ -5,7 +5,7 @@
|
||||||
// @grant GM.getValue
|
// @grant GM.getValue
|
||||||
// @grant GM.setValue
|
// @grant GM.setValue
|
||||||
// @grant GM_addValueChangeListener
|
// @grant GM_addValueChangeListener
|
||||||
// @version 1.1.0
|
// @version 1.1.1
|
||||||
// @author blankie
|
// @author blankie
|
||||||
// @description Replaces the "close this toolbar" button with one that lets you reopen the toolbar; its collapsed state is also saved
|
// @description Replaces the "close this toolbar" button with one that lets you reopen the toolbar; its collapsed state is also saved
|
||||||
// @inject-into page
|
// @inject-into page
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
let wmIppBase = null;
|
let wmIppBase = null;
|
||||||
let wmIpp = null;
|
let wmIpp = null;
|
||||||
|
|
||||||
function hideToolbar() {
|
function hideToolbar(save = true) {
|
||||||
wmIpp.querySelector("#wm-ipp-inside").style.display = "none";
|
wmIpp.querySelector("#wm-ipp-inside").style.display = "none";
|
||||||
|
|
||||||
let openA = wmIpp.querySelector("#wmtt-open-toolbar");
|
let openA = wmIpp.querySelector("#wmtt-open-toolbar");
|
||||||
|
@ -26,15 +26,21 @@ function hideToolbar() {
|
||||||
|
|
||||||
openA.style.display = "";
|
openA.style.display = "";
|
||||||
|
|
||||||
|
if (!save) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
GM.setValue("autoHideToolbar", true).catch(function(error) {
|
GM.setValue("autoHideToolbar", true).catch(function(error) {
|
||||||
console.error("Failed to set autoHideToolbar to true:", error);
|
console.error("Failed to set autoHideToolbar to true:", error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function showToolbar() {
|
function showToolbar(save = true) {
|
||||||
wmIpp.querySelector("#wm-ipp-inside").style.display = "";
|
wmIpp.querySelector("#wm-ipp-inside").style.display = "";
|
||||||
wmIppBase.style.height = "";
|
wmIppBase.style.height = "";
|
||||||
wmIpp.querySelector("#wmtt-open-toolbar").style.display = "none";
|
wmIpp.querySelector("#wmtt-open-toolbar").style.display = "none";
|
||||||
|
|
||||||
|
if (!save) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
GM.setValue("autoHideToolbar", false).catch(function(error) {
|
GM.setValue("autoHideToolbar", false).catch(function(error) {
|
||||||
console.error("Failed to set autoHideToolbar to false:", error);
|
console.error("Failed to set autoHideToolbar to false:", error);
|
||||||
});
|
});
|
||||||
|
@ -60,10 +66,9 @@ function handleWmIpp() {
|
||||||
let openA = document.createElement("a");
|
let openA = document.createElement("a");
|
||||||
openA.id = "wmtt-open-toolbar";
|
openA.id = "wmtt-open-toolbar";
|
||||||
openA.className = "wm-btn wm-closed";
|
openA.className = "wm-btn wm-closed";
|
||||||
openA.addEventListener("click", function(event) {
|
openA.addEventListener("click", function() {
|
||||||
event.preventDefault();
|
|
||||||
showToolbar();
|
showToolbar();
|
||||||
});
|
}, {passive: true});
|
||||||
// hide by default
|
// hide by default
|
||||||
openA.style.display = "none";
|
openA.style.display = "none";
|
||||||
// copy of #wm-expand to avoid duplicate ids
|
// copy of #wm-expand to avoid duplicate ids
|
||||||
|
@ -90,7 +95,7 @@ function handleWmIpp() {
|
||||||
// Automatically hide toolbar on startup
|
// Automatically hide toolbar on startup
|
||||||
GM.getValue("autoHideToolbar", false).then(function(autoHideToolbar) {
|
GM.getValue("autoHideToolbar", false).then(function(autoHideToolbar) {
|
||||||
if (autoHideToolbar) {
|
if (autoHideToolbar) {
|
||||||
hideToolbar();
|
hideToolbar(false);
|
||||||
}
|
}
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
console.error("Failed to fetch autoHideToolbar:", error);
|
console.error("Failed to fetch autoHideToolbar:", error);
|
||||||
|
@ -101,9 +106,9 @@ function handleWmIpp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoHideToolbar) {
|
if (autoHideToolbar) {
|
||||||
hideToolbar();
|
hideToolbar(false);
|
||||||
} else {
|
} else {
|
||||||
showToolbar();
|
showToolbar(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue