【问题标题】:How to copy link to highlight using chrome API如何使用 chrome API 复制链接以突出显示
【发布时间】:2022-07-08 01:15:48
【问题描述】:

在Chrome浏览器中,我们可以选择一个文本,然后右键菜单(右键)有一个选项Copy link to highlight

在 chrome 扩展中使用 chrome API 复制链接或应用/删除选择范围上的特定突出显示是可能的以及如何。

const selection = window.getSelection();
const range = selection.getRangeAt(0);
// chrome.highlight.add(range);
// chrome.highight.remove();

【问题讨论】:

    标签: javascript google-chrome-extension


    【解决方案1】:

    我认为您无法使用 Chrome API 做到这一点。 但您可以自己编写链接。

    当您查看链接到突出显示 URL 的结构时。

    https://stackoverflow.com/questions/71806679/how-to-copy-link-to-highlight-using-chrome-api#:~:text=How%20to%20copy%20link%20to%20highlight

    它由三部分组成:

    1. 原始网址
    2. #:~:text= 参数
    3. 和实际的 URL 编码文本选择
    const selection = window.getSelection();
    const range = selection.getRangeAt(0);
    const linkToHighlight = location.href + "#:~:text=" + encodeURIComponent(range.toString())
    

    【讨论】:

      猜你喜欢
      • 2018-07-25
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      相关资源
      最近更新 更多