Scratch Question mark fix

Fix question marks on Scratch without reloading.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name              Scratch Question mark fix
// @name:zh-cn        谁家问号暗飞声?
// @name:ja           ハテナマークを何とか消せるやつ
// @namespace         ScratchStorageFix
// @version           1.0
// @description       Fix question marks on Scratch without reloading.
// @description:zh-cn 修复 Scratch 问号问题而无需刷新页面。
// @description:ja    リロード不要でハテナマーク問題をバッチリ解決。
// @author            FurryR
// @license           MIT
// @match             https://scratch.mit.edu/projects/*
// @match             https://aerfaying.com/Projects/*
// @match             https://gitblock.cn/Projects/*
// @grant             none
// @run-at            document-start
// ==/UserScript==

(function() {
    'use strict';

    // Default to 64 for best performance.
    const MAX_PARALLEL_REQUESTS = 64;

    function trap(callback) {
        const _bind = Function.prototype.bind;
        Function.prototype.bind = function (self2, ...args) {
            if (typeof self2 === "object" && self2 !== null && Object.prototype.hasOwnProperty.call(self2, "editingTarget") && Object.prototype.hasOwnProperty.call(self2, "runtime")) {
                Function.prototype.bind = _bind;
                callback(self2);
                return _bind.call(this, self2, ...args);
            }
            return _bind.call(this, self2, ...args);
        };
    }
    function withResolvers() {
        let resolve, reject;
        const promise = new Promise((res, rej) => {
            resolve = res;
            reject = rej;
        });
        return { resolve, reject, promise };
    }
    trap(vm => {
        const attachStorage = vm.runtime.attachStorage;
        vm.runtime.attachStorage = storage => {
            let reqs = [];
            const load = storage.load;
            storage.load = async (...args) => {
                const { resolve, reject, promise } = withResolvers();
                reqs.push({ resolve, reject, args });
                return promise;
            };
            requestIdleCallback(function idle() {
                const processReqs = reqs.splice(0, MAX_PARALLEL_REQUESTS);
                Promise.allSettled(processReqs.map(req => load.call(storage, ...req.args).then(req.resolve, req.reject))).then(() => {
                    requestIdleCallback(idle);
                });
            });
            return attachStorage.call(vm.runtime, storage);
        };
    });
})();