Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Greasemonkey脚本,用于自动修改具有特定id值的URL_Url_Replace_Greasemonkey - Fatal编程技术网

Greasemonkey脚本,用于自动修改具有特定id值的URL

Greasemonkey脚本,用于自动修改具有特定id值的URL,url,replace,greasemonkey,Url,Replace,Greasemonkey,我想将url从更改为“http://example.com/products/description/product123/index.html“到”http://example.com/f123456/products/description/product123/index.html". 对于来自特定站点的每个链接(仅一个),我需要像在示例中那样进行更改,在链接的基础之后添加代码,然后继续正常链接 更具体地说,这里是我想用我的脚本修改的链接:针对每个链接、产品等 我尝试了一些我发现的东西,但

我想将url从更改为“http://example.com/products/description/product123/index.html“到”http://example.com/f123456/products/description/product123/index.html". 对于来自特定站点的每个链接(仅一个),我需要像在示例中那样进行更改,在链接的基础之后添加代码,然后继续正常链接

更具体地说,这里是我想用我的脚本修改的链接:针对每个链接、产品等

我尝试了一些我发现的东西,但它不起作用,我不知道是什么问题

    // ==UserScript==
    // @name     F64.ro
    // @include  http://www.f64.ro/*
    // ==/UserScript==

    var targID      = "f444618/";
    var targLink    = document.querySelector ("#" + targID);
    targLink.href  += targID + "\/";

谢谢大家!

例如,关于stackoverflow也有类似的问题

基于此,这里有一个示例,它将此站点上指向stackoverflow.com的所有链接修改为www.stackoverflow.com

// ==UserScript==
// @name           changeurl test
// @namespace      https://stackoverflow.com/
// @description    test for https://stackoverflow.com/q/10267423/33499
// @include        https://stackoverflow.com/*
// ==/UserScript==

var links,thisLink;
links = document.evaluate("//a[@href]",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
for (var i=0;i<links.snapshotLength;i++) {
    var thisLink = links.snapshotItem(i);

    thisLink.href = thisLink.href.replace('https://stackoverflow.com/',
                                          'http://www.stackoverflow.com/');
}
/==UserScript==
//@name changeurl测试
//@名称空间https://stackoverflow.com/
//@描述测试https://stackoverflow.com/q/10267423/33499
//@包括https://stackoverflow.com/*
//==/UserScript==
var链接,thisLink;
links=document.evaluate(“//a[@href]”,
文件,
无效的
XPathResult.UNORDERED\节点\快照\类型,
无效);

对于(var i=0;i如果它是一个固定数

/==UserScript==
//@name TESTE 2
//@teste2
//@description TESTE 2
//@include http*://*堆栈溢出*
//==/UserScript==
for(var i=0,link;(link=document.links[i]);i++){
linkID=“/F44618”
link.href=link.href.replace(location.hostname,location.hostname+linkID);
}

如果数字在不同的链接之间变化,只需获取当前链接的ID并替换为
linkID='F44618'

您是否意识到这只会影响您的浏览器?其他人不会受到影响。是的,我意识到这一点,但我只想能够复制修改后的URL并将其粘贴到某个人或某个地方,如果可能的话,而是修改手册中的每个链接。谢谢你的回答。这是一条路要走,尽管似乎没有太多的思考进入它的发展。。。