// ==UserScript== // @name Native Promise for YouTube // @namespace http://tampermonkey.net/ // @version 0.1.0 // @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 // @downloadURL none // ==/UserScript== (function () { 'use strict'; 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; const 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... })();