Native Promise for YouTube

YouTube replaced Promise with polyfill in some old browsers.

  1. // ==UserScript==
  2. // @name Native Promise for YouTube
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.4
  5. // @license MIT
  6. // @description YouTube replaced Promise with polyfill in some old browsers.
  7. // @author CY Fung
  8. // @match https://*.youtube.com/*
  9. // @match https://www.youtube-nocookie.com/embed/*
  10. // @run-at document-start
  11. // @grant none
  12. // @unwrap
  13. // @allFrames
  14. // @inject-into page
  15. // @compatible firefox Firefox >= 52 && Firefox < 69
  16. // @compatible edge Edge >= 15 && Edge < 79
  17. // ==/UserScript==
  18.  
  19. (function () {
  20. 'use strict';
  21.  
  22. if (typeof PromiseRejectionEvent !== 'function') {
  23.  
  24. /*
  25. Minimum Requirement:
  26. async ()=>{}: Chrome 55, Edge 15, Safari 11, Firefox 52, Opera 42
  27. Target Browsers below the following versions:
  28. PromiseRejectionEvent: Chrome 49, Edge 79, Safari 11, Firefox 69, Opera 36
  29. This script will only work for
  30. Edge >= 15 && Edge < 79
  31. Firefox >= 52 && Firefox <= 69
  32. */
  33.  
  34. try {
  35.  
  36. const truePromise = (async () => { })().constructor; // suppress polyfill if the old browser can support async arrow function;
  37.  
  38. window.PromiseRejectionEvent = (() => {
  39. throw 'PromiseRejectionEvent is not supported';
  40. }); // Waterfox Classic does not have "PromiseRejectionEvent"
  41.  
  42. if (truePromise !== Promise) window.Promise = truePromise; // if the script runs after polyfill.
  43.  
  44. } catch (e) {
  45. throw 'Your browser is too old. This script will not work for you';
  46. }
  47.  
  48. }
  49.  
  50. })();

QingJ © 2025

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