Skip to content

Commit

Permalink
js: init selfhost btn immediately if already loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jo3-l committed Jan 1, 2025
1 parent 8c07718 commit 6e72549
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions assets/js/custom.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
// Put your custom JS code here
// self-hosting view
function getSelfhost() {
return localStorage.getItem('selfhost') || 'no';
}

// self-hosting view.
const getSelfhost = () => {
return localStorage.getItem('selfhost') || 'no';
};
function setSelfhost(enabled) {
localStorage.setItem('selfhost', enabled);
document.documentElement.setAttribute('data-selfhost', enabled);
}

const setSelfhost = (selfhost) => {
localStorage.setItem('selfhost', selfhost);
document.documentElement.setAttribute('data-selfhost', selfhost);
};
function initSelfhostToggle() {
setSelfhost(getSelfhost());
document.querySelectorAll('[data-selfhost-value]').forEach((element) => {
element.addEventListener('click', () => {
const selfhost = element.getAttribute('data-selfhost-value');
setSelfhost(selfhost);
});
});
}

setSelfhost(getSelfhost());

window.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('[data-selfhost-value]').forEach((element) => {
element.addEventListener('click', (event) => {
const selfhost = element.getAttribute('data-selfhost-value');
setSelfhost(selfhost);
});
}
)});
if (document.readyState !== 'loading') {
initSelfhostToggle();
} else {
document.addEventListener('DOMContentLoaded', initSelfhostToggle);
}

0 comments on commit 6e72549

Please sign in to comment.