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

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