Fix New-Window Links (Remove target Attribute)

Remove the target attribute from the links matching the given string.

当前为 2020-06-04 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Fix New-Window Links (Remove target Attribute)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Remove the target attribute from the links matching the given string.
// @author       Gavin Borg
// @match        
// @grant        none
// ==/UserScript==

var linkQueryStrings = [""];

(function() {
    'use strict';

    fixLinks();
})();

function fixLinks() {
    for(var i = 0; i < linkQueryStrings.length; i++) {
        fixLinksWithQuery(linkQueryStrings[i]);
    }
}

function fixLinksWithQuery(queryString) {
    if (document.querySelector(queryString)) { // Make sure the links we want to fix exist, in case they show up via AJAX a little later than page load.
        document.querySelectorAll(queryString).forEach(link => link.removeAttribute("target"));
    } else {
        setTimeout(fixLinksWithQuery.bind(null, queryString), 0);
    }
}