这是一个特殊的 GreaseKit 脚本,它成功地更改了页面上的某些 URL。它非常棒,我喜欢这里写它的人。但我想对其进行调整,以便在单击链接时在新窗口中打开
// the new base url
var base = ' https://www.example.co.uk/wine/order?ie=UTF8&asin=';
// all the links with className 'PrmryBtnMed'
var links = document.getElementsByTagName('a');
for(var i = 0;i < links.length;i++){
// check each link for the 'asin' value
var result = /asin=([\d\w]+)/.exec(links[i].getAttribute('href'));
if(result){
// make a new url using the 'base' and the 'asin' value
links[i].setAttribute('href', base+result[1]);
}
}
我对如何解决这个问题的猜测:
有人可以告诉我如何实现这一目标吗?我的猜测是在link.target="_blank"
某个地方添加,但我不确定确切的位置。