您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Enforce `target="_self"` on links within Reddit posts and messages on desktop, delevoped for next chapter links on r/HFY.
当前为
// ==UserScript== // @name Reddit Links Open in Same Tab // @namespace ultrabenosaurus.Reddit // @version 1.5 // @description Enforce `target="_self"` on links within Reddit posts and messages on desktop, delevoped for next chapter links on r/HFY. // @author Ultrabenosaurus // @license GNU AGPLv3 // @source https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name // @match https://www.reddit.com/r/* // @match https://www.reddit.com/message/* // @match https://old.reddit.com/r/* // @match https://old.reddit.com/message/* // @icon https://www.google.com/s2/favicons?sz=64&domain=reddit.com // @grant none // ==/UserScript== (function() { 'use strict'; setTimeout(function(){ RemoveTargetFromLinks(); }, 1000); })(); function RemoveTargetFromLinks(){ //console.log("RemoveTargetFromLinks", location.origin); var links=null; if("https://www.reddit.com"==location.origin){ links=document.querySelectorAll('div[data-test-id="post-content"] div.RichTextJSON-root p > a[target="_blank"], div.content div.md-container a[href*="www.reddit.com"]'); for (var lin in links) { if (links.hasOwnProperty(lin)) { links[lin].removeAttribute('target'); links[lin].setAttribute('target', '_self'); } } } else if("https://old.reddit.com"==location.origin){ links=document.querySelectorAll('div.content div.usertext-body a, div.content div.md-container a[href*="www.reddit.com"]'); for (var lin in links) { if (links.hasOwnProperty(lin)) { var linClone=links[lin].cloneNode(true); linClone.removeAttribute('target'); linClone.setAttribute('target', '_self'); if(-1<linClone.attributes.href.nodeValue.indexOf("//www.reddit.com")){ linClone.attributes.href.nodeValue = linClone.attributes.href.nodeValue.replace("www.reddit.com", "old.reddit.com"); } if(-1<linClone.attributes.href.nodeValue.indexOf("//reddit.com")){ linClone.attributes.href.nodeValue = linClone.attributes.href.nodeValue.replace("reddit.com", "old.reddit.com"); } if(-1<linClone.attributes.href.nodeValue.indexOf("//redd.it/")){ linClone.attributes.href.nodeValue = linClone.attributes.href.nodeValue.replace("redd.it", "old.reddit.com/comments"); } links[lin].parentNode.insertBefore(linClone, links[lin]); links[lin].remove(); } } } }