谁家问号暗飞声?

修复 Scratch 问号问题而无需刷新页面。

  1. // ==UserScript==
  2. // @name Scratch Question mark fix
  3. // @name:zh-cn 谁家问号暗飞声?
  4. // @name:ja ハテナマークを何とか消せるやつ
  5. // @namespace ScratchStorageFix
  6. // @version 1.0
  7. // @description Fix question marks on Scratch without reloading.
  8. // @description:zh-cn 修复 Scratch 问号问题而无需刷新页面。
  9. // @description:ja リロード不要でハテナマーク問題をバッチリ解決。
  10. // @author FurryR
  11. // @license MIT
  12. // @match https://scratch.mit.edu/projects/*
  13. // @match https://aerfaying.com/Projects/*
  14. // @match https://gitblock.cn/Projects/*
  15. // @grant none
  16. // @run-at document-start
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21.  
  22. // Default to 64 for best performance.
  23. const MAX_PARALLEL_REQUESTS = 64;
  24.  
  25. function trap(callback) {
  26. const _bind = Function.prototype.bind;
  27. Function.prototype.bind = function (self2, ...args) {
  28. if (typeof self2 === "object" && self2 !== null && Object.prototype.hasOwnProperty.call(self2, "editingTarget") && Object.prototype.hasOwnProperty.call(self2, "runtime")) {
  29. Function.prototype.bind = _bind;
  30. callback(self2);
  31. return _bind.call(this, self2, ...args);
  32. }
  33. return _bind.call(this, self2, ...args);
  34. };
  35. }
  36. function withResolvers() {
  37. let resolve, reject;
  38. const promise = new Promise((res, rej) => {
  39. resolve = res;
  40. reject = rej;
  41. });
  42. return { resolve, reject, promise };
  43. }
  44. trap(vm => {
  45. const attachStorage = vm.runtime.attachStorage;
  46. vm.runtime.attachStorage = storage => {
  47. let reqs = [];
  48. const load = storage.load;
  49. storage.load = async (...args) => {
  50. const { resolve, reject, promise } = withResolvers();
  51. reqs.push({ resolve, reject, args });
  52. return promise;
  53. };
  54. requestIdleCallback(function idle() {
  55. const processReqs = reqs.splice(0, MAX_PARALLEL_REQUESTS);
  56. Promise.allSettled(processReqs.map(req => load.call(storage, ...req.args).then(req.resolve, req.reject))).then(() => {
  57. requestIdleCallback(idle);
  58. });
  59. });
  60. return attachStorage.call(vm.runtime, storage);
  61. };
  62. });
  63. })();

QingJ © 2025

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