Greasy Fork is available in English.

新标签页打开链接

将网页中所有链接改为新标签页打开~

< Rückmeldungen auf新标签页打开链接

Rezension: Gut - Skript funktioniert

§
Veröffentlicht: 21.01.2022

大佬 可以写个强制在当前标签页刷新新连接吗?PWA要用到

X.I.UVerfasser
§
Veröffentlicht: 21.01.2022

你新建一个脚本,粘贴下面内容并保存即可。

// ==UserScript==
// @name         当前标签页打开链接
// @version      1.0.0
// @author       X.I.U
// @description  将网页中所有链接改为当前标签页打开~
// @match        *://*/*
// @grant        none
// @run-at       document-body
// @namespace    https://github.com/XIU2/UserScript
// ==/UserScript==
(function() {
    document.head.appendChild(document.createElement('base')).target = '_self';
})();

如果只想要部分网站使用,则可以修改 @match 标签为(可以同时写好几个):

// @match        *://a.com/*
// @match        *://b.com/*
§
Veröffentlicht: 22.01.2022

好的,谢谢大佬

§
Veröffentlicht: 23.01.2022

大佬 貌似不行啊 微博还是跳转到新窗口

§
Veröffentlicht: 23.01.2022

// ==UserScript==
// @name no-blank
// @version 1
// @grant none
// @match *://*.qq.com/*
// @match *://*.bilibili.com/*
// @match *://*.huya.com/*
// @match *://*.douyu.com/*
// @match *://*.weibo.com/*
// @run-at document-end
// ==/UserScript==
(function (window) {
"use strict";

// 注册 mouseover 事件
document.addEventListener('mouseover', function (event) {
var a = event.target, depth = 3;

// 当前 html 标签可能不是 a,需要递归查询其父标签。
// 一般递归个几次就差不多了
while (a && a.tagName != 'A' && depth-- > 0)
a = a.parentNode;
// 只处理 a 标签
if (a && a.tagName == 'A') {
a.removeAttribute('target'); // 移除 target 属性
a.setAttribute('target','_self') //添加 target 属性 _self
var u = new URL(a.href);
var p = u.searchParams
var t = p.get("target")||p.get("to");
if (t) a.href = t;
}
}, true);
})(window);

(微博。话题榜点开内容会新建标签)
大佬 帮我看看 啥问题

Antwort schreiben

Anmelden um eine Antwort zu senden.