Greasy Fork

来自缓存

Greasy Fork is available in English.

Worldguessr 0.1 Flash Mode

AI-written script for Worldguessr to play 0.1 second / flash mode in single player

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Worldguessr 0.1 Flash Mode
// @version     1.0.0
// @description AI-written script for Worldguessr to play 0.1 second / flash mode in single player
// @author      Me and AI
// @license     MIT
// @match       https://www.worldguessr.com/*
// @namespace http://greasyfork.icu/users/1508060
// ==/UserScript==

(function () {
  const PEEK_TIME = 1550; // ms to show the view
  const STARTUP_SCAN_DURATION = 5000; // ms to keep scanning for round 1 iframe
  const STARTUP_SCAN_INTERVAL = 100; // ms between scans

  const seen = new WeakMap(); // iframe -> { lastSrc }

  function now() { return Date.now(); }

  function isSVIframe(node) {
    return node &&
           node.nodeType === 1 &&
           node.tagName === 'IFRAME' &&
           node.classList.contains('svframe');
  }

  function hideSV(el) {
    el.style.setProperty('display', 'none', 'important');
  }

  function showSV(el) {
    el.style.removeProperty('display');
  }

  function shouldFlash(iframe) {
    const state = seen.get(iframe);
    const src = iframe.getAttribute('src') || '__no_src__';
    // Only flash if we've never seen this iframe OR src changed
    return !state || state.lastSrc !== src;
  }

  function markFlashed(iframe) {
    seen.set(iframe, { lastSrc: iframe.getAttribute('src') || '__no_src__' });
  }

  function flash(iframe) {
    hideSV(iframe);
    requestAnimationFrame(() => {
      requestAnimationFrame(() => {
        showSV(iframe);
        markFlashed(iframe);
        setTimeout(() => hideSV(iframe), PEEK_TIME);
      });
    });
  }

  function primeAndFlash(iframe) {
    if (!iframe || !shouldFlash(iframe)) return;
    hideSV(iframe);
    let finished = false;
    const finish = () => {
      if (finished) return;
      finished = true;
      flash(iframe);
    };
    iframe.addEventListener('load', finish, { once: true });
    setTimeout(finish, 200); // fallback if already loaded
  }

  function scanExisting() {
    const iframes = document.querySelectorAll('iframe.svframe');
    if (iframes.length) {
      iframes.forEach(primeAndFlash);
      return true;
    }
    return false;
  }

  // MutationObserver for new iframes or src changes
  const obs = new MutationObserver(() => {
    scanExisting();
  });

  obs.observe(document.body, { childList: true, subtree: true });

  // Startup scan loop for round 1
  const startTime = now();
  const startupScan = setInterval(() => {
    if (scanExisting()) {
      clearInterval(startupScan);
    } else if (now() - startTime > STARTUP_SCAN_DURATION) {
      clearInterval(startupScan);
    }
  }, STARTUP_SCAN_INTERVAL);

  console.log('🚀 Street View flash active (round 1 + later rounds, no infinite loop)');
})();