Add quick exit functionality to prevent navigation back to the site after a user exits. Implemented in multiple HTML files and updated script.js for session management.
This commit is contained in:
1 parent
a772e454e6
commit
9d9b6ed918
12 files changed
+188
No files matched your search
@@ -3,13 +3,46 @@
|
||||
document.documentElement.classList.replace("no-js", "js");
|
||||
|
||||
const QUICK_EXIT_URL = "https://www.google.com/";
|
||||
const QUICK_EXIT_KEY = "quick-exit";
|
||||
const STAGING_HOST = "whispersoflhj.cosmicallycreative.com";
|
||||
const MOBILE_NAV_QUERY = window.matchMedia("(max-width: 88em)");
|
||||
|
||||
function navigationType() {
|
||||
const navigation = performance.getEntriesByType("navigation")[0];
|
||||
return navigation ? navigation.type : "";
|
||||
}
|
||||
|
||||
function quickExit() {
|
||||
try {
|
||||
// Remember the exit for this tab so Back cannot reopen the site.
|
||||
sessionStorage.setItem(QUICK_EXIT_KEY, "1");
|
||||
} catch (error) {}
|
||||
|
||||
document.documentElement.hidden = true;
|
||||
if (document.body) document.body.replaceChildren();
|
||||
window.location.replace(QUICK_EXIT_URL);
|
||||
}
|
||||
|
||||
try {
|
||||
if (navigationType() === "back_forward" && sessionStorage.getItem(QUICK_EXIT_KEY) === "1") {
|
||||
document.documentElement.hidden = true;
|
||||
window.location.replace(QUICK_EXIT_URL);
|
||||
}
|
||||
} catch (error) {}
|
||||
|
||||
window.addEventListener("pageshow", (event) => {
|
||||
if (!event.persisted) return;
|
||||
|
||||
try {
|
||||
if (sessionStorage.getItem(QUICK_EXIT_KEY) !== "1") return;
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.documentElement.hidden = true;
|
||||
window.location.replace(QUICK_EXIT_URL);
|
||||
});
|
||||
|
||||
document.querySelectorAll(".quick-exit").forEach((link) => {
|
||||
link.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
@@ -31,6 +64,29 @@ document.addEventListener("keydown", (event) => {
|
||||
quickExit();
|
||||
});
|
||||
|
||||
document.addEventListener("click", (event) => {
|
||||
if (event.defaultPrevented || event.button !== 0) return;
|
||||
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
||||
|
||||
const link = event.target.closest("a[href]");
|
||||
if (!link || link.classList.contains("quick-exit")) return;
|
||||
if (link.target && link.target !== "_self") return;
|
||||
if (link.hasAttribute("download")) return;
|
||||
|
||||
let url;
|
||||
try {
|
||||
url = new URL(link.href);
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.origin !== window.location.origin) return;
|
||||
if (url.pathname === window.location.pathname && url.search === window.location.search && url.hash) return;
|
||||
|
||||
event.preventDefault();
|
||||
window.location.replace(url.href);
|
||||
});
|
||||
|
||||
document.querySelectorAll(".nav").forEach((nav) => {
|
||||
const toggle = nav.querySelector(".mobile-nav-toggle");
|
||||
const toggleLabel = toggle?.querySelector(".mobile-nav-toggle-label");
|
||||
|
||||
Reference in new issue
Block a user