页面中的所有链接

页面中的所有链接

本文介绍了如何更改页面中的所有链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于像这样的IP-direct,Google搜索这样的网页:

  http://62.0.54.118/search?& q = 42& oq = 42& sourceid = chrome& ie = UTF-8& filter = 0 



如何将该页面中的所有链接从搜索?q 更改为搜索?& q =

例如,我想建立链接:

  http://62.0.54.118/search?q=42&ei=Xf5bUqHLOKeQ0AWV4YG4Cg&start=10&sa=N&filter=0 

转换为:

  http://62.0.54.118/search?& q = 42& ei = Xf5bUqHLOKeQ0AWV4YG4Cg& start = 10& sa = N& filter = 0 

>
如何让Chrome通过自动脚本或类似的方式改变链接?

改变这些链接,在一个静态页面上(例如你的例子):
$ b $ ol
  • 搜索适用的链接

  • 循环通过链接和改变它们。 (通常使用正则表达式。)

    完整的userscript 想要这样:

      // == UserScript == 
    // @name _Modify select Google搜索链接
    // @include http:// YOUR_SERVER.COM/YOUR_PATH/*
    // @include http://62.0.54.118/*
    // == / UserScript ==

    var qLinks = document.querySelectorAll ( 一个[HREF * = 'q =']); $ var $ H $ = $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
    var newHref = oldHref.replace(/ \?q = /,?& q =);

    //console.log(oldHref +\\\
    + newHref);
    qLinks [J] .setAttribute('href',newHref);
    }





    将文件另存为 GoogleLinkModify.user.js ,然后。 (或安装并通过Tampermonkey安装脚本)。






    重要提示:




    1. 对于AJAX驱动页面,安装Tampermonkey和。

    2. Google页面是PITA脚本。请注意,即使您更改了 href ,许多Google页面都会忽略该页面,并且在点击链接时也会偷偷地重定向链接。查看或打开其他问题以获取更多信息。


    For pages like this IP-direct, Google search:

    http://62.0.54.118/search?&q=42&oq=42&sourceid=chrome&ie=UTF-8&filter=0
    


    How can I change all the links in that page from search?q to search?&q=?

    For example, I want to make the link:

    http://62.0.54.118/search?q=42&ei=Xf5bUqHLOKeQ0AWV4YG4Cg&start=10&sa=N&filter=0
    

    into:

    http://62.0.54.118/search?&q=42&ei=Xf5bUqHLOKeQ0AWV4YG4Cg&start=10&sa=N&filter=0
    


    How can I make Chrome change the links by automatic script or something like that?

    解决方案

    To change those links, on a static page (like your example):

    1. Search for applicable links.
    2. Loop through the links and change them. (Typically using regex.)

    A complete userscript would like like this:

    // ==UserScript==
    // @name     _Modify select Google search links
    // @include  http://YOUR_SERVER.COM/YOUR_PATH/*
    // @include  http://62.0.54.118/*
    // ==/UserScript==
    
    var qLinks  = document.querySelectorAll ("a[href*='?q=']");
    
    for (var J = qLinks.length - 1;  J >= 0;  --J) {
        var oldHref = qLinks[J].getAttribute ('href');
        var newHref = oldHref.replace (/\?q=/, "?&q=");
    
        //console.log (oldHref + "\n" + newHref);
        qLinks[J].setAttribute ('href', newHref);
    }
    


    Save the file as GoogleLinkModify.user.js and then drag it to the extensions page to install. (Or install the Tampermonkey extension and install the script via Tampermonkey).


    Important:

    1. For AJAX-driven pages, install Tampermonkey and use waitForKeyElements().
    2. Google pages are a PITA to script. Beware that even though you change the href, many Google pages will ignore that and also sneakily redirect links just as you click on them. See or open other questions for more on that.

    这篇关于如何更改页面中的所有链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 09-05 09:22