fixed issues with the random button and hotkeys
This commit is contained in:
@@ -130,12 +130,12 @@
|
||||
return false;
|
||||
}
|
||||
renderTags(res.tags);
|
||||
span.parentElement.removeChild(span);
|
||||
if (span.parentElement) span.parentElement.removeChild(span);
|
||||
testList.innerText = "";
|
||||
addtagClick();
|
||||
}
|
||||
else if (e.key === "Escape") {
|
||||
span.parentElement.removeChild(span);
|
||||
if (span.parentElement) span.parentElement.removeChild(span);
|
||||
testList.innerText = "";
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -208,10 +208,10 @@ window.requestAnimFrame = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
const link = e.target.closest('#next, #prev, #random, .id-link, .nav-next, .nav-prev');
|
||||
const link = e.target.closest('#next, #prev, #random, #nav-random, .id-link, .nav-next, .nav-prev');
|
||||
if (link && link.href && link.hostname === window.location.hostname && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey) {
|
||||
// Special check for random
|
||||
if (link.id === 'random') {
|
||||
if (link.id === 'random' || link.id === 'nav-random') {
|
||||
e.preventDefault();
|
||||
const nav = document.querySelector("nav.navbar");
|
||||
if (nav) nav.classList.add("pbwork");
|
||||
@@ -240,7 +240,10 @@ window.requestAnimFrame = (function () {
|
||||
window.location.href = link.href;
|
||||
}
|
||||
})
|
||||
.catch(() => window.location.href = link.href);
|
||||
.catch((err) => {
|
||||
console.error("Random fetch failed:", err);
|
||||
window.location.href = link.href;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -261,7 +264,7 @@ window.requestAnimFrame = (function () {
|
||||
"a": clickOnElementBinding("#next"),
|
||||
"ArrowRight": clickOnElementBinding("#prev"),
|
||||
"d": clickOnElementBinding("#prev"),
|
||||
"r": clickOnElementBinding("#random"),
|
||||
"r": clickOnElementBinding("#random, #nav-random"),
|
||||
" ": clickOnElementBinding("#f0ck-image")
|
||||
};
|
||||
document.addEventListener("keydown", e => {
|
||||
@@ -541,10 +544,13 @@ function init() {
|
||||
|
||||
window.addEventListener('load', init);
|
||||
|
||||
document.getElementById('sbtForm').addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const input = document.getElementById('sbtInput').value.trim();
|
||||
if (input) {
|
||||
window.location.href = `/tag/${encodeURIComponent(input)}`;
|
||||
}
|
||||
});
|
||||
const sbtForm = document.getElementById('sbtForm');
|
||||
if (sbtForm) {
|
||||
sbtForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const input = document.getElementById('sbtInput').value.trim();
|
||||
if (input) {
|
||||
window.location.href = `/tag/${encodeURIComponent(input)}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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>`;
|
||||
|
||||
Reference in New Issue
Block a user