s Disable YouTube Channel/User Home Page Video AutoPlay 2.0.16 fork May 2023 bugfix

Disable the video autoplay at YouTube channel/user home page

目前為 2023-05-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name         s Disable YouTube Channel/User Home Page Video AutoPlay 2.0.16 fork May 2023 bugfix
// @namespace    DisableYouTubeChannelUserHomePageVideoAutoPlayFork
// @version      2.0.16.1
// @license      GNU AGPLv3
// @description  Disable the video autoplay at YouTube channel/user home page
// @match        *://*.youtube.com/*
// @grant        none
// @run-at       document-start
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// ==/UserScript==

// original author jcunews https://greasyfork.org/en/users/85671-jcunews
(() => {
  let xo = XMLHttpRequest.prototype.open;
  XMLHttpRequest.prototype.open = function(mtd, url) {
    this.url_dyuhpv = url;
    return xo.apply(this, arguments)
  };
  let xs = XMLHttpRequest.prototype.send, rx = /:\/\/[^\/]+\/(((c(hannel)?|u(ser)?)\/)|@)[^\/]+(\/(about|featured)?)?(\?|$)/, blk;
  XMLHttpRequest.prototype.send = function(dat) {
    if (/player\?key=/.test(this.url_dyuhpv) && dat && dat.toUpperCase) {
      let z, o;
      try {
        if (
          (o = (o = JSON.parse(dat)).context.client) && (rx.test(o.originalUrl) | ((o = o.mainAppWebInfo) && rx.test(o.graftUrl)))
        ) blk = true
      } catch(z) {}
    }
    return xs.apply(this, arguments)
  };
  let mp = HTMLMediaElement.prototype.play;
  HTMLMediaElement.prototype.play = function() {
    if (blk) throw blk = false;
    return mp.apply(this, arguments)
  };
})();