YouTube replaced Promise with polyfill in some old browser.
目前為
// ==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...
})();