9DB Raid Finder: Fix focus detection

Fixes the focus detection on the 9DB Pokémon GO Raid Finder

  1. // ==UserScript==
  2. // @name 9DB Raid Finder: Fix focus detection
  3. // @namespace m43v6blcjzeaiq6oh9
  4. // @match https://9db.jp/pokego/data/62
  5. // @match https://9db.jp/pokemongo/data/9906
  6. // @grant none
  7. // @version 1.0
  8. // @description Fixes the focus detection on the 9DB Pokémon GO Raid Finder
  9. // @run-at document-start
  10. // @inject-into content
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16.  
  17. const { CustomEvent } = window, { WeakSet } = globalThis;
  18.  
  19. // Block blur/focus events on window,
  20. // except the fake ones we create
  21. const whitelistedEvents = new WeakSet();
  22. const filterEvents = (event) => {
  23. // .delete() returns true if the element was actually removed
  24. if (!whitelistedEvents.delete(event)) {
  25. event.stopImmediatePropagation?.();
  26. }
  27. };
  28.  
  29. window.addEventListener("blur", filterEvents, { passive: true });
  30. window.addEventListener("focus", filterEvents, { passive: true });
  31.  
  32. // Convert visibility events to blur/focus events
  33. window.addEventListener("visibilitychange", function () {
  34. const fakeEvent = new CustomEvent((document.visibilityState === "hidden") ? "blur" : "focus");
  35.  
  36. whitelistedEvents.add(fakeEvent);
  37. this.dispatchEvent(fakeEvent);
  38. });
  39. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址