diff --git a/tampermonkey/backtohome.js b/tampermonkey/backtohome.js index 5dbb51e..a7a0935 100644 --- a/tampermonkey/backtohome.js +++ b/tampermonkey/backtohome.js @@ -9,22 +9,31 @@ // @grant GM_addStyle // ==/UserScript== +const target = "https://kiosk.39c3.by.vincent.mahn.ke/"; (function() { 'use strict'; + // if the user is on target already or subdomain, do nothing + if (window.location.href === target || window.location.href.startsWith(target + '/')) { + return; + } + const btn = document.createElement('button'); btn.textContent = 'Home'; btn.style.cssText = ' all: unset; box-sizing: border-box; border: 2px solid #141414; background: #faf5f5; text-align: center; color: #141414; position: fixed; right: 10px; bottom: 10px; width: 60px; height: 60px; z-index: 2147483647; padding-top: 6px; border-radius: 60px;'; btn.innerHTML = ''; btn.addEventListener('click', () => { - window.location.href = 'http://127.0.0.1:8080'; + window.location.href = target; }); (document.body || document.documentElement).appendChild(btn); - const IDLE_LIMIT_MS = 30_000; // 30 seconds + const IDLE_LIMIT_MS = 60_000; let idleTimer = null; let promptVisible = false; + const PROMPT_LIMIT_MS = 30_000; + let promptInterval = null; + let promptTimeout = null; const modal = document.createElement('div'); modal.id = 'idle-modal'; @@ -46,6 +55,7 @@
Do you want to stay on this page or go back to the home page?
+Auto return in 30s
`; document.body.appendChild(modal); @@ -76,21 +86,57 @@ promptVisible = true; modal.hidden = false; backdrop.hidden = false; - debugger; - // Move focus to the primary action for accessibility - document.querySelector("#idle-stay").addEventListener("click", () => { + + // Clear any previous prompt timers + if (promptInterval) { clearInterval(promptInterval); promptInterval = null; } + if (promptTimeout) { clearTimeout(promptTimeout); promptTimeout = null; } + + // Wire button actions (once to avoid duplicates) + const stayBtn = document.querySelector("#idle-stay"); + const goBtn = document.querySelector("#idle-go"); + + if (stayBtn) { + stayBtn.addEventListener("click", () => { hidePrompt(); resetIdleTimer(); - }); - document.querySelector("#idle-go").addEventListener("click", () => { - window.location.href = 'https://www.google.com'; - }); + }, { once: true }); + } + + if (goBtn) { + goBtn.addEventListener("click", () => { + window.location.href = target; + }, { once: true }); + } + + // 30s countdown visible to the user + let remaining = PROMPT_LIMIT_MS / 1000; // seconds + const countdownEl = document.querySelector("#idle-countdown"); + if (countdownEl) countdownEl.textContent = String(remaining); + + promptInterval = setInterval(() => { + remaining -= 1; + if (remaining >= 0 && countdownEl) { + countdownEl.textContent = String(remaining); + } + }, 1000); + + // Auto-go when expired + promptTimeout = setTimeout(() => { + const go = document.querySelector("#idle-go"); + if (go) { + go.click(); + } else { + window.location.href = target; + } + }, PROMPT_LIMIT_MS); } function hidePrompt() { promptVisible = false; modal.hidden = true; backdrop.hidden = true; + if (promptInterval) { clearInterval(promptInterval); promptInterval = null; } + if (promptTimeout) { clearTimeout(promptTimeout); promptTimeout = null; } } function onIdle() {