mirror of
https://github.com/hyzendust/hyzendust.github.io.git
synced 2026-06-30 23:12:16 +02:00
161 lines
4.9 KiB
HTML
161 lines
4.9 KiB
HTML
<script>
|
|
(function () {
|
|
// Hide UniNotes menu item for everyone except hyzen
|
|
document.querySelectorAll('.menu__item').forEach(function (li) {
|
|
var a = li.querySelector('a');
|
|
if (a && a.getAttribute('href') === '/uninotes/') {
|
|
li.classList.add('menu__item--uninotes');
|
|
}
|
|
});
|
|
})();
|
|
</script>
|
|
<script>
|
|
(function () {
|
|
var btn = document.getElementById('theme-toggle');
|
|
if (!btn) return;
|
|
|
|
function getTheme() {
|
|
var stored = localStorage.getItem('theme');
|
|
if (stored) return stored;
|
|
return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
|
}
|
|
|
|
function applyTheme(theme) {
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
localStorage.setItem('theme', theme);
|
|
}
|
|
|
|
applyTheme(getTheme());
|
|
|
|
btn.addEventListener('click', function () {
|
|
var current = document.documentElement.getAttribute('data-theme') || getTheme();
|
|
applyTheme(current === 'dark' ? 'light' : 'dark');
|
|
});
|
|
})();
|
|
</script>
|
|
<script>
|
|
(function () {
|
|
var BACKEND = 'https://backend.freedoms4.org/auth.php';
|
|
var username = localStorage.getItem('f4_username');
|
|
if (!username) return;
|
|
|
|
function applyLoggedIn(uname) {
|
|
// ── Desktop ──────────────────────────────────────────────────────────
|
|
var authDesktop = document.querySelector('.brand__auth');
|
|
if (authDesktop && !authDesktop.querySelector('.brand__auth-user')) {
|
|
authDesktop.classList.add('brand__auth--loggedin');
|
|
|
|
// Build user button + dropdown
|
|
var userWrap = document.createElement('div');
|
|
userWrap.className = 'brand__auth-user';
|
|
|
|
var userBtn = document.createElement('button');
|
|
userBtn.className = 'brand__auth-user-btn';
|
|
userBtn.setAttribute('aria-label', 'Account menu');
|
|
|
|
var iconSvg = document.createElement('span');
|
|
iconSvg.innerHTML =
|
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="12" height="12" fill="currentColor"><path d="M12 12c2.7 0 4.8-2.1 4.8-4.8S14.7 2.4 12 2.4 7.2 4.5 7.2 7.2 9.3 12 12 12zm0 2.4c-3.2 0-9.6 1.6-9.6 4.8v2.4h19.2v-2.4c0-3.2-6.4-4.8-9.6-4.8z"/></svg>';
|
|
userBtn.appendChild(iconSvg.firstChild);
|
|
userBtn.appendChild(document.createTextNode('\u00a0' + uname));
|
|
|
|
var dropdown = document.createElement('div');
|
|
dropdown.className = 'brand__auth-user-dropdown';
|
|
|
|
var logoutBtn = document.createElement('button');
|
|
logoutBtn.className = 'brand__auth-user-logout';
|
|
logoutBtn.textContent = 'Log Out';
|
|
logoutBtn.addEventListener('click', doLogout);
|
|
|
|
dropdown.appendChild(logoutBtn);
|
|
userWrap.appendChild(userBtn);
|
|
userWrap.appendChild(dropdown);
|
|
authDesktop.appendChild(userWrap);
|
|
|
|
// Toggle dropdown on button click
|
|
userBtn.addEventListener('click', function (e) {
|
|
e.stopPropagation();
|
|
userWrap.classList.toggle('is-open');
|
|
});
|
|
document.addEventListener('click', function () {
|
|
userWrap.classList.remove('is-open');
|
|
});
|
|
}
|
|
}
|
|
|
|
function doLogout() {
|
|
fetch(BACKEND, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
credentials: 'include',
|
|
body: JSON.stringify({ action: 'logout' }),
|
|
}).finally(function () {
|
|
localStorage.removeItem('f4_username');
|
|
localStorage.removeItem('f4_login_time');
|
|
localStorage.removeItem('f4_session_fails');
|
|
window.location.reload();
|
|
});
|
|
}
|
|
|
|
applyLoggedIn(username);
|
|
})();
|
|
</script>
|
|
<script>
|
|
(function () {
|
|
var sub = document.querySelector('.rss-subscribe');
|
|
if (!sub) return;
|
|
var btn = sub.querySelector('.rss-subscribe__btn');
|
|
|
|
// Toggle dropdown
|
|
btn.addEventListener('click', function (e) {
|
|
e.stopPropagation();
|
|
sub.classList.toggle('is-open');
|
|
});
|
|
|
|
// Close on outside click
|
|
document.addEventListener('click', function (e) {
|
|
if (!sub.contains(e.target)) sub.classList.remove('is-open');
|
|
});
|
|
|
|
// Copy URL on item click
|
|
sub.querySelectorAll('.rss-subscribe__item').forEach(function (item) {
|
|
item.addEventListener('click', function (e) {
|
|
e.stopPropagation();
|
|
var url = item.getAttribute('data-rss-url');
|
|
var orig = item.textContent;
|
|
|
|
function showCopied() {
|
|
item.textContent = 'Copied!';
|
|
setTimeout(function () {
|
|
item.textContent = orig;
|
|
sub.classList.remove('is-open');
|
|
}, 1200);
|
|
}
|
|
|
|
// Synchronous fallback works on mobile within the click handler
|
|
try {
|
|
var ta = document.createElement('textarea');
|
|
ta.value = url;
|
|
ta.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none;';
|
|
document.body.appendChild(ta);
|
|
ta.focus();
|
|
ta.select();
|
|
document.execCommand('copy');
|
|
document.body.removeChild(ta);
|
|
showCopied();
|
|
} catch (err) {
|
|
// Try async clipboard as last resort
|
|
if (navigator.clipboard) {
|
|
navigator.clipboard
|
|
.writeText(url)
|
|
.then(showCopied)
|
|
.catch(function () {
|
|
item.textContent = url;
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
})();
|
|
</script>
|