用于自动将一种类型的URL更改为另一种类型

Plugin for changing urls of one type to another automatically

本文关键字:类型 URL 另一种 一种 用于      更新时间:2023-09-26

我有一组表单的内部大学链接http://www.foo.in/x/*并且只有手动更改为http://www.foo.in/x/y/*

有没有插件可以帮助我在点击第一种类型的链接时自动将其更改为第二种类型?如果没有,有没有办法写这样一个插件?

我在linux上使用firefox/chrome。

我以前从未写过任何插件,听说过java脚本,但从未写过。

我将感谢在这个方向上的任何联系。感谢

试试这个。。。简单的jQuery代码可以替换文档上的所有链接,但只能替换特定的类。

HTML

<a href="http://www.foo.in/x/foo.html" class="link">Link one</a>
<a href="http://www.foo.in/x/bar.html" class="link">Link two</a>
<a href="http://www.foo.in/x/bar.html">Link tree (not affected)</a>​

jQuery

$(document).ready(function() {
    $('.link').each(function() {
        var newLink = $(this).attr('href');
        newLink = newLink.replace("/x", "/x/y");
        $(this).attr('href',newLink);
    });
});

实际示例


编辑以匹配新信息:

在浏览器中创建一个新的书签(crtl+chrome中的D)并编辑书签url。将url替换为以下代码:

javascript:function getLinks(){var arr=new Array();arr=document.getElementsByTagName("a");for(var i=0;i<arr.length;i++){var link=document.getElementsByTagName("a").item(i).href;newLink=link.replace("/x","/x/y");document.getElementsByTagName('a').item(i).href=newLink;}};getLinks();

不要错过最初的"javascrip:"

现在,当您在要替换链接的页面中时,只需单击书签,链接就会被替换。