Auto ColorTest

Whenever the page contains “过关” and #box.lv{n}, click the single span whose background‑color is unique. Runs continuously.

当前为 2025-05-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Auto ColorTest
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Whenever the page contains “过关” and #box.lv{n}, click the single span whose background‑color is unique. Runs continuously.
// @match        *://*.webhek.com/post/color-test*
// @license MIT
// @grant        none
// ==/UserScript==

(() => {
  const pass = /过关/;
  const flag = 'data-oddspan-clicked';
  const isBox = e => e instanceof HTMLElement && e.id === 'box' && [...e.classList].some(c => /^lv\d+$/.test(c));
  const clickUnique = b => {
    const s = [...b.querySelectorAll('span')].filter(x => !x.hasAttribute(flag));
    if (!s.length) return;
    const m = new Map();
    s.forEach(x => {
      const c = getComputedStyle(x).backgroundColor.trim();
      (m.get(c) || m.set(c, []).get(c)).push(x);
    });
    let t = null, n = 1e9;
    m.forEach(v => { if (v.length === 1) t = v[0]; else if (!t && v.length < n) { n = v.length; t = v[0]; } });
    if (!t) return;
    t.setAttribute(flag, '1');
    t.scrollIntoView({block:'center'});
    t.click();
  };
  const scan = () => { if (!pass.test(document.body?.innerText||'')) return; const b = document.getElementById('box'); if (b && isBox(b)) clickUnique(b); };
  let pend = false;
  const schedule = () => { if (pend) return; pend = true; requestAnimationFrame(() => { pend = false; scan(); }); };
  document.addEventListener('DOMContentLoaded', () => {
    scan();
    new MutationObserver(schedule).observe(document.body, {childList:true,subtree:true});
    setInterval(scan, 0);
  });
})();