Wikipedia:在新标签页打开链接
让指向其他文章的链接在新标签页中打开,使你不会丢失当前页面。
可复制的代码
// Open internal article links in a new background tab
function tabifyLinks() {
const links = document.querySelectorAll('.mw-parser-output a[href^="/wiki/"]');
links.forEach(function (a) {
if (a.dataset.jzTab) { return; }
a.dataset.jzTab = '1';
a.setAttribute('target', '_blank');
a.setAttribute('rel', 'noopener');
});
}
tabifyLinks();
new MutationObserver(tabifyLinks).observe(document.body, { childList: true, subtree: true });
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。