From 5cfa41c2fc605db5e56f3fbe359da4fbc01a4c37 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 25 Oct 2026 12:52:17 +0000 Subject: [PATCH 1/2] Recompute the cleaned URL after Horrible settings restore Make it stop and Escape restore Aggressive and Duplicates after the mode flag is off, then run the clean once so the shown result matches the restored settings. Co-authored-by: Andromeda --- app.js | 10 +++++++ horrible.js | 21 ++++++++++++-- horrible/logic.js | 6 ++++ horrible/playbook.js | 16 +++++++---- tests/horrible-playbook.playwright.mjs | 39 ++++++++++++++++++++++++++ tests/horrible.test.js | 11 ++++++++ 6 files changed, 94 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index c955185..7f632ca 100644 --- a/app.js +++ b/app.js @@ -873,6 +873,16 @@ horribleEffects = bindHorriblePage({ onStop: () => { saveSetting(STORAGE_KEYS.horrible, false); applyHorribleMode(false); + }, + onSettingsRestored: ({ snap, cleaningChanged } = {}) => { + if (!snap || horribleIsOn()) return; + saveSetting(STORAGE_KEYS.cleanOnPaste, snap.paste); + saveSetting(STORAGE_KEYS.autoCopy, snap.copy); + saveSetting(STORAGE_KEYS.aggressiveMode, snap.aggressive); + saveSetting(STORAGE_KEYS.removeDuplicates, snap.duplicates); + if (cleaningChanged && input.value.trim()) { + runClean({ allowAutoCopy: false }); + } } }); horribleEffects.setEnabled(document.documentElement.dataset.horrible === "on"); diff --git a/horrible.js b/horrible.js index 4eea54d..ead5cf8 100644 --- a/horrible.js +++ b/horrible.js @@ -150,7 +150,8 @@ export function bindHorriblePage({ hitCounter, guestbook, onStop, - onClean + onClean, + onSettingsRestored } = {}) { const root = rootDocument; if (!root) return { dispose() {}, setEnabled() {}, clearPopups() {} }; @@ -164,6 +165,7 @@ export function bindHorriblePage({ let cleanWindowUntil = 0; let spawnTimer = 0; let enabled = false; + let pendingRestore = null; const isHorrible = () => root.documentElement.dataset.horrible === "on"; const view = () => root.defaultView || globalThis; @@ -349,6 +351,17 @@ export function bindHorriblePage({ afterClean() {} }; + const noteRestore = (restored) => { + if (restored?.snap) pendingRestore = restored; + }; + + const flushRestore = () => { + if (isHorrible() || !pendingRestore) return; + const pending = pendingRestore; + pendingRestore = null; + onSettingsRestored?.(pending); + }; + const setEnabled = (nextEnabled) => { enabled = Boolean(nextEnabled); if (enabled && isHorrible()) { @@ -356,15 +369,17 @@ export function bindHorriblePage({ playbook.enable(); } else { stopStorm(); - playbook.disable(); + noteRestore(playbook.disable()); + flushRestore(); } }; const stopEverything = () => { enabled = false; stopStorm(); - playbook.disable(); + noteRestore(playbook.disable()); onStop?.(); + flushRestore(); }; const onEscape = (event) => { diff --git a/horrible/logic.js b/horrible/logic.js index 7fffeb7..0ecc4e6 100644 --- a/horrible/logic.js +++ b/horrible/logic.js @@ -239,6 +239,12 @@ export function shouldCommitSlotReveal(generation, activeGeneration, enabled) { return Boolean(enabled) && generation === activeGeneration; } +export function cleaningOptionsChanged(before, after) { + if (!before || !after) return false; + return Boolean(before.aggressive) !== Boolean(after.aggressive) + || Boolean(before.duplicates) !== Boolean(after.duplicates); +} + export function slotCharsForTick(finalText, tick, alphabet = "abcdefghijklmnopqrstuvwxyz0123456789:/?&=._-%") { const text = String(finalText ?? ""); if (tick >= SLOT_TICKS) return text; diff --git a/horrible/playbook.js b/horrible/playbook.js index 3b8cfdd..4f957a4 100644 --- a/horrible/playbook.js +++ b/horrible/playbook.js @@ -16,6 +16,7 @@ import { TOUR_STEPS, appendSliderChar, captchaCellHasUtm, + cleaningOptionsChanged, charFromSlider, clampAsciiCode, dialupMs, @@ -208,11 +209,13 @@ export function bindPlaybook({ const snap = savedSettings || readHorribleSettingsSnapshot(settingsStorage()); savedSettings = null; clearHorribleSettingsSnapshot(settingsStorage()); - if (!snap) return; - setCheckbox(cleanOnPaste, snap.paste, { persist: true }); - setCheckbox(autoCopy, snap.copy, { persist: true }); - setCheckbox(aggressiveMode, snap.aggressive, { persist: true }); - setCheckbox(removeDuplicates, snap.duplicates, { persist: true }); + if (!snap) return null; + const before = snapshotSettings(); + setCheckbox(cleanOnPaste, snap.paste); + setCheckbox(autoCopy, snap.copy); + setCheckbox(aggressiveMode, snap.aggressive); + setCheckbox(removeDuplicates, snap.duplicates); + return { snap, cleaningChanged: cleaningOptionsChanged(before, snap) }; }; const stopSlotReveal = () => { @@ -770,7 +773,7 @@ export function bindPlaybook({ view().clearTimeout(holdTimer); holdTimer = 0; restoreLabels(); - restoreSettings(); + const restored = restoreSettings(); setCaptchaOpen(true); const captcha = q("[data-idea='5']"); if (captcha) captcha.hidden = true; @@ -804,6 +807,7 @@ export function bindPlaybook({ message.textContent = message.dataset.original; delete message.dataset.original; } + return restored; }; cleanButton?.addEventListener("click", onCleanClick); diff --git a/tests/horrible-playbook.playwright.mjs b/tests/horrible-playbook.playwright.mjs index 9ef1814..06cfd90 100644 --- a/tests/horrible-playbook.playwright.mjs +++ b/tests/horrible-playbook.playwright.mjs @@ -160,6 +160,45 @@ try { assert.notEqual(await page.evaluate(() => localStorage.getItem("url-cleaner.clean-on-paste")), "false"); assert.equal(await page.evaluate(() => localStorage.getItem("url-cleaner.horrible-settings")), null); + await page.fill("#url-input", "https://example.com/?ref=important"); + await page.locator("#url-input").focus(); + await page.keyboard.press("Control+Enter"); + await page.waitForFunction(() => document.querySelector("#cleaned-url")?.textContent.trim() === "https://example.com/?ref=important", null, { timeout: 5000 }); + await page.check("#horrible-mode"); + await page.waitForSelector('[data-idea="26"]:not([hidden])', { timeout: 3000 }); + await page.click('[data-act="splash-clean"]', { force: true }); + if (await page.locator('[data-idea="23"]:not([hidden])').count()) { + await page.locator('[data-act="cookie"]').first().click({ force: true }); + } + if (await page.locator('[data-idea="25"]:not([hidden])').count()) { + await page.click('[data-act="tour-skip"]', { force: true }); + } + await page.locator("[data-gravity='aggressive']").fill("80"); + assert.equal(await page.locator("#aggressive-mode").isChecked(), true); + await page.locator("#url-input").focus(); + await page.keyboard.press("Enter"); + await page.waitForFunction(() => document.querySelector("#cleaned-url")?.textContent.trim() === "https://example.com/", null, { timeout: 5000 }); + await page.click("#horrible-stop"); + await page.waitForFunction(() => !document.documentElement.dataset.horrible, null, { timeout: 3000 }); + assert.equal(await page.locator("#aggressive-mode").isChecked(), false); + assert.equal((await page.locator("#cleaned-url").textContent()).trim(), "https://example.com/?ref=important", "Make it stop must recompute after restoring Aggressive"); + + await page.check("#horrible-mode"); + await page.click('[data-act="splash-clean"]', { force: true }); + if (await page.locator('[data-idea="25"]:not([hidden])').count()) { + await page.click('[data-act="tour-skip"]', { force: true }); + } + await page.locator("[data-gravity='duplicates']").fill("80"); + assert.equal(await page.locator("#remove-duplicates").isChecked(), true); + await page.fill("#url-input", "https://example.com/?id=1&id=1"); + await page.locator("#url-input").focus(); + await page.keyboard.press("Enter"); + await page.waitForFunction(() => document.querySelector("#cleaned-url")?.textContent.trim() === "https://example.com/?id=1", null, { timeout: 5000 }); + await page.keyboard.press("Escape"); + await page.waitForFunction(() => !document.documentElement.dataset.horrible, null, { timeout: 3000 }); + assert.equal(await page.locator("#remove-duplicates").isChecked(), false); + assert.equal((await page.locator("#cleaned-url").textContent()).trim(), "https://example.com/?id=1&id=1", "Escape must recompute after restoring duplicate cleanup"); + const faviconCspNoise = consoleErrors.filter((text) => /favicon|apple-touch-icon/i.test(text) && /Content-Security-Policy|connect-src/i.test(text)); const realErrors = consoleErrors.filter((text) => !faviconCspNoise.includes(text)); assert.equal(realErrors.length, 0, `Console/page errors:\n${realErrors.join("\n")}`); diff --git a/tests/horrible.test.js b/tests/horrible.test.js index c596712..0f97927 100644 --- a/tests/horrible.test.js +++ b/tests/horrible.test.js @@ -29,6 +29,7 @@ import { appendSliderChar, applyPopupDismissal, captchaCellHasUtm, + cleaningOptionsChanged, charFromSlider, clampZoom, dialupMs, @@ -142,6 +143,8 @@ test("app stops horrible mode from the panic button and Escape", () => { assert.match(app, /__urlCleaner/); assert.match(app, /source:\s*"keyboard"/); assert.match(app, /if \(horribleIsOn\(\)\) return;/); + assert.match(app, /onSettingsRestored/); + assert.match(app, /cleaningChanged && input\.value\.trim\(\)/); }); test("dodge helpers cycle a few classes then give up", () => { @@ -225,6 +228,10 @@ test("playbook ships all 33 ideas behind the horrible toggle", () => { assert.match(js, /rememberSettings/); assert.match(js, /restoreSettings/); assert.match(js, /stopSlotReveal/); + assert.match(js, /cleaningOptionsChanged/); + const page = readFileSync(join(root, "horrible.js"), "utf8"); + assert.match(page, /onSettingsRestored/); + assert.match(page, /flushRestore/); assert.match(js, /shouldCommitSlotReveal/); assert.match(js, /readHorribleSettingsSnapshot/); }); @@ -254,4 +261,8 @@ test("playbook helpers stay local and never block the real URL", () => { assert.equal(shouldCommitSlotReveal(1, 1, true), true); assert.equal(shouldCommitSlotReveal(1, 2, true), false); assert.equal(shouldCommitSlotReveal(3, 3, false), false); + assert.equal(cleaningOptionsChanged({ aggressive: true, duplicates: false }, { aggressive: false, duplicates: false }), true); + assert.equal(cleaningOptionsChanged({ aggressive: false, duplicates: true }, { aggressive: false, duplicates: false }), true); + assert.equal(cleaningOptionsChanged({ aggressive: false, duplicates: false }, { aggressive: false, duplicates: false }), false); + assert.equal(cleaningOptionsChanged(null, { aggressive: true }), false); }); From dc87dc144a0f283957fa0cc8e2d18b9947b4e369 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 25 Oct 2026 13:05:25 +0000 Subject: [PATCH 2/2] Reclean from the options the visible result was computed with Gravity can sink Aggressive back to Off before Make it stop, so a checkbox diff never recleans. Compare the restored settings to the options used for the result on screen. Co-authored-by: Andromeda --- app.js | 25 +++++++++++++++++++++---- tests/horrible-playbook.playwright.mjs | 17 +++++++++++------ tests/horrible.test.js | 8 +++++++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 7f632ca..364b5fa 100644 --- a/app.js +++ b/app.js @@ -30,6 +30,7 @@ import { popHorribleStamp, spawnHorribleConfetti } from "./horrible.js"; +import { cleaningOptionsChanged } from "./horrible/logic.js"; const form = document.querySelector("#clean-form"); const input = document.querySelector("#url-input"); @@ -79,6 +80,7 @@ const horribleMode = document.querySelector("#horrible-mode"); let cleanedValue = ""; let batchCopyValue = ""; +let resultCleanOptions = null; let clipboardOfferValue = ""; let totdCollapsed = false; @@ -421,6 +423,17 @@ function hideResults() { batchCopyValue = ""; } +function hasVisibleResult() { + return resultPanel.hidden === false || batchPanel.hidden === false; +} + +function currentCleanOptions() { + return { + aggressive: aggressiveMode.checked, + duplicates: removeDuplicates.checked + }; +} + function showCleanResult(result, { allowAutoCopy = true, originalValue = "", revealInspection = false } = {}) { cleanedValue = result.url; renderOriginalUrl( @@ -550,15 +563,17 @@ function requestClean(options = {}) { function runClean(options = {}) { hideResults(); + const computedWith = currentCleanOptions(); const entries = cleanBatch(input.value, { - aggressive: aggressiveMode.checked, - removeDuplicateParameters: removeDuplicates.checked + aggressive: computedWith.aggressive, + removeDuplicateParameters: computedWith.duplicates }); if (entries.length === 0) { showMessage("Paste or type a URL to clean.", "error"); return; } + resultCleanOptions = computedWith; if (entries.length === 1) { const [entry] = entries; @@ -782,6 +797,7 @@ input.addEventListener("input", () => { message.textContent = ""; delete message.dataset.kind; hideResults(); + resultCleanOptions = null; } }); @@ -874,13 +890,14 @@ horribleEffects = bindHorriblePage({ saveSetting(STORAGE_KEYS.horrible, false); applyHorribleMode(false); }, - onSettingsRestored: ({ snap, cleaningChanged } = {}) => { + onSettingsRestored: ({ snap } = {}) => { if (!snap || horribleIsOn()) return; saveSetting(STORAGE_KEYS.cleanOnPaste, snap.paste); saveSetting(STORAGE_KEYS.autoCopy, snap.copy); saveSetting(STORAGE_KEYS.aggressiveMode, snap.aggressive); saveSetting(STORAGE_KEYS.removeDuplicates, snap.duplicates); - if (cleaningChanged && input.value.trim()) { + const restored = { aggressive: snap.aggressive, duplicates: snap.duplicates }; + if (hasVisibleResult() && input.value.trim() && cleaningOptionsChanged(resultCleanOptions, restored)) { runClean({ allowAutoCopy: false }); } } diff --git a/tests/horrible-playbook.playwright.mjs b/tests/horrible-playbook.playwright.mjs index 06cfd90..d794436 100644 --- a/tests/horrible-playbook.playwright.mjs +++ b/tests/horrible-playbook.playwright.mjs @@ -173,31 +173,36 @@ try { if (await page.locator('[data-idea="25"]:not([hidden])').count()) { await page.click('[data-act="tour-skip"]', { force: true }); } - await page.locator("[data-gravity='aggressive']").fill("80"); + await page.locator("[data-gravity='aggressive']").fill("100"); assert.equal(await page.locator("#aggressive-mode").isChecked(), true); await page.locator("#url-input").focus(); await page.keyboard.press("Enter"); await page.waitForFunction(() => document.querySelector("#cleaned-url")?.textContent.trim() === "https://example.com/", null, { timeout: 5000 }); + await page.waitForFunction(() => !document.querySelector("#aggressive-mode").checked, null, { timeout: 8000 }); await page.click("#horrible-stop"); await page.waitForFunction(() => !document.documentElement.dataset.horrible, null, { timeout: 3000 }); assert.equal(await page.locator("#aggressive-mode").isChecked(), false); - assert.equal((await page.locator("#cleaned-url").textContent()).trim(), "https://example.com/?ref=important", "Make it stop must recompute after restoring Aggressive"); + assert.equal((await page.locator("#cleaned-url").textContent()).trim(), "https://example.com/?ref=important", "Make it stop must recompute after gravity sinks Aggressive"); + assert.doesNotMatch(await page.locator("#message").textContent(), /Tracking parameters removed/); await page.check("#horrible-mode"); await page.click('[data-act="splash-clean"]', { force: true }); if (await page.locator('[data-idea="25"]:not([hidden])').count()) { await page.click('[data-act="tour-skip"]', { force: true }); } - await page.locator("[data-gravity='duplicates']").fill("80"); + await page.locator("[data-gravity='duplicates']").fill("100"); assert.equal(await page.locator("#remove-duplicates").isChecked(), true); - await page.fill("#url-input", "https://example.com/?id=1&id=1"); + await page.fill("#url-input", "https://example.com/keep?id=1&id=1"); await page.locator("#url-input").focus(); await page.keyboard.press("Enter"); - await page.waitForFunction(() => document.querySelector("#cleaned-url")?.textContent.trim() === "https://example.com/?id=1", null, { timeout: 5000 }); + await page.waitForFunction(() => document.querySelector("#cleaned-url")?.textContent.trim() === "https://example.com/keep?id=1", null, { timeout: 5000 }); + const duplicatesOn = (await page.locator("#cleaned-url").textContent()).trim(); await page.keyboard.press("Escape"); await page.waitForFunction(() => !document.documentElement.dataset.horrible, null, { timeout: 3000 }); assert.equal(await page.locator("#remove-duplicates").isChecked(), false); - assert.equal((await page.locator("#cleaned-url").textContent()).trim(), "https://example.com/?id=1&id=1", "Escape must recompute after restoring duplicate cleanup"); + const duplicatesOff = (await page.locator("#cleaned-url").textContent()).trim(); + assert.equal(duplicatesOff, "https://example.com/keep?id=1&id=1"); + assert.notEqual(duplicatesOff, duplicatesOn, "Escape must change the result when Duplicates is restored"); const faviconCspNoise = consoleErrors.filter((text) => /favicon|apple-touch-icon/i.test(text) && /Content-Security-Policy|connect-src/i.test(text)); const realErrors = consoleErrors.filter((text) => !faviconCspNoise.includes(text)); diff --git a/tests/horrible.test.js b/tests/horrible.test.js index 0f97927..53b2d59 100644 --- a/tests/horrible.test.js +++ b/tests/horrible.test.js @@ -144,7 +144,8 @@ test("app stops horrible mode from the panic button and Escape", () => { assert.match(app, /source:\s*"keyboard"/); assert.match(app, /if \(horribleIsOn\(\)\) return;/); assert.match(app, /onSettingsRestored/); - assert.match(app, /cleaningChanged && input\.value\.trim\(\)/); + assert.match(app, /resultCleanOptions/); + assert.match(app, /cleaningOptionsChanged\(resultCleanOptions, restored\)/); }); test("dodge helpers cycle a few classes then give up", () => { @@ -265,4 +266,9 @@ test("playbook helpers stay local and never block the real URL", () => { assert.equal(cleaningOptionsChanged({ aggressive: false, duplicates: true }, { aggressive: false, duplicates: false }), true); assert.equal(cleaningOptionsChanged({ aggressive: false, duplicates: false }, { aggressive: false, duplicates: false }), false); assert.equal(cleaningOptionsChanged(null, { aggressive: true }), false); + const sunkCheckbox = { aggressive: false, duplicates: false }; + const restored = { aggressive: false, duplicates: false }; + const computedWhileOn = { aggressive: true, duplicates: false }; + assert.equal(cleaningOptionsChanged(sunkCheckbox, restored), false); + assert.equal(cleaningOptionsChanged(computedWhileOn, restored), true); });