Wikipedia:在工具提示中显示链接目标
将每个链接的工具提示设为目标文章的可读名称,让你知道它指向何处。
可复制的代码
// Show the decoded target article in each link's tooltip
function annotateLinks() {
const links = document.querySelectorAll('.mw-parser-output a[href^="/wiki/"]');
links.forEach(function (a) {
if (a.dataset.jzTip) { return; }
a.dataset.jzTip = '1';
try {
const name = decodeURIComponent(a.getAttribute('href').slice(6))
.replace(/_/g, ' ');
a.title = '→ ' + name;
} catch (e) { /* skip malformed links */ }
});
}
annotateLinks();
new MutationObserver(annotateLinks).observe(document.body, { childList: true, subtree: true });
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。