复制当前区域锚点链接
该动作复制带有顶部附近区域标题锚点的网址。
可复制的代码
var heads = Array.prototype.slice.call(document.querySelectorAll('h1[id], h2[id], h3[id]'));
var top = window.pageYOffset + 100;
var current = null;
heads.forEach(function (h) {
if (h.getBoundingClientRect().top + window.pageYOffset <= top) { current = h; }
});
if (current) {
var url = location.origin + location.pathname + '#' + current.id;
navigator.clipboard.writeText(url).then(function () {
alert('Copied: ' + url);
});
} else {
alert('No section heading with an id found above.');
}
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 启用操作面板,在「操作」选项卡中添加按钮并粘贴代码 — 一键运行。
为此示例评分
暂无评分 — 成为第一个。