global: add custom context menu, fix js not working when swapping through htmx

This commit is contained in:
Agahnim 2026-03-24 16:33:32 +01:00
parent c8d03cf709
commit 8f4b04a1fd
Signed by: Agahnim
SSH key fingerprint: SHA256:Zj65PJnE0dRYye8Ltk/qDglynyXUxJngQ9qqx/VI+b4
5 changed files with 89 additions and 20 deletions

BIN
static/assets/gifs/helo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

42
static/contextmenu.js Normal file
View file

@ -0,0 +1,42 @@
(function() {
if (window._contextMenuInitialized) return;
window._contextMenuInitialized = true;
const menu = document.createElement('div');
menu.className = 'context-menu';
menu.innerHTML = `
<img src="/static/assets/gifs/helo.gif"/>
`;
menu.style.display = 'none';
document.body.appendChild(menu);
const showMenu = (x, y) => {
menu.style.display = 'block';
menu.style.left = `${x}px`;
menu.style.top = `${y}px`;
const rect = menu.getBoundingClientRect();
if (x + rect.width > window.innerWidth) {
menu.style.left = `${window.innerWidth - rect.width - 10}px`;
}
if (y + rect.height > window.innerHeight) {
menu.style.top = `${window.innerHeight - rect.height - 10}px`;
}
};
const hideMenu = () => {
menu.style.display = 'none';
};
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
showMenu(e.clientX, e.clientY);
}, false);
document.addEventListener('click', hideMenu);
document.addEventListener('scroll', hideMenu);
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') hideMenu();
});
})();

View file

@ -923,4 +923,23 @@ mini-player {
width: 90%;
}
}
}
/* Context Menu */
.context-menu {
position: fixed;
background: var(--win-bg-grey);
border: 2px solid;
border-color: #ffffff #808080 #808080 #ffffff;
box-shadow: 2px 2px 0 #000;
border-radius: 4px;
padding: 0.5rem 0;
min-width: 150px;
z-index: 9999;
font-family: 'VT323', monospace;
font-size: 1.2rem;
img {
width: 10svw;
}
}

View file

@ -1,6 +1,8 @@
<!DOCTYPE html>
<html>
<!-- Welcome!! -->
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, interactive-widget=resizes-content" />
@ -17,6 +19,7 @@
<body hx-boost="true" hx-target="#content">
<crt>
<!-- They won't ever disappear -->
<persistent-ui>
{% include "partials/header.html" %}
<miniplayer-container id="miniplayer-container">
@ -24,12 +27,15 @@
</miniplayer-container>
</persistent-ui>
<!-- Will get swapped by HTMX-->
<main id="content">
{% block content %}{% endblock %}
</main>
</crt>
<!-- Noooooooooooooooooooooooooo -->
<script src="/static/miniplayer.js"></script>
<script src="/static/contextmenu.js"></script>
<script>
function updateMiniplayerVisibility() {
const isMusicPage = window.location.pathname === '/music';

View file

@ -83,6 +83,7 @@
</website-news>
</box>
</boxes>
<!-- Nous sommes les bestioles et nous sommes responsive -->
<chibis>
<img id="me" src="/static/assets/images/boubouille.webp" />
<img id="raplapla" src="/static/assets/images/rapla.webp" />
@ -91,7 +92,7 @@
<!-- I know I know but I need it for this pretty rainbow flagish animation -->
<script>
(function() {
(function () {
<!-- For rainbow text -->
const el = document.querySelector('woopwoop');
if (!el) return;
@ -100,28 +101,29 @@
`<span style="animation-delay: ${i * 0.08}s">${ch === ' ' ? '&nbsp;' : ch}</span>`
).join('');
const BIBOU_QUOTES = {{bibou_quotes| tojson | safe }};
const BIBOU_QUOTES = {{bibou_quotes| tojson | safe
}};
const txtEl = document.querySelector('bibou-text');
const ctrEl = document.querySelector('bibou-container');
let intervalRef = null;
const txtEl = document.querySelector('bibou-text');
const ctrEl = document.querySelector('bibou-container');
let intervalRef = null;
const ttText = (texte) => {
if (intervalRef) clearInterval(intervalRef);
const ttText = (texte) => {
if (intervalRef) clearInterval(intervalRef);
let accumulated = "";
let index = 0;
let accumulated = "";
let index = 0;
intervalRef = setInterval(() => {
if (index < texte.length) {accumulated += texte.charAt(index); txtEl.textContent = accumulated; index++;} else {
clearInterval(intervalRef); intervalRef = null;
}
}, 40);
};
intervalRef = setInterval(() => {
if (index < texte.length) {accumulated += texte.charAt(index); txtEl.textContent = accumulated; index++;} else {
clearInterval(intervalRef); intervalRef = null;
}
}, 40);
};
ctrEl.addEventListener('mouseenter', () => {
const quote = BIBOU_QUOTES[Math.floor(Math.random() * BIBOU_QUOTES.length)];
ttText(quote);
});
})();
ctrEl.addEventListener('mouseenter', () => {
const quote = BIBOU_QUOTES[Math.floor(Math.random() * BIBOU_QUOTES.length)];
ttText(quote);
});
}) ();
</script>