google-chrome-extension - 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>
有什么帮助吗?这是我的第一个脚本,但我自己做不到。
解决方案
根据给出的示例,这里是一个示例
// <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);
推荐阅读
- html - 在 div 中添加大量文本时,下一个元素会向下移动
- windows - 如何为 Windows 安装 Gym Torcs
- laravel - Pusher 没有从服务器接收事件
- javascript - 从回调 url 读取数据
- xamarin.forms - Xamarin Android 中的导航栏高度不正确
- c# - .Net Core 不支持 UserPasswordCredential
- ionic-framework - Ionic 4:当我尝试使用 ionic serve 运行我的项目时出错
- javascript - 如何将两个数组放入新数组中
- r - 重新采样或聚合大型栅格限制内存使用 R
- istio - 如何让 istio 解析自定义主机