Reddit Links Open in Same Tab

Remove `target="_blank"` from links within Reddit posts on desktop, focused on next chapter links on r/HFY.

目前為 2023-04-30 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Reddit Links Open in Same Tab
// @namespace    ultrabenosaurus.Reddit
// @version      1.1
// @description  Remove `target="_blank"` from links within Reddit posts on desktop, focused on 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/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    setTimeout(function(){
        RemoveTargetFromLinks();
    }, 1000);
})();

function RemoveTargetFromLinks(){
    var links=document.querySelectorAll('div[data-test-id="post-content"] div.RichTextJSON-root p > a[target="_blank"]');
    for (var lin in links) {
        if (links.hasOwnProperty(lin)) {
            links[lin].removeAttribute('target');
        }
    }
}