fixed issues with the random button and hotkeys

This commit is contained in:
eins
2026-01-23 14:07:52 +00:00
parent b72fcaa426
commit 6799ec1567
5 changed files with 85 additions and 76 deletions

View File

@@ -1,10 +1,10 @@
const Cookie = {
get: name => {
const c = document.cookie.match(`(?:(?:^|.*; *)${name} *= *([^;]*).*$)|^.*$`)[1];
if(c) return decodeURIComponent(c);
if (c) return decodeURIComponent(c);
},
set: (name, value, opts = {}) => {
if(opts.days) {
if (opts.days) {
opts['max-age'] = opts.days * 60 * 60 * 24;
delete opts.days;
}
@@ -17,8 +17,11 @@ const Cookie = {
(() => {
const acttheme = Cookie.get('theme') ?? "w0bm";
const themecontainer = document.querySelector("li#themes > ul.dropdown-menu");
if (!themecontainer) return; // Theme menu not present on this page
const themes = [...themecontainer.querySelectorAll("li > a")].map(t => t.innerText.toLowerCase());
if(acttheme !== document.documentElement.getAttribute("theme") && themes.includes(acttheme))
if (acttheme !== document.documentElement.getAttribute("theme") && themes.includes(acttheme))
document.documentElement.setAttribute("theme", acttheme);
[...themecontainer.querySelectorAll("li > a")].forEach(t => t.addEventListener("click", e => {
e.preventDefault();
@@ -30,15 +33,15 @@ const Cookie = {
}));
document.addEventListener("keydown", e => {
if(e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA")
if (e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA")
return;
const acttheme = Cookie.get('theme') ?? "w0bm";
const themes = [...themecontainer.querySelectorAll("li > a")].map(t => t.innerText.toLowerCase());
const k = e.key;
if(k === "t") {
if (k === "t") {
e.preventDefault();
let i = themes.indexOf(acttheme);
if(++i >= themes.length)
if (++i >= themes.length)
i = 0;
document.documentElement.setAttribute("theme", themes[i]);
document.querySelector("#themes > a").setAttribute("content", themes[i]);
@@ -46,10 +49,10 @@ const Cookie = {
}
});
if(tbuttonfull = document.querySelector('svg#a_tfull')) {
if (tbuttonfull = document.querySelector('svg#a_tfull')) {
tbuttonfull.addEventListener('click', e => {
let f = Cookie.get('fullscreen');
if(f == 1) {
if (f == 1) {
Cookie.set('fullscreen', 0);
document.querySelector('html').setAttribute('res', '');
tbuttonfull.innerHTML = `<use href="/s/img/iconset.svg#window-maximize"></use>`;