theoldreader link disabler

Disable links to third-party sites on theoldreader.com

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name    theoldreader link disabler
// @description     Disable links to third-party sites on theoldreader.com
// @version  1
// @match    https://theoldreader.com/*
// @grant    none
// @namespace https://greasyfork.org/users/668680
// ==/UserScript==


// Disable links within content of feed posts
unsafeWindow.blankshield.open = function(e,t,n) {}

// Disable links of titles of feed posts
function disableClicks(event) { event.preventDefault() }

function disableClicksForThirdPartyLinks(anchorElement) {
  let href = anchorElement.href;
  if (!(href.startsWith("https://theoldreader.com") || href.startsWith("/"))) {
    anchorElement.addEventListener("click", disableClicks)
  }
}

let targetNode = document.querySelector("div.content-cell")

for (let element of targetNode.querySelectorAll("a[href]")) {
  disableClicksForThirdPartyLinks(element)
}

function mutationsCallback(mutations) {
  for (let mutation of mutations) {
    for (let node of mutation.addedNodes) {
      if (!(node instanceof HTMLElement)) continue;
      if (node.matches("a[href]")) {
        disableClicksForThirdPartyLinks(node)
      }
      for (let element of node.querySelectorAll("a[href]")) {
        disableClicksForThirdPartyLinks(element)
      }
    }
  }
}

let observer = new MutationObserver(mutationsCallback)

observer.observe(targetNode, {childList:true, subtree:true}) // Mind the letter cases, childList and subtree.