最近发现在浏览社区时,点击帖子链接都是在当前页面打开的,对于想同时浏览多个帖子的朋友来说不太方便。于是写了一个简单的 浏览器 脚本来解决这个问题。
功能介绍
- 让所有帖子链接(/t/topic/)在新标签页中打开
- 支持动态加载的内容
- 不影响网站其他功能
使用方法
- 安装 Stay 浏览器插件(Safari)(原则上油猴 Tampermonkey 安装脚本也是可以的)
- 打开 Stay 脚本管理器
- 创建新脚本
- 复制以下代码并粘贴
- 保存并启用
// ==UserScript==
// @name Linux.do 新标签页打开帖子
// @namespace https://linux.do/
// @version 1.1
// @description 让 linux.do 网站的帖子链接在新标签页中打开
// @author Your Name
// @match https://linux.do/*
// @grant none
// ==/UserScript==(function() {
‘use strict’;// 使用事件委托处理所有点击事件 document.addEventListener('click', function(e) { // 查找被点击的链接元素 let target = e.target; while (target && target.tagName !== 'A') { target = target.parentElement; } // 如果找到了链接元素 if (target && target.tagName === 'A') { // 检查是否是帖子链接 const href = target.getAttribute('href'); if (href && href.startsWith('/t/topic/')) { // 阻止默认行为 e.preventDefault(); e.stopPropagation(); // 获取完整URL const fullUrl = new URL(href, window.location.origin).href; // 在新标签页中打开 window.open(fullUrl, '_blank'); } } }, true);})();
工作原理
- 使用事件委托监听所有点击事件
- 判断点击的是否为帖子链接
- 如果是帖子链接,则阻止默认行为并在新标签页打开
最新版本更新至GitHub
一个智能的浏览器用户脚本(UserScript),可以自动判断并在新标签页中打开网页链接。无需配置,即装即用,支持所有主流浏览器。

