Auto ColorTest

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

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

  1. // ==UserScript==
  2. // @name Auto ColorTest
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Whenever the page contains “过关” and #box.lv{n}, click the single span whose background‑color is unique. Runs continuously.
  6. // @match https://www.webhek.com/post/color-test/
  7. // @run-at document-start
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (() => {
  13. const pass = /过关/;
  14. const flag = 'data-oddspan-clicked';
  15. const isBox = e => e instanceof HTMLElement && e.id === 'box' && [...e.classList].some(c => /^lv\d+$/.test(c));
  16. const clickUnique = b => {
  17. const s = [...b.querySelectorAll('span')].filter(x => !x.hasAttribute(flag));
  18. if (!s.length) return;
  19. const m = new Map();
  20. s.forEach(x => {
  21. const c = getComputedStyle(x).backgroundColor.trim();
  22. (m.get(c) || m.set(c, []).get(c)).push(x);
  23. });
  24. let t = null, n = 1e9;
  25. m.forEach(v => { if (v.length === 1) t = v[0]; else if (!t && v.length < n) { n = v.length; t = v[0]; } });
  26. if (!t) return;
  27. t.setAttribute(flag, '1');
  28. t.scrollIntoView({block:'center'});
  29. t.click();
  30. };
  31. const scan = () => { if (!pass.test(document.body?.innerText||'')) return; const b = document.getElementById('box'); if (b && isBox(b)) clickUnique(b); };
  32. let pend = false;
  33. const schedule = () => { if (pend) return; pend = true; requestAnimationFrame(() => { pend = false; scan(); }); };
  34. document.addEventListener('DOMContentLoaded', () => {
  35. scan();
  36. new MutationObserver(schedule).observe(document.body, {childList:true,subtree:true});
  37. setInterval(scan, 10);
  38. });
  39. })();