Greasy Fork 还支持 简体中文。

yt blocker

none

Version vom 17.03.2025. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         yt blocker
// @version      2
// @description  none
// @run-at       document-start
// @author       rssaromeo
// @license      GPLv3
// @match        *://youtube.com/*
// @match        *://*.youtube.com/*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAMAAABiM0N1AAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAHJQTFRFAAAAEIijAo2yAI60BYyuF4WaFIifAY6zBI2wB4usGIaZEYigIoiZCIyrE4igG4iYD4mjEomhFoedCoqpDIqnDomlBYyvE4efEYmiDYqlA42xBoytD4mkCYqqGYSUFYidC4qoC4upAo6yCoupDYqmCYur4zowOQAAACZ0Uk5TAO////9vr////1+/D/+/L+/Pf/////+f3///////H4////////+5G91rAAACgUlEQVR4nM2Y22KjIBCGidg1264liZqDadK03X3/V2wNKHMC7MpF/xthHD5mgERAqZhWhfYqH6K+Qf2qNNf625hCoFj9/gblMUi5q5jLkXLCKudgyiRm0FMK82cWJp1fLbV5VmvJbCIc0GCYaFqqlDJgADdBjncqAXYobm1xh72aFMflbysteFfdy2Yi1XGOm5HGBzQ1dq7TzEoxjeNTjQZb7VA3e1c7+ImgasAgQ9+xusNVNZIo5xmOMgihIS2PbCQIiHEUdTvhxCcS/kPomfFI2zHy2PkWmA6aNatIJpKFJyekyy02xh5Y3DI9T4aOT6VhIUrsNTFp1pf79Z4SIIVDegl6IJO6cHiL/GimIZDhgTu/BlYWCQzHMl0zBWT/T3KAhtxOuUB9FtBrpsz0RV4xsjHmW+UCaffcSy/5viMGer0/6HdFNMZBq/vjJL38H9Dqx4Fuy0Em12DbZy+9pGtiDijbglwAehyj11n0tRD3WUBm+lwulE/8h4BuA+iWAQQnteg2Xm63WQLTpnMnpjdge0Mgu/GRPsV4xdjQ94Lfi624fabhDkfUqIKNrM64Q837v8yL0prasepCgrtvw1sJpoqanGEX7b5mQboNW8eawXaWXTMfMGxub472hzWzHSn6Sg2G9+6TAyRruE71s+zAzjWaknoyJCQzwxrghH2k5FDT4eqWunuNxyN9QCGcxVod5oADbYnIUkDTGZEf1xDJnSFteQ3KdsT8zYDMQXcHxsevcLH1TrsABzkNPyA/L7b0jg704viMMlpQI96WsHknCt/3YH0kOEo9zcGkwrFK39ck72rmoehmKqo2RKlilzSy/nJKEV45CT38myJp456fezktHjN5aeMAAAAASUVORK5CYII=
// @grant        unsafeWindow
// @require https://update.greasyfork.org/scripts/491829/1356221/tampermonkey%20storage%20proxy.js
// @grant GM_getValue
// @grant GM_setValue
// @namespace https://greasyfork.org/users/1184528
// ==/UserScript==

