您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
使linux.do网站的帖子链接在新标签页中打开
当前为
// ==UserScript== // @name Linux.do 新标签页打开 // @namespace http://tampermonkey.net/ // @version 0.2 // @description 使linux.do网站的帖子链接在新标签页中打开 // @author You // @match https://linux.do/* // @grant none // @run-at document-start // @license MIT // ==/UserScript== (function() { 'use strict'; // 主函数,用于修改链接 function modifyLinks() { // 选择所有帖子链接 - 更精确的选择器 const postLinks = document.querySelectorAll('a[href^="/t/"], a[href^="/d/"], a.title[href], .topic-list-item a.title, .topic-list a.title, .latest-topic-list-item a.title'); // 遍历所有链接并添加target="_blank"属性 postLinks.forEach(link => { // 检查链接是否包含帖子URL模式 if (link.href && (link.href.includes('/t/') || link.href.includes('/d/'))) { if (!link.hasAttribute('target') || link.getAttribute('target') !== '_blank') { link.setAttribute('target', '_blank'); // 添加rel="noopener"以提高安全性 if (!link.hasAttribute('rel') || !link.getAttribute('rel').includes('noopener')) { const currentRel = link.getAttribute('rel') || ''; link.setAttribute('rel', currentRel ? currentRel + ' noopener' : 'noopener'); } // 防止点击事件被其他处理程序拦截 link.addEventListener('click', function(e) { // 阻止默认行为和事件冒泡 e.stopPropagation(); }, true); } } }); } // 页面加载完成后执行 window.addEventListener('load', function() { modifyLinks(); // 创建一个MutationObserver来监视DOM变化,处理动态加载的内容 const observer = new MutationObserver(function(mutations) { modifyLinks(); }); // 开始观察document.body的所有子树变化 observer.observe(document.body, { childList: true, subtree: true }); }); // 也在DOMContentLoaded时执行一次 document.addEventListener('DOMContentLoaded', modifyLinks); // 定期执行以确保所有链接都被处理 setInterval(modifyLinks, 2000); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址