Geoguessr Styles Scan

Provides utility functions to make your geoguessr scripts independent of arbitrary changes to class name suffixes

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/460322/1408713/Geoguessr%20Styles%20Scan.js

  1. // ==UserScript==
  2. // @name Geoguessr Styles Scan
  3. // @description Provides utility functions to make your geoguessr scripts independent of arbitrary changes to class name suffixes
  4. // @version 1.0.1
  5. // @author victheturtle#5159
  6. // @license MIT
  7. // @namespace https://greasyfork.org/users/967692-victheturtle
  8. // ==/UserScript==
  9.  
  10. const _cndic = {};
  11. const _hrefset = new Set();
  12.  
  13. async function scanStyles() {
  14. for (let node of document.querySelectorAll('head link[rel="stylesheet"], head style[data-n-href*=".css"]')) {
  15. const href = node.href || location.origin+node.dataset.nHref;
  16. if (_hrefset.has(href)) continue;
  17. _hrefset.add(href);
  18. await fetch(href)
  19. .then(res => res.text())
  20. .then(stylesheet => {
  21. for (let className of stylesheet.split(".")) {
  22. const ind = className.indexOf("__");
  23. if (ind != -1) _cndic[className.substr(0, ind+2)] = className.substr(0, ind+7);
  24. };
  25. });
  26. };
  27. };
  28.  
  29. const cn = (classNameStart) => _cndic[classNameStart]; // cn("status_section__") -> "status_section__8uP8o"
  30.  
  31. const checkAllStylesFound = (STYLES_USED) => STYLES_USED.reduce((res, className) => res && cn(className), true);
  32.  
  33. async function requireClassName(classNameStart) {
  34. if (_cndic[classNameStart]) return _cndic[classNameStart];
  35. return await scanStyles().then(() => _cndic[classNameStart]);
  36. }