首页 > 解决方案 > Tampermonkey 脚本更改文本

问题描述

我有一个使用 javascript 显示链接的网页。但我想轻松复制链接,所以我需要像这样搜索和替换所有行:

<a href="javascript:;" class="question-link" data-question-id="34144011">Error 1606 while installation</a>

这样:

 <a href="htt ps://www.domain.com/?qid=34144011">Error 1606 while installation</a>

有什么帮助吗?这是我的第一个脚本,但我自己做不到。

标签: google-chrome-extensiontampermonkey

解决方案


根据给出的示例,这里是一个示例

// <a href="javascript:;" class="question-link" data-question-id="34144011">Error 1606 while installation</a>

// assuming there are a number of such links with class="question-link"

document.querySelectorAll('a.question-link').forEach(a => 
  a.href = 'https://www.example.com/?qid=' + a.dataset.questionId);

推荐阅读