diff --git a/app.js b/app.js index 78a1262..5207f04 100644 --- a/app.js +++ b/app.js @@ -457,6 +457,7 @@ function showCleanResult(result, { allowAutoCopy = true, originalValue = "", rev showMessage(baseMessage, result.unwrapLimitReached ? "info" : "success"); celebrateHorribleClean(); + horribleEffects.afterClean?.({ url: result.url, source: "single" }); if (allowAutoCopy && autoCopy.checked) { copyText(cleanedValue).then((copied) => { @@ -520,6 +521,7 @@ function showBatchResults(entries, { allowAutoCopy = true } = {}) { : `${cleaned.length} cleaned, ${failed} failed.`; showMessage(baseMessage, cleaned.length > 0 ? "success" : "error"); if (cleaned.length > 0) celebrateHorribleClean(); + if (cleaned.length > 0) horribleEffects.afterClean?.({ url: batchCopyValue, source: "batch" }); if (allowAutoCopy && autoCopy.checked && batchCopyValue) { copyText(batchCopyValue).then((copied) => { @@ -531,6 +533,17 @@ function showBatchResults(entries, { allowAutoCopy = true } = {}) { } } +function requestClean(options = {}) { + if (!input.value.trim()) { + showMessage("Paste or type a URL to clean.", "error"); + return; + } + if (horribleEffects.beforeClean?.({ source: options.source || "form", proceed: () => runClean(options) })) { + return; + } + runClean(options); +} + function runClean(options = {}) { hideResults(); @@ -742,11 +755,22 @@ renderTrackerOfTheDay(); form.addEventListener("submit", (event) => { event.preventDefault(); - if (!input.value.trim()) { - showMessage("Paste or type a URL to clean.", "error"); + requestClean({ source: "form" }); +}); + +input.addEventListener("keydown", (event) => { + if (event.key !== "Enter") return; + const chord = event.ctrlKey || event.metaKey; + const horribleOn = document.documentElement.dataset.horrible === "on"; + if (chord) { + event.preventDefault(); + requestClean({ source: "keyboard" }); return; } - runClean(); + if (horribleOn && !event.shiftKey) { + event.preventDefault(); + requestClean({ source: "keyboard" }); + } }); input.addEventListener("input", () => { @@ -838,6 +862,7 @@ horribleEffects = bindHorriblePage({ popupHost: document.querySelector("#horrible-popups"), hitCounter: document.querySelector(".horrible-hit-counter"), guestbook: document.querySelector("#horrible-guestbook"), + onClean: () => runClean(), onStop: () => { saveSetting(STORAGE_KEYS.horrible, false); applyHorribleMode(false); @@ -862,6 +887,14 @@ clipboardOfferDismiss.addEventListener("click", () => { clipboardOfferValue = ""; }); +window.__urlCleaner = { + cleanCurrentInput: () => requestClean({ source: "keyboard" }), + setHorribleMode: (enabled) => { + saveSetting(STORAGE_KEYS.horrible, Boolean(enabled)); + applyHorribleMode(Boolean(enabled)); + } +}; + if (!loadHandoff()) { offerClipboardIfPermitted(); } diff --git a/horrible.css b/horrible.css index 196f5cc..534def4 100644 --- a/horrible.css +++ b/horrible.css @@ -50,6 +50,7 @@ html[data-horrible="on"] .construction-banner { margin: 0; padding: 0.45rem 0.75rem; border-bottom: 3px solid #111; + /* Static hazard stripes. They do not scroll or flash; wobble is 2.4s pose-only. */ background: repeating-linear-gradient( -45deg, #111 0 14px, @@ -522,6 +523,10 @@ html[data-horrible="on"] .horrible-toasters span:nth-child(3) { top: 78%; left: html[data-horrible="on"] .horrible-popups { display: block; + position: fixed; + inset: 0; + z-index: 2147482998; + pointer-events: none; } html[data-horrible="on"] .horrible-joke-tag { @@ -538,13 +543,14 @@ html[data-horrible="on"] .horrible-joke-tag { html[data-horrible="on"] .horrible-popup { position: fixed; - z-index: 60; + z-index: 2147482998; width: min(16.5rem, calc(100vw - 2.4rem)); padding: 0.7rem 0.75rem 0.8rem; border: 4px solid #111; border-radius: 1.4rem 0.4rem 1.6rem 0.7rem; color: #1a0033; box-shadow: 8px 8px 0 #111; + pointer-events: none; } html[data-horrible="on"] .horrible-popup h2 { @@ -576,6 +582,7 @@ html[data-horrible="on"] .horrible-popup-x { position: absolute; top: 0.4rem; right: 0.45rem; + z-index: 2147482999; width: 2rem; height: 2rem; padding: 0; @@ -585,11 +592,16 @@ html[data-horrible="on"] .horrible-popup-x { color: #c00; font-size: 1rem; line-height: 1; + transform: none !important; + animation: none !important; + pointer-events: auto; } -html[data-horrible="on"] .horrible-popup-x.horrible-dodge-a { transform: translate(-2.4rem, 1.2rem); } -html[data-horrible="on"] .horrible-popup-x.horrible-dodge-b { transform: translate(-3.2rem, 2rem); } -html[data-horrible="on"] .horrible-popup-x.horrible-dodge-c { transform: translate(-1.4rem, 2.6rem); } +html[data-horrible="on"] .horrible-popup:hover, +html[data-horrible="on"] .horrible-popup:focus-within { + animation: none !important; + transform: none; +} html[data-horrible="on"] .horrible-popup-action { border: 3px solid #111; @@ -597,6 +609,7 @@ html[data-horrible="on"] .horrible-popup-action { background: #fff; color: #1a0033; padding: 0.35rem 0.7rem; + pointer-events: auto; } html[data-horrible="on"] .horrible-loading { @@ -725,6 +738,7 @@ html[data-horrible="on"] .theme-toggle { @media (prefers-reduced-motion: no-preference) { html[data-horrible="on"]::before { + /* Luminance cycle ~0.04 Hz (28s). Stay well under the 2 Hz cap. */ animation: horrible-bg-shift 28s linear infinite, horrible-hue 40s linear infinite; } @@ -760,18 +774,8 @@ html[data-horrible="on"] .theme-toggle { animation: horrible-input-jiggle 4.8s ease-in-out infinite; } - html[data-horrible="on"] .horrible-popup { - animation: horrible-popup-wiggle 1.6s ease-in-out infinite; - } - - html[data-horrible="on"] .horrible-popup-slot-1, - html[data-horrible="on"] .horrible-popup-slot-3, - html[data-horrible="on"] .horrible-popup-slot-5 { - animation-direction: reverse; - } - html[data-horrible="on"] .horrible-loading-bar { - animation: horrible-loading-shimmer 1.2s linear infinite; + animation: horrible-loading-shimmer 2.4s linear infinite; } html[data-horrible="on"] .horrible-spin-banner { @@ -779,7 +783,7 @@ html[data-horrible="on"] .theme-toggle { } html[data-horrible="on"] .input-row .primary-button { - animation: horrible-blink 1s step-end infinite; + animation: horrible-blink 1.6s step-end infinite; transition: transform 0.22s ease; } @@ -818,7 +822,7 @@ html[data-horrible="on"] .theme-toggle { } html[data-horrible="on"] .horrible-stars span { - animation: horrible-twinkle 1.2s step-end infinite; + animation: horrible-twinkle 2s step-end infinite; } html[data-horrible="on"] .horrible-stars span:nth-child(odd) { diff --git a/horrible.js b/horrible.js index 6f5e826..4eea54d 100644 --- a/horrible.js +++ b/horrible.js @@ -1,4 +1,6 @@ import { STORAGE_KEYS, openAppStorage, readBooleanSetting, writeBooleanSetting } from "./storage.js"; +import { applyPopupDismissal, isCleanWindow, nextSpawnDelay } from "./horrible/logic.js"; +import { bindPlaybook } from "./horrible/playbook.js"; export const HORRIBLE_STORAGE_KEY = STORAGE_KEYS.horrible; export const HORRIBLE_HITS_KEY = "url-cleaner.horrible-hits"; @@ -140,23 +142,6 @@ export function popHorribleStamp(stamp) { globalThis.setTimeout(() => stamp.classList.remove("is-popping"), 1600); } -function bindRunawayClose(button, root) { - if (!button) return; - let dodges = 0; - let tiredUntil = 0; - button.addEventListener("mouseenter", () => { - if (prefersReducedMotion(root.defaultView || globalThis)) return; - const now = Date.now(); - const next = resolveCleanDodge(dodges, tiredUntil, now); - dodges = next.dodges; - tiredUntil = next.tiredUntil; - button.classList.remove(...HORRIBLE_DODGE_CLASSES); - if (next.action === "dodge") { - button.classList.add(nextDodgeClass(dodges - 1)); - } - }); -} - export function bindHorriblePage({ document: rootDocument = globalThis.document, stopButton, @@ -164,7 +149,8 @@ export function bindHorriblePage({ popupHost, hitCounter, guestbook, - onStop + onStop, + onClean } = {}) { const root = rootDocument; if (!root) return { dispose() {}, setEnabled() {}, clearPopups() {} }; @@ -219,13 +205,38 @@ export function bindHorriblePage({ const openCount = () => popupHost?.querySelectorAll(".horrible-popup").length || 0; - const spawnPopup = () => { + const quietNow = () => isCleanWindow(Date.now(), cleanWindowUntil); + + const recordDismissal = (openBeforeRemove) => { + const next = applyPopupDismissal({ + openCount: openBeforeRemove, + closes, + now: Date.now(), + cap: cap(), + multiply: HORRIBLE_POPUP_MULTIPLY, + cleanWindowUntil, + every: HORRIBLE_CLEAN_WINDOW_EVERY, + windowMs: HORRIBLE_CLEAN_WINDOW_MS + }); + closes = next.closes; + cleanWindowUntil = next.cleanWindowUntil; + if (next.inWindow || quietNow()) { + queueSpawn(); + return; + } + for (let index = 0; index < next.extras; index += 1) { + if (quietNow()) break; + spawnPopup(); + } + }; + + const spawnPopup = (override) => { if (!enabled || !isHorrible() || !popupHost) return null; + if (quietNow()) return null; if (openCount() >= cap()) return null; - if (Date.now() < cleanWindowUntil) return null; - const copy = nextPopupCopy(copyIndex); - copyIndex += 1; + const copy = override && override.title ? override : nextPopupCopy(copyIndex); + if (!override) copyIndex += 1; const slot = pickPopupSlot(usedSlots()); const skin = (slot % 4) + 1; const popup = root.createElement("aside"); @@ -233,6 +244,7 @@ export function bindHorriblePage({ popup.dataset.slot = String(slot); popup.setAttribute("role", "dialog"); popup.setAttribute("aria-label", "Joke popup"); + popup.tabIndex = -1; const tag = root.createElement("p"); tag.className = "horrible-joke-tag"; @@ -257,63 +269,114 @@ export function bindHorriblePage({ popup.append(tag, close, title, body, action); popupHost.append(popup); - bindRunawayClose(close, root); - close.addEventListener("click", () => dismissPopup(popup)); - action.addEventListener("click", () => dismissPopup(popup)); return popup; }; const dismissPopup = (popup) => { if (!popup?.isConnected) return; - const current = openCount(); - const inWindow = Date.now() < cleanWindowUntil; - const extras = popupsToSpawnOnClose(current, cap(), HORRIBLE_POPUP_MULTIPLY, inWindow); popup.remove(); - closes += 1; - const nextWindow = nextCleanWindowUntil(closes, Date.now()); - if (nextWindow) cleanWindowUntil = nextWindow; - for (let index = 0; index < extras; index += 1) spawnPopup(); }; + const onPopupHostClick = (event) => { + const button = event.target.closest?.(".horrible-popup-x, .horrible-popup-action"); + if (!button || !popupHost?.contains(button)) return; + const popup = button.closest(".horrible-popup"); + if (!popup) return; + event.preventDefault(); + dismissPopup(popup); + }; + + const onPopupHostMutate = (records) => { + if (!enabled) return; + for (const record of records) { + for (const node of record.removedNodes) { + if (node?.classList?.contains("horrible-popup")) { + recordDismissal(openCount() + 1); + } + } + } + }; + + const popupObserver = popupHost && typeof view().MutationObserver === "function" + ? new (view().MutationObserver)(onPopupHostMutate) + : null; + popupObserver?.observe(popupHost, { childList: true }); + const clearPopups = () => { if (!popupHost) return; + popupObserver?.disconnect(); popupHost.replaceChildren(); + popupObserver?.observe(popupHost, { childList: true }); }; const stopStorm = () => { - if (spawnTimer) view().clearInterval(spawnTimer); + if (spawnTimer) view().clearTimeout(spawnTimer); spawnTimer = 0; clearPopups(); cleanWindowUntil = 0; closes = 0; }; + const queueSpawn = () => { + if (spawnTimer) view().clearTimeout(spawnTimer); + spawnTimer = 0; + if (!enabled || !isHorrible()) return; + const base = reduced() ? 5000 : 2800; + const delay = nextSpawnDelay(Date.now(), cleanWindowUntil, base); + spawnTimer = view().setTimeout(() => { + spawnTimer = 0; + if (quietNow()) { + queueSpawn(); + return; + } + spawnPopup(); + queueSpawn(); + }, delay); + }; + const startStorm = () => { stopStorm(); enabled = true; spawnPopup(); if (!reduced()) spawnPopup(); - const interval = reduced() ? 5000 : 2800; - spawnTimer = view().setInterval(() => { - if (Date.now() >= cleanWindowUntil) spawnPopup(); - }, interval); + queueSpawn(); + }; + + let playbook = { + enable() {}, + disable() {}, + beforeClean() { return false; }, + afterClean() {} }; const setEnabled = (nextEnabled) => { enabled = Boolean(nextEnabled); - if (enabled && isHorrible()) startStorm(); - else stopStorm(); + if (enabled && isHorrible()) { + startStorm(); + playbook.enable(); + } else { + stopStorm(); + playbook.disable(); + } }; const stopEverything = () => { enabled = false; stopStorm(); + playbook.disable(); onStop?.(); }; const onEscape = (event) => { if (event.key !== "Escape") return; if (!isHorrible() && !enabled) return; + const popup = event.target.closest?.(".horrible-popup"); + if (popup && popupHost?.contains(popup) && enabled) { + event.preventDefault(); + event.stopPropagation(); + dismissPopup(popup); + return; + } event.preventDefault(); stopEverything(); }; @@ -323,12 +386,20 @@ export function bindHorriblePage({ cleanButton.addEventListener("focus", clearDodges); } root.addEventListener("pointermove", onPointerMove, { passive: true }); + popupHost?.addEventListener("click", onPopupHostClick); stopButton?.addEventListener("click", stopEverything); view().addEventListener?.("keydown", onEscape); guestbook?.addEventListener("click", () => { guestbook.textContent = "THANKS FOR SIGNING MY GUESTBOOK!!!1"; }); + playbook = bindPlaybook({ + document: root, + onClean, + spawnPopup, + prefersReduced: prefersReducedMotion + }); + if (hitCounter) { const storage = openHorribleStorage(view()); let current = 1337; @@ -347,13 +418,17 @@ export function bindHorriblePage({ return { dispose() { stopStorm(); + popupObserver?.disconnect(); cleanButton?.removeEventListener("mouseenter", onCleanEnter); cleanButton?.removeEventListener("focus", clearDodges); root.removeEventListener("pointermove", onPointerMove); + popupHost?.removeEventListener("click", onPopupHostClick); view().removeEventListener?.("keydown", onEscape); }, setEnabled, clearPopups, - spawnPopup + spawnPopup, + beforeClean: (...args) => playbook.beforeClean?.(...args), + afterClean: (...args) => playbook.afterClean?.(...args) }; } diff --git a/horrible/logic.js b/horrible/logic.js new file mode 100644 index 0000000..253c06b --- /dev/null +++ b/horrible/logic.js @@ -0,0 +1,289 @@ +export const PLAYBOOK_IDEAS = [ + { id: 1, name: "Marquee input", file: "horrible/playbook.js" }, + { id: 2, name: "Phone-slider URL entry", file: "horrible/playbook.js" }, + { id: 3, name: "Upside-down field", file: "horrible/playbook.js" }, + { id: 4, name: "URL password rules", file: "horrible/playbook.js" }, + { id: 5, name: "Tracker CAPTCHA", file: "horrible/playbook.js" }, + { id: 6, name: "NO / here", file: "horrible/playbook.js" }, + { id: 7, name: "Thumbwheel Clean", file: "horrible/playbook.js" }, + { id: 8, name: "Shell game", file: "horrible/playbook.js" }, + { id: 9, name: "Begin menu", file: "horrible/playbook.js" }, + { id: 10, name: "Hold to clean", file: "horrible/playbook.js" }, + { id: 11, name: "Slot machine reveal", file: "horrible/playbook.js" }, + { id: 12, name: "RealCD results", file: "horrible/playbook.js" }, + { id: 13, name: "Find95 menu bar", file: "horrible/playbook.js" }, + { id: 14, name: "Swapped labels", file: "horrible/playbook.js" }, + { id: 15, name: "Missile-menu settings", file: "horrible/playbook.js" }, + { id: 16, name: "Gravity sliders", file: "horrible/playbook.js" }, + { id: 17, name: "Prime-factor aggressiveness", file: "horrible/playbook.js" }, + { id: 18, name: "Theme roulette", file: "horrible/playbook.js" }, + { id: 19, name: "Bob's living room", file: "horrible/playbook.js" }, + { id: 20, name: "Programmerisms", file: "horrible/playbook.js" }, + { id: 21, name: "Confirmshaming buttons", file: "horrible/playbook.js" }, + { id: 22, name: "Slow T&Cs", file: "horrible/playbook.js" }, + { id: 23, name: "Cookie banner for no cookies", file: "horrible/playbook.js" }, + { id: 24, name: "The Helpful Paperclip-adjacent Thing", file: "horrible/playbook.js" }, + { id: 25, name: "Step 3 of 2", file: "horrible/playbook.js" }, + { id: 26, name: "Space Jam splash", file: "horrible/playbook.js" }, + { id: 27, name: "Comic Sans if you've got it", file: "horrible.css" }, + { id: 28, name: "Zoom roulette", file: "horrible/playbook.js" }, + { id: 29, name: "Narrator captions", file: "horrible/playbook.js" }, + { id: 30, name: "Permanent hourglass", file: "horrible/playbook.css" }, + { id: 31, name: "Silent MIDI player", file: "horrible/playbook.js" }, + { id: 32, name: "Subtitles for nonexistent sound", file: "horrible/playbook.js" }, + { id: 33, name: "Dial-up handshake", file: "horrible/playbook.js" } +]; + +export const SLIDER_ASCII_MIN = 32; +export const SLIDER_ASCII_MAX = 126; +export const THUMBWHEEL_WINDS_NEEDED = 5; +export const HOLD_CLEAN_MS = 3000; +export const HOLD_MOVE_LIMIT_PX = 2; +export const GRAVITY_OFF_RATE = 18; +export const PRIME_FACTORS = [2, 3, 5, 7]; +export const ZOOM_MIN = 0.9; +export const ZOOM_MAX = 1.3; +export const DIALUP_MS = 1500; +export const SLOT_TICKS = 8; +export const SHELL_CUP_COUNT = 3; + +export const HORRIBLE_THEMES = [ + "light", + "dark", + "darker", + "beige", + "fax", + "night-vision", + "wet-paper", + "y1997", + "back-to-light" +]; + +export const URL_PASSWORD_RULES = [ + { + id: "vegetable", + label: "at least one vegetable", + test: (value) => /carrot|celery|broccoli|kale|onion|beet|turnip|leek|yam|pea|spinach|radish/i.test(value) + }, + { + id: "palindrome", + label: "a palindrome", + test: (value) => { + const compact = String(value).replace(/[^a-z0-9]/gi, "").toLowerCase(); + return compact.length > 2 && compact === [...compact].reverse().join(""); + } + }, + { + id: "vowels", + label: "fewer vowels than trackers", + test: (value) => { + const text = String(value); + const trackers = text.match(/utm_|fbclid|gclid|mc_eid|_ga|msclkid/gi) || []; + const leftover = text.replace(/utm_|fbclid|gclid|mc_eid|_ga|msclkid/gi, ""); + const vowels = (leftover.match(/[aeiou]/gi) || []).length; + return trackers.length > vowels; + } + } +]; + +export const CAPTCHA_FRAGMENTS = [ + "utm_source=newsletter", + "ref=home", + "utm_medium=email", + "id=42", + "utm_source=ads", + "page=2", + "fbclid=abc", + "utm_campaign=spring", + "q=search" +]; + +export const SOUND_CAPTIONS = [ + "[ominous fax noises]", + "[dial-up screaming]", + "[a single kazoo, far away]", + "[the sound of a modem thinking about it]", + "[hold music, but imagined]", + "[someone dropping a stapler in 1998]" +]; + +export const NARRATOR_LINES = [ + "A brave URL enters, covered in utm.", + "The trackers gasp. The query string trembles.", + "Our hero has been sanitized. The audience pretends to clap.", + "Meanwhile, fbclid writes a sad postcard.", + "The cleaned link takes a bow. Nobody asked it to." +]; + +export const TOUR_STEPS = [ + { n: "3", of: "2", text: "First, paste a URL. This is step 3. Do not ask questions." }, + { n: "2", of: "2", text: "Next is also a step. The Next button has moved. Again." }, + { n: "1", of: "2", text: "Congratulations. This is step 1 of 2. You are done, probably." } +]; + +export const PROGRAMMERISM_SUCCESS = "Error 0x0000UTM: The operation completed successfully"; + +export function clampAsciiCode(value) { + const code = Number.isFinite(Number(value)) ? Math.round(Number(value)) : SLIDER_ASCII_MIN; + return Math.min(SLIDER_ASCII_MAX, Math.max(SLIDER_ASCII_MIN, code)); +} + +export function charFromSlider(value) { + return String.fromCharCode(clampAsciiCode(value)); +} + +export function appendSliderChar(current, sliderValue) { + return `${current ?? ""}${charFromSlider(sliderValue)}`; +} + +export function evaluatePasswordRules(value) { + return URL_PASSWORD_RULES.map((rule) => ({ + id: rule.id, + label: rule.label, + ok: rule.test(value ?? "") + })); +} + +export function captchaCellHasUtm(text) { + return /utm_source/i.test(String(text)); +} + +export function splitCaptchaCell(text) { + const value = String(text || ""); + const mid = Math.max(1, Math.ceil(value.length / 2)); + const left = value.slice(0, mid); + const right = value.slice(mid); + return [left, right || "utm"]; +} + +export function nextThumbwheelWinds(winds, deltaY, needed = THUMBWHEEL_WINDS_NEEDED) { + const current = Math.max(0, Math.trunc(winds) || 0); + if (deltaY < -8) { + const next = current + 1; + return { winds: next, armed: next >= needed }; + } + return { winds: current, armed: current >= needed }; +} + +export function holdMovedTooFar(start, current, limit = HOLD_MOVE_LIMIT_PX) { + if (!start || !current) return false; + return Math.hypot((current.x ?? 0) - (start.x ?? 0), (current.y ?? 0) - (start.y ?? 0)) > limit; +} + +export function initialShellOrder() { + return ["clean", "unclean-a", "unclean-b"]; +} + +export function shuffleCups(order, swapIndex = 0) { + const next = [...order]; + const index = Math.abs(Math.trunc(swapIndex)) % next.length; + const other = (index + 1) % next.length; + [next[index], next[other]] = [next[other], next[index]]; + return next; +} + +export function shellIsClean(order, index) { + return order[index] === "clean"; +} + +export function stepGravity(value, dtSeconds, rate = GRAVITY_OFF_RATE) { + const current = Number.isFinite(value) ? value : 0; + const dt = Number.isFinite(dtSeconds) ? Math.max(0, dtSeconds) : 0; + return Math.max(0, current - rate * dt); +} + +export function gravityIsOn(value) { + return Number(value) > 50; +} + +export function multiplyPrime(product, prime) { + const current = Number.isFinite(product) && product > 0 ? product : 1; + const factor = PRIME_FACTORS.includes(prime) ? prime : 1; + const next = current * factor; + return { product: next, aggressive: next > 50 }; +} + +export function resetPrimes() { + return { product: 1, aggressive: false }; +} + +export function nextHorribleTheme(current) { + const index = HORRIBLE_THEMES.indexOf(current); + return HORRIBLE_THEMES[(index + 1) % HORRIBLE_THEMES.length]; +} + +export function clampZoom(scale) { + const value = Number(scale); + if (!Number.isFinite(value)) return 1; + return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, value)); +} + +export function nextZoomScale(seed = 0) { + const t = Math.abs(Number(seed)) % 9; + return clampZoom(ZOOM_MIN + (t / 8) * (ZOOM_MAX - ZOOM_MIN)); +} + +export function dialupMs(reducedMotion) { + return reducedMotion ? 0 : DIALUP_MS; +} + +export function pickSoundCaption(index = 0) { + return SOUND_CAPTIONS[Math.abs(Math.trunc(index)) % SOUND_CAPTIONS.length]; +} + +export function pickNarratorLine(index = 0) { + return NARRATOR_LINES[Math.abs(Math.trunc(index)) % NARRATOR_LINES.length]; +} + +export function slotCharsForTick(finalText, tick, alphabet = "abcdefghijklmnopqrstuvwxyz0123456789:/?&=._-%") { + const text = String(finalText ?? ""); + if (tick >= SLOT_TICKS) return text; + return [...text].map((char, index) => { + if (/\s/.test(char)) return char; + const pick = (index * 13 + tick * 7) % alphabet.length; + return alphabet[pick]; + }).join(""); +} + +export function isCleanWindow(now, cleanWindowUntil) { + return Number(cleanWindowUntil) > Number(now); +} + +export function applyPopupDismissal({ + openCount, + closes, + now, + cap, + multiply, + cleanWindowUntil = 0, + every, + windowMs +} = {}) { + const nextCloses = (Number(closes) || 0) + 1; + const started = nextCleanWindow(nextCloses, now, every, windowMs); + const windowUntil = started || cleanWindowUntil || 0; + const inWindow = Boolean(started) || isCleanWindow(now, windowUntil); + const extras = extrasAfterClose(openCount, cap, multiply, inWindow); + return { + closes: nextCloses, + cleanWindowUntil: windowUntil, + extras, + inWindow + }; +} + +export function nextCleanWindow(closesAfterThis, now, every = 3, windowMs = 6000) { + if (closesAfterThis > 0 && closesAfterThis % every === 0) return now + windowMs; + return 0; +} + +export function extrasAfterClose(openCount, cap, multiply = 2, inCleanWindow = false) { + if (inCleanWindow) return 0; + const afterRemoval = Math.max(0, (Number(openCount) || 0) - 1); + return Math.min(multiply, Math.max(0, cap - afterRemoval)); +} + +export function nextSpawnDelay(now, cleanWindowUntil, baseMs) { + if (cleanWindowUntil > now) return Math.max(16, cleanWindowUntil - now); + return Math.max(16, baseMs); +} diff --git a/horrible/playbook.css b/horrible/playbook.css new file mode 100644 index 0000000..52fa641 --- /dev/null +++ b/horrible/playbook.css @@ -0,0 +1,601 @@ +/* Playbook ideas #1–#33. Off unless html[data-horrible="on"]. */ + +html[data-horrible="on"] { + --horrible-scale: 1; +} + +html[data-horrible="on"] body { + zoom: var(--horrible-scale, 1); +} + +html[data-horrible="on"] .horrible-visually-hidden { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0 0 0 0); + white-space: nowrap; + border: 0; +} + +html[data-horrible="on"] #horrible-playbook, +html[data-horrible="on"] #horrible-overlays { + display: block; +} + +html[data-horrible="on"] #horrible-playbook [hidden], +html[data-horrible="on"] #horrible-overlays [hidden] { + display: none !important; +} + +html[data-horrible="on"] .horrible-stop { + z-index: 2147483000 !important; + visibility: visible !important; + opacity: 1 !important; + pointer-events: auto !important; + display: inline-flex !important; + transform: none !important; +} + +html[data-horrible="on"] { + cursor: url("data:image/svg+xml,%3Csvg xmlns='http%3A//www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23ffe600' stroke='%23111111' stroke-width='1' d='M3 1.5h10v3.2L8.2 8 13 11.3V14.5H3v-3.2L7.8 8 3 4.7z'/%3E%3C/svg%3E") 8 8, wait; +} + +html[data-horrible="on"] .horrible-play-panel, +html[data-horrible="on"] .horrible-input-toys, +html[data-horrible="on"] .horrible-clean-toys, +html[data-horrible="on"] .horrible-settings-toys, +html[data-horrible="on"] .horrible-result-toys { + display: block; + margin: 0.75rem 0; + padding: 0.65rem 0.75rem; + border: 3px dashed #111; + background: #fff7c2; + color: #1a0033; +} + +html[data-horrible="on"] .horrible-input-wrap { + position: relative; +} + +html[data-horrible="on"] #url-input { + transform: rotate(180deg); + color: transparent; + caret-color: #111; +} + +html[data-horrible="on"] .horrible-australia-hint { + margin: 0.2rem 0 0.4rem; + text-align: right; +} + +html[data-horrible="on"] .horrible-marquee-input { + display: block; + overflow: hidden; + pointer-events: none; + margin: 0 0 0.4rem; + min-height: 1.4rem; + color: #9b0870; +} + +html[data-horrible="on"] .horrible-marquee-text { + display: inline-block; + white-space: nowrap; +} + +html[data-horrible="on"] .horrible-phone-slider label, +html[data-horrible="on"] .horrible-phone-char { + display: inline-block; + margin-right: 0.4rem; +} + +html[data-horrible="on"] .horrible-phone-char { + min-width: 1.4rem; + border: 2px solid #111; + background: #fff; + text-align: center; +} + +html[data-horrible="on"] .horrible-password-rules { + margin: 0.4rem 0 0; + padding-left: 1.2rem; +} + +html[data-horrible="on"] .horrible-password-rules li.is-ok { + color: #176b36; +} + +html[data-horrible="on"] .horrible-no-here { + margin: 0 0 0.5rem; +} + +html[data-horrible="on"] .horrible-here { + border: 0; + background: none; + color: blue; + text-decoration: underline; + font: inherit; + cursor: inherit; +} + +html[data-horrible="on"] .horrible-wheel { + width: 7rem; + height: 7rem; + border: 4px solid #111; + border-radius: 50%; + background: repeating-linear-gradient( + 180deg, + #333 0 8px, + #999 8px 16px + ); + background-position: 0 var(--wheel-y, 0px); + touch-action: none; +} + +html[data-horrible="on"] .horrible-hold { + margin: 0.6rem 0; +} + +html[data-horrible="on"] .horrible-hold-track { + height: 0.9rem; + margin-top: 0.35rem; + border: 2px solid #111; + background: #fff; +} + +html[data-horrible="on"] .horrible-hold-bar { + display: block; + width: 0; + height: 100%; + background: #39ff14; +} + +html[data-horrible="on"] .horrible-hold-bar.is-filling { + width: 100%; +} + +html[data-horrible="on"] .horrible-shell-stage { + position: relative; + height: 6.2rem; +} + +html[data-horrible="on"] .horrible-cup { + position: absolute; + top: 0; + left: var(--cup-x, 0); + width: 30%; + height: 5.6rem; + border: 3px solid #111; + border-radius: 0 0 2rem 2rem; + background: #c47b3a; +} + +html[data-horrible="on"] .horrible-begin { + position: relative; + margin-top: 0.6rem; + background: #c3c3c3; + border: 2px solid #111; + color: #111; + font-family: sans-serif; +} + +html[data-horrible="on"] .horrible-begin summary, +html[data-horrible="on"] .horrible-begin button { + font-family: sans-serif; + background: #c3c3c3; + color: #111; + border: 1px solid #111; +} + +html[data-horrible="on"] .horrible-begin-menu { + display: none; + position: absolute; + left: 0; + bottom: 100%; + min-width: 10rem; + margin: 0; + padding: 0.2rem 0; + list-style: none; + background: #c3c3c3; + border: 2px solid #111; +} + +html[data-horrible="on"] .horrible-begin:focus-within .horrible-begin-menu, +html[data-horrible="on"] .horrible-begin:hover .horrible-begin-menu, +html[data-horrible="on"] .horrible-begin.is-open .horrible-begin-menu { + display: block; +} + +html[data-horrible="on"] .horrible-begin-sub { + display: none; + position: absolute; + left: 100%; + top: 0; + min-width: 9rem; + margin: 0; + padding: 0.2rem 0; + list-style: none; + background: #c3c3c3; + border: 2px solid #111; +} + +html[data-horrible="on"] .horrible-begin-item:focus-within > .horrible-begin-sub, +html[data-horrible="on"] .horrible-begin-item:hover > .horrible-begin-sub { + display: block; +} + +html[data-horrible="on"] .horrible-captcha, +html[data-horrible="on"] .horrible-dialup, +html[data-horrible="on"] .horrible-splash, +html[data-horrible="on"] .horrible-cookie, +html[data-horrible="on"] .horrible-tour { + position: fixed; + z-index: 120; + border: 4px solid #111; + background: #fff8dc; + color: #1a0033; +} + +html[data-horrible="on"] .horrible-captcha, +html[data-horrible="on"] .horrible-dialup { + top: 18%; + left: 50%; + width: min(22rem, calc(100vw - 2rem)); + padding: 0.8rem; + transform: translateX(-50%); +} + +html[data-horrible="on"] .horrible-captcha-grid { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 0.35rem; +} + +html[data-horrible="on"] .horrible-captcha-cell { + min-height: 3.2rem; + border: 2px solid #111; + background: #eee; + font-size: 0.72rem; + word-break: break-all; +} + +html[data-horrible="on"] .horrible-skip, +html[data-horrible="on"] .horrible-splash button, +html[data-horrible="on"] .horrible-cookie button, +html[data-horrible="on"] .horrible-tour button { + border: 2px solid #111; + background: #ffe600; + color: #111; +} + +html[data-horrible="on"] .horrible-find95 { + display: flex; + gap: 0.4rem; + margin: 0 0 0.5rem; + padding: 0.15rem 0.3rem; + background: #c3c3c3; + border: 2px solid #111; + font-family: sans-serif; +} + +html[data-horrible="on"] .horrible-find95 details { + position: relative; +} + +html[data-horrible="on"] .horrible-find95 ul { + display: none; + position: absolute; + left: 0; + top: 100%; + margin: 0; + padding: 0.2rem 0.4rem; + list-style: none; + background: #c3c3c3; + border: 2px solid #111; + white-space: nowrap; + z-index: 4; +} + +html[data-horrible="on"] .horrible-find95 details:focus-within ul, +html[data-horrible="on"] .horrible-find95 details:hover ul { + display: block; +} + +html[data-horrible="on"] .horrible-lies { + display: none; + margin-left: 0.4rem; + padding: 0 0.3rem; + border: 1px dashed #111; + background: #ffe600; + font-size: 0.75rem; +} + +html[data-horrible-swap-labels] .horrible-lies, +html.horrible-swap-labels[data-horrible="on"] .horrible-lies { + display: inline-block; +} + +html.horrible-swap-labels[data-horrible="on"] #result-panel .url-block:first-of-type h3, +html.horrible-swap-labels[data-horrible="on"] #result-panel .result-heading h3 { + font-size: 0; +} + +html.horrible-swap-labels[data-horrible="on"] #result-panel .url-block:first-of-type h3::after { + content: "After (lies)"; + font-size: 1.125rem; +} + +html.horrible-swap-labels[data-horrible="on"] #result-panel .result-heading h3::after { + content: "Before (lies)"; + font-size: 1.125rem; +} + +html[data-horrible="on"] .horrible-realcd { + display: block; + position: relative; + min-height: 7rem; + margin: 0.5rem 0; + perspective: 800px; +} + +html[data-horrible="on"] .horrible-case { + position: relative; + min-height: 7rem; + border: 4px solid #1d3557; + background: #457b9d; + color: #fff; +} + +html[data-horrible="on"] .horrible-case-lid { + position: absolute; + inset: 0; + background: #1d3557; + transform-origin: left center; +} + +html[data-horrible="on"] .horrible-realcd.is-open .horrible-case-lid { + transform: rotateY(-118deg); +} + +html[data-horrible="on"] .horrible-slot { + display: block; + margin: 0.4rem 0; + min-height: 1.5rem; + overflow: hidden; + font-family: ui-monospace, monospace; +} + +html[data-horrible="on"] .horrible-missile { + list-style: none; + margin: 0; + padding: 0; +} + +html[data-horrible="on"] .horrible-missile button { + display: block; + width: 100%; + margin: 0.15rem 0; + border: 0; + background: none; + color: #003; + text-align: left; + text-decoration: underline; + font: inherit; + letter-spacing: 0.04em; + text-transform: uppercase; +} + +html[data-horrible="on"] .horrible-gravity label { + display: block; + margin: 0.35rem 0; +} + +html[data-horrible="on"] .horrible-primes { + display: flex; + flex-wrap: wrap; + gap: 0.35rem; + align-items: center; +} + +html[data-horrible="on"] .horrible-bob { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 0.4rem; + margin-top: 0.5rem; + padding: 0.5rem; + border: 3px solid #6b4a1b; + background: #f7e7c2; +} + +html[data-horrible="on"] .horrible-bob button { + min-height: 4.2rem; + border: 2px solid #6b4a1b; + background: #fff8dc; +} + +html[data-horrible="on"] .horrible-terms { + height: 4.5rem; + overflow: hidden; + border: 2px inset #111; + background: #fff; +} + +html[data-horrible="on"] .horrible-terms-copy { + display: block; + padding: 0.4rem; +} + +html[data-horrible="on"] .horrible-cookie { + right: 0.8rem; + bottom: 5.4rem; + left: auto; + width: min(18rem, calc(100vw - 1.6rem)); + padding: 0.7rem; +} + +html[data-horrible="on"] .horrible-splash { + inset: 8% 6%; + z-index: 110; + background: + radial-gradient(circle at 20% 30%, #ffe600 0 8%, transparent 9%), + radial-gradient(circle at 70% 60%, #00e5ff 0 6%, transparent 7%), + #050018; + color: #fff; +} + +html[data-horrible="on"] .horrible-planets { + display: flex; + flex-wrap: wrap; + justify-content: space-around; + align-items: center; + min-height: 14rem; +} + +html[data-horrible="on"] .horrible-planet { + width: 6.2rem; + height: 6.2rem; + border: 0; + border-radius: 50%; + color: #111; + font-weight: 700; +} + +html[data-horrible="on"] .horrible-planet-clean { background: radial-gradient(circle at 30% 30%, #fff, #39ff14 40%, #0a6); } +html[data-horrible="on"] .horrible-planet-inspect { background: radial-gradient(circle at 30% 30%, #fff, #00e5ff 40%, #046); } +html[data-horrible="on"] .horrible-planet-book { background: radial-gradient(circle at 30% 30%, #fff, #ff8c1a 40%, #832); } +html[data-horrible="on"] .horrible-planet-lunch { background: radial-gradient(circle at 30% 30%, #fff, #ff2d95 40%, #604); } + +html[data-horrible="on"] .horrible-tour { + top: 22%; + left: 1rem; + width: min(16rem, calc(100vw - 2rem)); + padding: 0.6rem; +} + +html[data-horrible="on"] .horrible-tour-next.horrible-tour-slot-0 { margin-left: 0; } +html[data-horrible="on"] .horrible-tour-next.horrible-tour-slot-1 { margin-left: 4rem; } +html[data-horrible="on"] .horrible-tour-next.horrible-tour-slot-2 { margin-left: 1.5rem; } + +html[data-horrible="on"] .horrible-midi { + margin-top: 0.7rem; +} + +html[data-horrible="on"] .horrible-midi-track { + height: 0.7rem; + border: 2px solid #111; + background: #111; +} + +html[data-horrible="on"] .horrible-midi-bar { + display: block; + width: 8%; + height: 100%; + background: #39ff14; +} + +html[data-horrible="on"] .horrible-subtitles, +html[data-horrible="on"] .horrible-narrator { + display: block; + position: fixed; + left: 50%; + z-index: 55; + transform: translateX(-50%); + max-width: min(28rem, calc(100vw - 2rem)); + padding: 0.25rem 0.55rem; + background: #111; + color: #ffe600; + text-align: center; + pointer-events: none; +} + +html[data-horrible="on"] .horrible-narrator { bottom: 7.2rem; } +html[data-horrible="on"] .horrible-subtitles { bottom: 5.2rem; opacity: 0; } +html[data-horrible="on"] .horrible-subtitles.is-on { opacity: 1; } + +html[data-horrible="on"] .horrible-wave { + width: 100%; + height: 3rem; +} + +html[data-horrible="on"] .horrible-querry { + display: flex; + align-items: center; + justify-content: center; + width: 2.4rem; + height: 2.4rem; + margin-bottom: 0.3rem; + border: 3px solid #111; + border-radius: 50%; + background: #ffe600; + font-size: 1.4rem; +} + +html[data-horrible="on"][data-horrible-theme="light"] { --horrible-ink: #222; } +html[data-horrible="on"][data-horrible-theme="dark"] body { filter: none; } +html[data-horrible="on"][data-horrible-theme="darker"] .app-shell { background: #111; color: #eee; } +html[data-horrible="on"][data-horrible-theme="beige"] .app-shell { background: #e6d3b3; } +html[data-horrible="on"][data-horrible-theme="fax"] .app-shell { background: #d8d8d8; filter: grayscale(0.8); } +html[data-horrible="on"][data-horrible-theme="night-vision"] .app-shell { background: #031a03; color: #39ff14; } +html[data-horrible="on"][data-horrible-theme="wet-paper"] .app-shell { background: #cfd8dc; } +html[data-horrible="on"][data-horrible-theme="y1997"] .app-shell { background: #008080; } +html[data-horrible="on"][data-horrible-theme="back-to-light"] .app-shell { background: #fff; } + +@media (prefers-reduced-motion: no-preference) { + html[data-horrible="on"] .horrible-marquee-text { + animation: horrible-marquee 16s linear infinite; + } + + html[data-horrible="on"] .horrible-hold-bar.is-filling { + transition: width 3s linear; + } + + html[data-horrible="on"] .horrible-cup { + transition: left 1.2s ease; + } + + html[data-horrible="on"] .horrible-case-lid { + transition: transform 0.8s ease; + } + + html[data-horrible="on"] .horrible-terms-copy { + animation: horrible-terms 28s linear infinite; + } + + html[data-horrible="on"] .horrible-midi-bar.is-playing { + animation: horrible-midi 18s linear infinite; + } + + html[data-horrible="on"] .horrible-subtitles { + transition: opacity 0.8s ease; + } + + html[data-horrible="on"] .horrible-wave path { + animation: horrible-wave 1.5s linear; + } +} + +@media (prefers-reduced-motion: reduce) { + html[data-horrible="on"] #horrible-playbook *, + html[data-horrible="on"] #horrible-playbook *::before, + html[data-horrible="on"] #horrible-playbook *::after { + animation: none !important; + transition: none !important; + } +} + +@keyframes horrible-terms { + from { transform: translateY(0); } + to { transform: translateY(-70%); } +} + +@keyframes horrible-midi { + from { width: 4%; } + to { width: 96%; } +} + +@keyframes horrible-wave { + from { stroke-dashoffset: 120; } + to { stroke-dashoffset: 0; } +} diff --git a/horrible/playbook.js b/horrible/playbook.js new file mode 100644 index 0000000..2b6ed6e --- /dev/null +++ b/horrible/playbook.js @@ -0,0 +1,783 @@ +import { + CAPTCHA_FRAGMENTS, + HOLD_CLEAN_MS, + HORRIBLE_THEMES, + PROGRAMMERISM_SUCCESS, + SHELL_CUP_COUNT, + SLOT_TICKS, + SOUND_CAPTIONS, + THUMBWHEEL_WINDS_NEEDED, + TOUR_STEPS, + appendSliderChar, + captchaCellHasUtm, + charFromSlider, + clampAsciiCode, + dialupMs, + evaluatePasswordRules, + gravityIsOn, + initialShellOrder, + multiplyPrime, + nextThumbwheelWinds, + nextZoomScale, + pickNarratorLine, + pickSoundCaption, + resetPrimes, + shellIsClean, + shuffleCups, + slotCharsForTick, + splitCaptchaCell, + stepGravity, + holdMovedTooFar +} from "./logic.js"; + +function el(root, tag, className, text) { + const node = root.createElement(tag); + if (className) node.className = className; + if (text != null) node.textContent = text; + return node; +} + +function setButtonLabel(button, text) { + if (!button) return; + const wrap = button.querySelector(".icon-button"); + if (wrap) { + const icon = wrap.querySelector("svg"); + wrap.replaceChildren(); + if (icon) wrap.append(icon); + wrap.append(rootText(button, text)); + return; + } + button.textContent = text; +} + +function rootText(button, text) { + return button.ownerDocument.createTextNode(text); +} + +function readButtonLabel(button) { + if (!button) return ""; + const wrap = button.querySelector(".icon-button"); + if (wrap) return wrap.textContent.trim(); + return button.textContent.trim(); +} + +function visuallyHide(node, hide) { + if (!node) return; + node.classList.toggle("horrible-visually-hidden", hide); +} + +export function bindPlaybook({ + document: rootDocument = globalThis.document, + onClean, + spawnPopup, + prefersReduced = () => false +} = {}) { + const root = rootDocument; + if (!root) return { enable() {}, disable() {}, beforeClean() { return false; }, afterClean() {} }; + + const view = () => root.defaultView || globalThis; + const reduced = () => prefersReduced(view()); + const isOn = () => root.documentElement.dataset.horrible === "on"; + + const input = root.querySelector("#url-input"); + const form = root.querySelector("#clean-form"); + const cleanButton = root.querySelector("#clean-form button.primary-button[type='submit']"); + const pasteButton = root.querySelector("#paste-button"); + const inspectButton = root.querySelector("#inspect-button"); + const copyButton = root.querySelector("#copy-button"); + const notNowButton = root.querySelector("#clipboard-offer-dismiss"); + const themeToggle = root.querySelector("#theme-toggle"); + const cleanOnPaste = root.querySelector("#clean-on-paste"); + const autoCopy = root.querySelector("#auto-copy"); + const aggressiveMode = root.querySelector("#aggressive-mode"); + const removeDuplicates = root.querySelector("#remove-duplicates"); + const resultPanel = root.querySelector("#result-panel"); + const cleanedUrl = root.querySelector("#cleaned-url"); + const message = root.querySelector("#message"); + const settings = root.querySelector(".settings"); + const popupHost = root.querySelector("#horrible-popups"); + + let enabled = false; + let captchaDone = false; + let splashDone = false; + let tourIndex = 0; + let swapLabels = false; + let zoomSeed = 0; + let narratorIndex = 0; + let soundIndex = 0; + let themeIndex = 0; + let winds = 0; + let holdTimer = 0; + let holdStart = null; + let gravityFrame = 0; + let lastGravity = 0; + let primes = resetPrimes(); + let shellOrder = initialShellOrder(); + let querrySpawned = false; + let savedLabels = null; + let savedSettings = null; + const gravity = { + paste: 100, + copy: 0, + aggressive: 0, + duplicates: 0 + }; + + const host = () => root.querySelector("#horrible-playbook"); + const overlays = () => root.querySelector("#horrible-overlays"); + const q = (selector) => root.querySelector(selector); + + const showSound = (phrase) => { + const caption = q("[data-idea='32']"); + if (!caption) return; + caption.textContent = phrase || pickSoundCaption(soundIndex); + soundIndex += 1; + caption.classList.add("is-on"); + view().setTimeout(() => caption.classList.remove("is-on"), 1800); + }; + + const showNarrator = (line) => { + const bar = q("[data-idea='29']"); + if (!bar) return; + bar.textContent = line || pickNarratorLine(narratorIndex); + narratorIndex += 1; + }; + + const syncMarquee = () => { + const mirror = q("[data-idea='1'] .horrible-marquee-text"); + if (mirror) mirror.textContent = input?.value || "type something. it will leave you."; + }; + + const syncPasswordRules = () => { + const list = q("[data-idea='4']"); + if (!list) return; + const results = evaluatePasswordRules(input?.value || ""); + for (const rule of results) { + const item = list.querySelector(`[data-rule='${rule.id}']`); + if (item) item.classList.toggle("is-ok", rule.ok); + } + }; + + const setCheckbox = (box, on) => { + if (!box || box.checked === on) return; + box.checked = on; + box.dispatchEvent(new Event("change", { bubbles: true })); + }; + + const syncGravityUi = () => { + if (!enabled || !isOn()) return; + const map = { + paste: cleanOnPaste, + copy: autoCopy, + aggressive: aggressiveMode, + duplicates: removeDuplicates + }; + for (const [key, box] of Object.entries(map)) { + const slider = q(`[data-gravity='${key}']`); + if (slider) slider.value = String(Math.round(gravity[key])); + setCheckbox(box, gravityIsOn(gravity[key])); + } + }; + + const snapshotSettings = () => ({ + paste: Boolean(cleanOnPaste?.checked), + copy: Boolean(autoCopy?.checked), + aggressive: Boolean(aggressiveMode?.checked), + duplicates: Boolean(removeDuplicates?.checked) + }); + + const restoreSettings = () => { + if (!savedSettings) return; + const snap = savedSettings; + savedSettings = null; + setCheckbox(cleanOnPaste, snap.paste); + setCheckbox(autoCopy, snap.copy); + setCheckbox(aggressiveMode, snap.aggressive); + setCheckbox(removeDuplicates, snap.duplicates); + }; + + const tickGravity = (now) => { + if (!enabled || !isOn() || reduced()) { + gravityFrame = 0; + return; + } + const dt = lastGravity ? Math.min(0.05, (now - lastGravity) / 1000) : 0.016; + lastGravity = now; + for (const key of Object.keys(gravity)) { + gravity[key] = stepGravity(gravity[key], dt); + } + syncGravityUi(); + gravityFrame = view().requestAnimationFrame(tickGravity); + }; + + const startGravity = () => { + if (reduced() || gravityFrame) return; + lastGravity = 0; + gravityFrame = view().requestAnimationFrame(tickGravity); + }; + + const stopGravity = () => { + if (gravityFrame) view().cancelAnimationFrame(gravityFrame); + gravityFrame = 0; + }; + + const syncPrimes = () => { + const out = q("[data-idea='17'] .horrible-prime-product"); + if (out) out.textContent = `product ${primes.product}`; + setCheckbox(aggressiveMode, primes.aggressive || gravityIsOn(gravity.aggressive)); + }; + + const applyZoom = () => { + root.documentElement.style.setProperty("--horrible-scale", String(nextZoomScale(zoomSeed))); + }; + + const applyTheme = () => { + const name = HORRIBLE_THEMES[themeIndex % HORRIBLE_THEMES.length]; + root.documentElement.dataset.horribleTheme = name; + const label = q("[data-idea='18']"); + if (label) label.textContent = `Theme: ${name.replace(/-/g, " ")}`; + }; + + const setSwap = (on) => { + swapLabels = on; + root.documentElement.classList.toggle("horrible-swap-labels", on); + const chip = q("[data-idea='14']"); + if (chip) chip.hidden = !on; + }; + + const setCaseOpen = (open) => { + q("[data-idea='12']")?.classList.toggle("is-open", open); + }; + + const setCaptchaOpen = (open) => { + const panel = q("[data-idea='5']"); + if (panel) panel.hidden = !open; + }; + + const setSplashOpen = (open) => { + const splash = q("[data-idea='26']"); + if (splash) splash.hidden = !open; + }; + + const setDialupOpen = (open) => { + const panel = q("[data-idea='33']"); + if (panel) panel.hidden = !open; + }; + + const setCookieOpen = (open) => { + const banner = q("[data-idea='23']"); + if (banner) banner.hidden = !open; + }; + + const renderTour = () => { + const card = q("[data-idea='25']"); + if (!card) return; + if (tourIndex < 0 || tourIndex >= TOUR_STEPS.length) { + card.hidden = true; + return; + } + const step = TOUR_STEPS[tourIndex]; + card.hidden = false; + card.querySelector(".horrible-tour-count").textContent = `Step ${step.n} of ${step.of}`; + card.querySelector(".horrible-tour-text").textContent = step.text; + const next = card.querySelector(".horrible-tour-next"); + next.className = `horrible-tour-next horrible-tour-slot-${tourIndex}`; + }; + + const skipTour = () => { + tourIndex = TOUR_STEPS.length; + renderTour(); + }; + + const fillCaptcha = (cells) => { + const grid = q("[data-idea='5'] .horrible-captcha-grid"); + if (!grid) return; + grid.replaceChildren(); + for (const text of cells) { + const cell = el(root, "button", "horrible-captcha-cell", text); + cell.type = "button"; + cell.dataset.fragment = text; + cell.classList.toggle("has-utm", captchaCellHasUtm(text)); + grid.append(cell); + } + }; + + const renderShell = () => { + const stage = q("[data-idea='8'] .horrible-shell-stage"); + if (!stage) return; + const cups = [...stage.querySelectorAll(".horrible-cup")]; + cups.forEach((cup, index) => { + cup.dataset.kind = shellOrder[index] || "unclean-a"; + cup.style.setProperty("--cup-x", `${index * 34}%`); + cup.querySelector(".horrible-cup-label").textContent = + shellOrder[index] === "clean" ? "Clean?" : "That was the Unclean button"; + }); + }; + + const shuffleShell = () => { + if (reduced()) return; + shellOrder = shuffleCups(shellOrder, Math.floor(Math.random() * SHELL_CUP_COUNT)); + renderShell(); + }; + + const restoreLabels = () => { + if (!savedLabels) return; + for (const [button, text] of savedLabels) setButtonLabel(button, text); + savedLabels = null; + }; + + const applyLabels = () => { + if (savedLabels) return; + savedLabels = []; + const swaps = [ + [pasteButton, "Execute sanitizeQueryParams()"], + [inspectButton, "inspectTrackingGraph()"], + [copyButton, "Copy? / Copy, but sadder"], + [notNowButton, "No thanks, I enjoy being tracked"], + [cleanButton, "NO"] + ]; + for (const [button, joke] of swaps) { + if (!button) continue; + savedLabels.push([button, readButtonLabel(button)]); + setButtonLabel(button, joke); + } + }; + + const requestPointerClean = () => { + if (!enabled || !isOn()) return; + if (!captchaDone) { + setCaptchaOpen(true); + showSound("[a tiny quiz fanfare, imagined]"); + return; + } + runGatedClean(); + }; + + const runGatedClean = () => { + const wait = dialupMs(reduced()); + if (!wait) { + setDialupOpen(false); + onClean?.(); + return; + } + setDialupOpen(true); + showSound("[dial-up screaming]"); + view().setTimeout(() => { + setDialupOpen(false); + onClean?.(); + }, wait); + }; + + const spawnQuerry = () => { + if (!enabled || !isOn() || querrySpawned || !spawnPopup) return; + const popup = spawnPopup({ + title: "Querry thinks you're writing a URL", + body: "It looks like you're pasting a URL. Would you like help? (it's a joke 🤡)", + action: "no, Querry" + }); + if (!popup) return; + querrySpawned = true; + const mascot = el(root, "div", "horrible-querry"); + mascot.setAttribute("aria-hidden", "true"); + mascot.textContent = "?"; + popup.prepend(mascot); + }; + + const onInput = () => { + if (!enabled || !isOn()) return; + syncMarquee(); + syncPasswordRules(); + showSound(pickSoundCaption(soundIndex)); + spawnQuerry(); + }; + + const onCleanClick = (event) => { + if (!enabled || !isOn()) return; + if (event.detail === 0) return; + event.preventDefault(); + event.stopPropagation(); + showSound("[a button that refuses]"); + }; + + const onThemeClick = (event) => { + if (!enabled || !isOn()) return; + event.preventDefault(); + event.stopImmediatePropagation(); + themeIndex = (themeIndex + 1) % HORRIBLE_THEMES.length; + applyTheme(); + showSound("[theme wardrobe collapsing]"); + }; + + const onPlaybookClick = (event) => { + if (!enabled || !isOn()) return; + const target = event.target.closest("[data-act]"); + if (!target) return; + const act = target.dataset.act; + + if (act === "begin-open") { + q("[data-idea='9']")?.classList.toggle("is-open"); + return; + } + if (act === "here" || act === "begin-clean") { + requestPointerClean(); + return; + } + if (act === "coward") { + input?.focus(); + return; + } + if (act === "add-char") { + if (!input) return; + const slider = q("[data-idea='2'] input[type='range']"); + input.value = appendSliderChar(input.value, slider?.value); + input.dispatchEvent(new Event("input", { bubbles: true })); + return; + } + if (act === "skip-captcha") { + captchaDone = true; + setCaptchaOpen(false); + runGatedClean(); + return; + } + if (act === "hold") return; + if (act === "cup") { + const index = Number(target.dataset.index); + if (shellIsClean(shellOrder, index)) requestPointerClean(); + else showSound("[wrong cup, politely]"); + return; + } + if (act === "prime") { + primes = multiplyPrime(primes.product, Number(target.dataset.prime)); + if (primes.aggressive) gravity.aggressive = 80; + syncPrimes(); + return; + } + if (act === "prime-reset") { + primes = resetPrimes(); + syncPrimes(); + return; + } + if (act === "missile") { + const box = root.querySelector(target.dataset.target); + if (box) setCheckbox(box, !box.checked); + const undo = q("[data-act='false-alarm']"); + if (undo) undo.hidden = false; + return; + } + if (act === "false-alarm") { + setCheckbox(cleanOnPaste, true); + setCheckbox(autoCopy, false); + setCheckbox(aggressiveMode, false); + setCheckbox(removeDuplicates, false); + gravity.paste = 100; + gravity.copy = 0; + gravity.aggressive = 0; + gravity.duplicates = 0; + primes = resetPrimes(); + syncGravityUi(); + syncPrimes(); + target.hidden = true; + return; + } + if (act === "bob") { + const box = root.querySelector(target.dataset.target); + if (box) setCheckbox(box, !box.checked); + return; + } + if (act === "cookie") { + setCookieOpen(false); + return; + } + if (act === "splash-clean") { + splashDone = true; + setSplashOpen(false); + renderTour(); + return; + } + if (act === "splash-dead") { + showSound("[a planet that goes nowhere]"); + return; + } + if (act === "tour-next") { + tourIndex += 1; + renderTour(); + return; + } + if (act === "tour-skip") { + skipTour(); + return; + } + if (act === "hinge") { + setCaseOpen(true); + return; + } + if (act === "find95") { + showSound("[Not available in this dialog]"); + return; + } + if (act === "mute") { + target.textContent = "Already muted. We have no ears."; + return; + } + if (act === "midi-volume") return; + }; + + const onCaptchaGridClick = (event) => { + const cell = event.target.closest(".horrible-captcha-cell"); + if (!cell) return; + const [left, right] = splitCaptchaCell(cell.dataset.fragment); + const grid = cell.parentElement; + const replacement = [left, right].map((text) => { + const next = el(root, "button", "horrible-captcha-cell horrible-captcha-split", text); + next.type = "button"; + next.dataset.fragment = text; + next.classList.toggle("has-utm", captchaCellHasUtm(text)); + return next; + }); + cell.replaceWith(...replacement); + if (grid && grid.children.length > 18) { + captchaDone = true; + setCaptchaOpen(false); + } + }; + + const onRangeInput = (event) => { + const range = event.target.closest("input[type='range']"); + if (!range) return; + if (range.dataset.gravity) { + gravity[range.dataset.gravity] = Number(range.value) || 0; + syncGravityUi(); + return; + } + if (range.dataset.phone) { + const preview = q("[data-idea='2'] .horrible-phone-char"); + if (preview) preview.textContent = charFromSlider(range.value); + return; + } + }; + + const onWheelPointer = (event) => { + if (!enabled || !isOn()) return; + const wheel = event.target.closest("[data-idea='7'] .horrible-wheel"); + if (!wheel) return; + if (event.type === "pointerdown") { + wheel.setPointerCapture?.(event.pointerId); + wheel.dataset.y = String(event.clientY); + return; + } + if (event.type === "pointermove" && wheel.dataset.y) { + const prev = Number(wheel.dataset.y); + const delta = event.clientY - prev; + wheel.dataset.y = String(event.clientY); + const next = nextThumbwheelWinds(winds, delta); + winds = next.winds; + const offset = (Number.parseFloat(wheel.style.getPropertyValue("--wheel-y")) || 0) + delta; + wheel.style.setProperty("--wheel-y", `${offset}px`); + const count = q("[data-idea='7'] .horrible-wheel-count"); + if (count) { + count.textContent = `${Math.min(winds, THUMBWHEEL_WINDS_NEEDED)} / ${THUMBWHEEL_WINDS_NEEDED} winds`; + } + if (next.armed) { + winds = 0; + requestPointerClean(); + } + } + if (event.type === "pointerup" || event.type === "pointercancel") { + delete wheel.dataset.y; + } + }; + + const onHoldPointer = (event) => { + const button = event.target.closest("[data-act='hold']"); + if (!button) return; + if (event.type === "pointerdown") { + holdStart = { x: event.clientX, y: event.clientY }; + const bar = q("[data-idea='10'] .horrible-hold-bar"); + bar?.classList.add("is-filling"); + holdTimer = view().setTimeout(() => { + holdTimer = 0; + requestPointerClean(); + }, HOLD_CLEAN_MS); + return; + } + if (event.type === "pointermove" && holdStart && holdMovedTooFar(holdStart, { x: event.clientX, y: event.clientY })) { + view().clearTimeout(holdTimer); + holdTimer = 0; + holdStart = null; + q("[data-idea='10'] .horrible-hold-bar")?.classList.remove("is-filling"); + return; + } + if (event.type === "pointerup" || event.type === "pointercancel") { + view().clearTimeout(holdTimer); + holdTimer = 0; + holdStart = null; + q("[data-idea='10'] .horrible-hold-bar")?.classList.remove("is-filling"); + } + }; + + const beforeClean = ({ source, proceed } = {}) => { + if (!enabled || !isOn()) return false; + if (source === "form" || source === "keyboard") { + captchaDone = true; + setCaptchaOpen(false); + proceed?.(); + return true; + } + return false; + }; + + const afterClean = ({ url } = {}) => { + if (!enabled || !isOn()) return; + setSwap(!swapLabels); + zoomSeed += 1; + applyZoom(); + setCaseOpen(false); + showNarrator(); + showSound(pickSoundCaption(soundIndex)); + if (message && message.dataset.kind === "success") { + message.dataset.original = message.textContent; + message.textContent = PROGRAMMERISM_SUCCESS; + } + const slot = q("[data-idea='11']"); + if (slot && url && !reduced()) { + slot.hidden = false; + let tick = 0; + const timer = view().setInterval(() => { + tick += 1; + slot.textContent = slotCharsForTick(url, tick); + if (tick >= SLOT_TICKS) { + view().clearInterval(timer); + slot.textContent = url; + view().setTimeout(() => { + slot.hidden = true; + if (cleanedUrl) cleanedUrl.textContent = url; + }, 400); + } + }, 90); + } + }; + + const bindOnce = () => { + const rootHost = host(); + const overlayHost = overlays(); + if (!rootHost || rootHost.dataset.bound === "true") return; + rootHost.dataset.bound = "true"; + rootHost.addEventListener("click", onPlaybookClick); + rootHost.addEventListener("input", onRangeInput); + rootHost.addEventListener("pointerdown", onWheelPointer); + rootHost.addEventListener("pointermove", onWheelPointer); + rootHost.addEventListener("pointerup", onWheelPointer); + rootHost.addEventListener("pointercancel", onWheelPointer); + rootHost.addEventListener("pointerdown", onHoldPointer); + rootHost.addEventListener("pointermove", onHoldPointer); + rootHost.addEventListener("pointerup", onHoldPointer); + rootHost.addEventListener("pointercancel", onHoldPointer); + overlayHost?.addEventListener("click", onPlaybookClick); + q("[data-idea='5'] .horrible-captcha-grid")?.addEventListener("click", onCaptchaGridClick); + }; + + const enable = () => { + enabled = true; + bindOnce(); + savedSettings = snapshotSettings(); + applyLabels(); + applyTheme(); + applyZoom(); + syncMarquee(); + syncPasswordRules(); + fillCaptcha(CAPTCHA_FRAGMENTS); + setCaptchaOpen(false); + captchaDone = false; + setCookieOpen(true); + setSplashOpen(!splashDone); + if (splashDone) renderTour(); + else { + const card = q("[data-idea='25']"); + if (card) card.hidden = true; + } + setDialupOpen(false); + setCaseOpen(false); + setSwap(false); + renderShell(); + if (!reduced()) view().setTimeout(shuffleShell, 900); + syncPrimes(); + gravity.paste = cleanOnPaste?.checked ? 100 : 0; + gravity.copy = autoCopy?.checked ? 100 : 0; + gravity.aggressive = aggressiveMode?.checked ? 100 : 0; + gravity.duplicates = removeDuplicates?.checked ? 100 : 0; + syncGravityUi(); + startGravity(); + visuallyHide(settings?.querySelector("legend"), false); + if (cleanOnPaste) visuallyHide(cleanOnPaste.closest(".setting"), true); + if (autoCopy) visuallyHide(autoCopy.closest(".setting"), true); + if (aggressiveMode) visuallyHide(aggressiveMode.closest(".setting"), true); + if (removeDuplicates) visuallyHide(removeDuplicates.closest(".setting"), true); + view().setTimeout(spawnQuerry, 1200); + const phone = q("[data-idea='2'] input[type='range']"); + if (phone) phone.value = String(clampAsciiCode(104)); + const preview = q("[data-idea='2'] .horrible-phone-char"); + if (preview) preview.textContent = "h"; + const midi = q("[data-idea='31'] .horrible-midi-bar"); + midi?.classList.toggle("is-playing", !reduced()); + }; + + const disable = () => { + enabled = false; + stopGravity(); + view().clearTimeout(holdTimer); + holdTimer = 0; + restoreLabels(); + restoreSettings(); + setCaptchaOpen(true); + const captcha = q("[data-idea='5']"); + if (captcha) captcha.hidden = true; + setSplashOpen(true); + const splash = q("[data-idea='26']"); + if (splash) splash.hidden = true; + setCookieOpen(true); + const cookie = q("[data-idea='23']"); + if (cookie) cookie.hidden = true; + setDialupOpen(false); + skipTour(); + const tour = q("[data-idea='25']"); + if (tour) tour.hidden = true; + setCaseOpen(false); + setSwap(false); + delete root.documentElement.dataset.horribleTheme; + root.documentElement.style.removeProperty("--horrible-scale"); + root.documentElement.classList.remove("horrible-swap-labels"); + if (cleanOnPaste) visuallyHide(cleanOnPaste.closest(".setting"), false); + if (autoCopy) visuallyHide(autoCopy.closest(".setting"), false); + if (aggressiveMode) visuallyHide(aggressiveMode.closest(".setting"), false); + if (removeDuplicates) visuallyHide(removeDuplicates.closest(".setting"), false); + captchaDone = false; + splashDone = false; + tourIndex = 0; + winds = 0; + querrySpawned = false; + primes = resetPrimes(); + themeIndex = 0; + if (message?.dataset.original) { + message.textContent = message.dataset.original; + delete message.dataset.original; + } + }; + + cleanButton?.addEventListener("click", onCleanClick); + themeToggle?.addEventListener("click", onThemeClick, true); + input?.addEventListener("input", onInput); + form?.addEventListener("submit", () => { + if (enabled && isOn()) showSound("[form submission, silently]"); + }); + + return { + enable, + disable, + beforeClean, + afterClean, + skipTour, + requestPointerClean + }; +} + +export { HORRIBLE_THEMES }; diff --git a/index.html b/index.html index 86f1ead..3b606e0 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,7 @@ +
it's a joke 🤡
+ +Australia mode
+ +The big button says NO. If you meant clean, click .
+Thumbwheel Clean. Drag up five times.
+ +0 / 5 winds
+Shell game. One cup is Clean.
+Gravity sliders sink to Off. Above 50% counts as On.
+ + + + +product 1
+ + + + + +Theme: light
+Terms of Cleaning
+By pretending to agree you agree that nothing is agreed. Cleaning happens locally. These terms scroll because 1999 said so. There is no payment. There is no account. There is only this box. I do not not agree is a joke checkbox and never gates a real action. If you can still read this, the scroll is doing its job too slowly, which is the point.
+Results arrive in this jewel case. Click the hinge.
+ +Programmerisms swap button labels only.
+Confirmshaming jokes never store a choice.
+Querry is an original question-mark mascot.
+Comic Sans uses local fonts only.
+Zoom roulette uses a local scale token.
+Hourglass cursor is a local data SVG.
+ +Now playing: tracker_theme.mid
+it's a joke 🤡
+Select all squares containing utm_source
+ + +it's a joke 🤡
+Welcome to URL SPACE. Only Clean leads anywhere.
+Step 3 of 2
+First, paste a URL. This is step 3. Do not ask questions.
+ + +it's a joke 🤡
+EEEE-KRRRR-SHHHH
+ +