您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
禁止B站包含target="_blank"的链接在新标签页中打开
当前为
- // ==UserScript==
- // @name Bilibili Disable target="_blank"
- // @namespace http://tampermonkey.net/
- // @version 0.3
- // @description 禁止B站包含target="_blank"的链接在新标签页中打开
- // @author malagebidi
- // @match *://*.bilibili.com/*
- // @license MIT
- // @grant none
- // @icon https://www.bilibili.com/favicon.ico
- // ==/UserScript==
- (function() {
- 'use strict';
- // 移除所有链接的 target="_blank"
- document.addEventListener('click', function(e) {
- if (e.target.tagName === 'A') {
- e.target.target = '_self';
- }
- }, true);
- // 或者使用 MutationObserver 动态处理
- const observer = new MutationObserver((mutations) => {
- mutations.forEach((mutation) => {
- if (mutation.type === 'childList') {
- document.querySelectorAll('a[target="_blank"]').forEach(link => {
- link.target = '_self';
- });
- }
- });
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- })();