;(async () => {
  const a = loadlib("allfuncs")
  const sp = new storageproxy("globaloptions")
  var ls = sp.get()
  var rate = 2
  var vidlock = true
  ls.blockedUsers ??= []
  ls.blockedTitles ??= []
  ls.blockedTitlesReg ??= []
  ls.blockedCreatorsReg ??= []
  await a.waitforelem(
    "#channel-name>#container>#text-container>yt-formatted-string>a"
  )
  var globalname
  function newBlockBtn(title, creator) {
    var elem = a.newelem("button", {
      innerHTML: ls.blockedUsers.includes(this.title)
        ? "unblock"
        : "block",
      creator,
      title,
      id: "blockbtn",
      onclick(e) {
        e.stopImmediatePropagation()
        e.stopPropagation()
        e.preventDefault()
        log(this.creator)
        if (ls.blockedUsers.includes(this.creator)) {
          ls.blockedUsers.splice(
            ls.blockedUsers.indexOf(this.creator),
            1
          )
        } else {
          ls.blockedUsers.push(this.creator)
        }
        update()
        log(ls.blockedUsers, this.creator)
      },
    })
    ;((elem, creator) => {
      var val = creator
      Object.defineProperty(elem, "creator", {
        get() {
          return val
        },
        set(newval) {
          val = newval.replace(/ • \d+\w? views$/, "")
        },
        enumerable: true,
        configurable: true,
      })
    })(elem, creator)
    return elem
  }

  update()

  function update() {
    unsafeWindow.ls = ls = sp.get()
    if (issearch()) {
      addVid(
        "div#dismissible.style-scope.ytd-video-renderer",
        "#video-title",
        "#text > a",
        "#channel-info"
      )
    } else if (isroot()) {
      globalname = null
      addVid(
        "div#content.style-scope.ytd-rich-item-renderer:has(ytd-rich-grid-media)",
        "#video-title-link",
        "#details>#meta>ytd-video-meta-block>#metadata>#byline-container>ytd-channel-name#channel-name>#container>#text-container>yt-formatted-string#text>a",
        "#details>#meta>ytd-video-meta-block"
      )
    } else if (iswatch()) {
      globalname = a.qs(
        "ytd-channel-name#channel-name>#container>#text-container>yt-formatted-string#text > a"
      )?.textContent
      if (
        !globalname ||
        !a.qs("#upload-info") ||
        !a.qs("#title > h1 > span.cbCustomTitle")
      ) {
        return "loading"
      }
      if (a.qs("#upload-info>#blockbtn")) {
        a.qs("#upload-info>#blockbtn").creator = globalname
      } else {
        a.qs("#upload-info").appendChild(
          newBlockBtn(
            a.qs("#title > h1 > span.cbCustomTitle").textContent,
            globalname
          )
        )
      }
      const btn = a.qs("#upload-info>#blockbtn")
      vidlock = isBlocked(btn.creator, btn.title)
      btn.innerHTML = isBlocked(btn.creator, btn.title)
        ? "unblock"
        : "block"
      try {
        addVid(
          "#dismissible:has(#video-title)",
          "#video-title",
          "#container>#text-container>yt-formatted-string#text",
          "#byline-container"
        )
        addVid(
          "#movie_player > div.html5-endscreen.ytp-player-content.videowall-endscreen.ytp-show-tiles > div > a:has(span.ytp-videowall-still-info)",
          "span.ytp-videowall-still-info > span > span>div>.cbCustomTitle",
          "span.ytp-videowall-still-info > span > span>.ytp-videowall-still-info-author",
          "span.ytp-videowall-still-info > span > span>div"
        )
      } catch (e) {
        error(e)
      }
    }
  }
  function isroot() {
    return /^https?:\/\/(?:www\.)?youtube\.com\/?(?:\?|#|$)/.test(
      location.href
    )
  }
  function iswatch() {
    return /^https?:\/\/(?:www\.)?youtube\.com\/watch\/?(?:\?|#|$)/.test(
      location.href
    )
  }
  function issearch() {
    return /^https?:\/\/(?:www\.)?youtube\.com\/results\?search_query=.*(?:#|$)/.test(
      location.href
    )
  }

  setInterval(() => {
    update()
    if (iswatch()) {
      for (var vid of a.qsa("video")) {
        vid.playbackRate = vidlock ? 0 : rate
      }
    }
  })

  function addVid(
    mainDivID,
    titleID,
    creatorID,
    blockButtonParentID
  ) {
    for (var viddiv of a.qsa(mainDivID)) {
      var btn
      if ((btn = a.qs(blockButtonParentID + ">#blockbtn", viddiv))) {
        ;(btn.title = a.qs(titleID, viddiv).textContent),
          (btn.creator = a.qs(creatorID, viddiv).textContent)
        btn.innerHTML = ls.blockedUsers.includes(btn.creator)
          ? "unblock"
          : "block"
      } else {
        btn = a
          .qs(blockButtonParentID, viddiv)
          .appendChild(
            newBlockBtn(
              a.qs(titleID, viddiv).textContent,
              a.qs(creatorID, viddiv).textContent
            )
          )
      }
      viddiv.style.display = isBlocked(btn.creator, btn.title)
        ? "none"
        : ""
    }
  }
  unsafeWindow.isBlocked = isBlocked
  unsafeWindow.addVid = addVid
  function isBlocked(creator, title) {
    if (
      ls.blockedUsers.includes(creator) ||
      ls.blockedTitles.includes(title)
    )
      return true
    for (let reg of ls.blockedCreatorsReg) {
      if (new RegExp(reg, "i").test(creator)) return true
    }
    for (let reg of ls.blockedTitlesReg) {
      if (new RegExp(reg, "i").test(title)) return true
    }
    return false
  }
})()