Native Promise for YouTube

YouTube replaced Promise with polyfill in some old browsers.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Native Promise for YouTube
// @namespace    http://tampermonkey.net/
// @version      0.1.4
// @license      MIT
// @description  YouTube replaced Promise with polyfill in some old browsers.
// @author       CY Fung
// @match        https://*.youtube.com/*
// @match        https://www.youtube-nocookie.com/embed/*
// @run-at       document-start
// @grant        none
// @unwrap
// @allFrames
// @inject-into  page
// @compatible   firefox Firefox >= 52 && Firefox < 69
// @compatible   edge Edge >= 15 && Edge < 79
// ==/UserScript==

(function () {
    'use strict';

    if (typeof PromiseRejectionEvent !== 'function') {

        /*
        
            Minimum Requirement:
                async ()=>{}: Chrome 55, Edge 15, Safari 11, Firefox 52, Opera 42
            
            Target Browsers below the following versions:
                PromiseRejectionEvent: Chrome 49, Edge 79, Safari 11, Firefox 69, Opera 36
            
            This script will only work for 
                Edge >= 15 && Edge < 79
                Firefox >= 52 && Firefox <= 69
        
        */

        try {

            const truePromise = (async () => { })().constructor; // suppress polyfill if the old browser can support async arrow function;

            window.PromiseRejectionEvent = (() => {
                throw 'PromiseRejectionEvent is not supported';
            }); // Waterfox Classic does not have "PromiseRejectionEvent"

            if (truePromise !== Promise) window.Promise = truePromise; // if the script runs after polyfill.

        } catch (e) {
            throw 'Your browser is too old. This script will not work for you';
        }

    }

})();