Native Promise for YouTube

YouTube replaced Promise with polyfill in some old browser.

目前为 2023-06-22 提交的版本。查看 最新版本

// ==UserScript==
// @name         Native Promise for YouTube
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @license      MIT
// @description  YouTube replaced Promise with polyfill in some old browser.
// @author       CY Fung
// @match        https://www.youtube.com/*
// @match        https://www.youtube-nocookie.com/embed/*
// @match        https://music.youtube.com/*
// @run-at       document-start
// @grant        none
// @unwrap
// @allFrames
// @inject-into page
// ==/UserScript==

(function () {
    'use strict';

    try {
        const truePromise = (async () => { })().constructor;

        window.PromiseRejectionEvent = window.PromiseRejectionEvent || (() => {
            throw 'PromiseRejectionEvent is not supported';
        });


        if (truePromise !== Promise) window.Promise = truePromise;
    } catch (e) { }

    /*
        const truePromise = (async () => { })().constructor;
        if (!truePromise) return;
        let cid = setInterval(() => {
            if (window.Promise !== truePromise) {
                window.Promise = truePromise;
                handler();
            }
        }, 1);
    
        const isMobile = location.hostname === 'm.youtube.com';
    
        const ets = isMobile ? ['initialdata', 'state-change', 'state-navigateend'] : ['yt-page-data-fetched', 'yt-navigate-finish', 'spfdone'];
        const mt = isMobile ? window : document;
        let handler = function () {
            if (!handler) return;
            handler = null;
            window.Promise = truePromise;
            clearInterval(cid);
            for (const et of ets) {
                mt.removeEventListener(et, handler, false);
            }
        }
    
        for (const et of ets) {
            mt.addEventListener(et, handler, false);
        }
    
    
        function onReady() {
            const f = handler;
            if (!f) return;
            handler = null;
            f();
        }
    
    
    
        if (document.readyState != 'loading') {
            onReady();
        } else {
            window.addEventListener("DOMContentLoaded", onReady, false);
        }
    
    */

    // Your code here...
})();

QingJ © 2025

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