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