Greasy Fork

Greasy Fork is available in English.

当页开链

全站通用型页内增强脚本,Bing兼容,bili兼容.添加kook按钮排除

当前为 2025-03-31 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name 当页开链
// @version  4.5
// @description  全站通用型页内增强脚本,Bing兼容,bili兼容.添加kook按钮排除
// @author   none
// @match *://*/*
// @grantunsafeWindow
// @run-at   document-body
// @exclude-match *://www.gamer520.com/*
// @namespace
// @namespace 
// ==/UserScript==

(function() {
'use strict';

const shouldExcludeElement = (target) => {
const EXCLUDE_SELECTORS = [
'.nav-content',
'.views',
'.presentation',
'.pay-box',
'[target="_self"]',
'[role="group"]',
'#ks',
'.bpx-player-ending-related-item-cover',
'#qs_searchBox',
'.actions'
];
return EXCLUDE_SELECTORS.some(selector => target.closest(selector));
};


document.addEventListener('click', function(event) {
var target = event.target;
if (shouldExcludeElement(target) || target.closest('form')) {
return true;
}
while (target && target.tagName !== 'A') {
target = target.parentElement;
}
if (target && target.tagName === 'A') {
event.preventDefault();
window.location.href = target.href;
}
});


const initEventHandlers = () => {
document.addEventListener('click', function(event) {
const target = event.composedPath()[0];
if (shouldExcludeElement(target) || target.closest('form')) {
return true;
}
let node = target;
while (node && node.tagName !== 'A') {
node = node.parentElement;
}
if (node && node.tagName === 'A') {
event.preventDefault();
window.location.href = node.href;
}
}, true);
};

// 核心初始化
const main = () => {
if (window.self !== window.top) return;
initEventHandlers();
// 处理window.open
unsafeWindow.open = function(url) {
window.location.href = url;
};
};

// 启动逻辑
document.readyState === 'complete' ? main() :
document.addEventListener('DOMContentLoaded', main);


})();