Skip to content

Instantly share code, notes, and snippets.

@astanin
Created September 25, 2012 14:52

Revisions

  1. astanin revised this gist Oct 2, 2012. 1 changed file with 43 additions and 16 deletions.
    59 changes: 43 additions & 16 deletions Direct_Links_in_Google_Search.user.js
    Original file line number Diff line number Diff line change
    @@ -12,10 +12,16 @@
    // @include http://www.google.tld/webhp*
    // @include https://www.google.tld/
    // @include http://www.google.tld/
    // @version 2.1
    // @include https://encrypted.google.com/*
    // @version 2.2
    // @grant none
    // ==/UserScript==

    // Version 2.2
    // - rewrite using DOMNodeInserted and getElements* to support Chromium too
    // - enable on encrypted.google.com
    // - try to fix new-style classless links in search results (/url?q=...)
    //
    // Version 2.1
    // - enable on plain Google search page, now it works with Instant too
    //
    @@ -32,26 +38,47 @@
    //
    // Version 1.0 (Less Google by @clump)

    document.addEventListener('DOMSubtreeModified',doPage,false);

    function doPage() {
    var ts = document.evaluate('//a[@class="l"]',
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null);
    for (var i=0;i<ts.snapshotLength;i++) {
    var t = ts.snapshotItem(i);
    var href = t.getAttribute('href');
    if (href) {
    function fixLinksOfClassL() {
    // fix old-style class="l" links
    var ts = document.getElementsByClassName("l");
    for (var i=0; i < ts.length; i++) {
    var t = ts[i];
    if (t.tagName == "A") {
    // remove javascript callback first
    t.removeAttribute("onmousedown");
    // fix link if necessary
    var href = t.getAttribute("href");
    var m = href.match(/&url=([^&]*)/);
    if (m) {
    t.setAttribute('href',decodeURIComponent(m[1]));
    t.removeAttribute('onmousedown');
    break;
    }
    }
    }
    return ts.length;
    }

    function fixClasslessLinks() {
    // fix new classless links (noticed in some search results)
    var results = document.getElementById("search");
    var ts = results.getElementsByTagName("A");
    for (var i=0; i < ts.length; i++) {
    t = ts[i];
    t.removeAttribute("onmousedown");
    var href = t.getAttribute("href");
    var m = href.match(/\/url?.*q=([^&]*)/)
    if (m) {
    t.setAttribute('href',decodeURIComponent(m[1]));
    }
    }
    return ts.length;
    }

    function cleanPage() {
    var n = fixLinksOfClassL();
    if (n == 0) {
    fixClasslessLinks();
    }
    }

    doPage();
    document.addEventListener('DOMNodeInserted',cleanPage,false);
    cleanPage();
  2. astanin revised this gist Sep 25, 2012. 1 changed file with 21 additions and 14 deletions.
    35 changes: 21 additions & 14 deletions Direct_Links_in_Google_Search.user.js
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,36 @@
    // ==UserScript==
    // @name Direct Links in Google Search
    // @namespace https://github.com/astanin
    // @description Remove indirections from Google search results on all TLDs.
    // @include https://www.google.tld/*output=search*
    // @include http://www.google.tld/*output=search*
    // @include https://www.google.tld/search*
    // @include http://www.google.tld/search*
    // @include https://www.google.tld/#*
    // @include http://www.google.tld/#*
    // @version 2.0
    // @grant none
    // @name Direct Links in Google Search
    // @namespace https://github.com/astanin
    // @description Remove indirections from Google search results on all TLDs.
    // @include https://www.google.tld/*output=search*
    // @include http://www.google.tld/*output=search*
    // @include https://www.google.tld/search*
    // @include http://www.google.tld/search*
    // @include https://www.google.tld/#*
    // @include http://www.google.tld/#*
    // @include https://www.google.tld/webhp*
    // @include http://www.google.tld/webhp*
    // @include https://www.google.tld/
    // @include http://www.google.tld/
    // @version 2.1
    // @grant none
    // ==/UserScript==

    //Version 2.0 (Direct Links in Google Search)
    // Version 2.1
    // - enable on plain Google search page, now it works with Instant too
    //
    // Version 2.0 (Direct Links in Google Search)
    // - fork "Less Google", which is not working any more, and rename
    // - enable on all Google top-level domains (only .com and .ca in Less Google)
    // - enable on new HTTPS search pages (HTTP still supported, just in case)
    // - remove deprecated @exclude patterns (search URLs have been changed)
    // - don't allow any "onmousedown" link modifications
    //
    //Version 1.1 (Less Google by @clump)
    // Version 1.1 (Less Google by @clump)
    // - change include to only apply to search results
    // (maps and images are too slow)
    //
    //Version 1.0 (Less Google by @clump)
    // Version 1.0 (Less Google by @clump)

    document.addEventListener('DOMSubtreeModified',doPage,false);

  3. astanin revised this gist Sep 25, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Direct_Links_in_Google_Search.user.js
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,7 @@
    // @include https://www.google.tld/#*
    // @include http://www.google.tld/#*
    // @version 2.0
    // @grant none
    // ==/UserScript==

    //Version 2.0 (Direct Links in Google Search)
  4. astanin revised this gist Sep 25, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Direct_Links_in_Google_Search.user.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@
    // ==/UserScript==

    //Version 2.0 (Direct Links in Google Search)
    // - fork "Less Google", which is not working anymore, and rename
    // - fork "Less Google", which is not working any more, and rename
    // - enable on all Google top-level domains (only .com and .ca in Less Google)
    // - enable on new HTTPS search pages (HTTP still supported, just in case)
    // - remove deprecated @exclude patterns (search URLs have been changed)
  5. astanin created this gist Sep 25, 2012.
    49 changes: 49 additions & 0 deletions Direct_Links_in_Google_Search.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    // ==UserScript==
    // @name Direct Links in Google Search
    // @namespace https://github.com/astanin
    // @description Remove indirections from Google search results on all TLDs.
    // @include https://www.google.tld/*output=search*
    // @include http://www.google.tld/*output=search*
    // @include https://www.google.tld/search*
    // @include http://www.google.tld/search*
    // @include https://www.google.tld/#*
    // @include http://www.google.tld/#*
    // @version 2.0
    // ==/UserScript==

    //Version 2.0 (Direct Links in Google Search)
    // - fork "Less Google", which is not working anymore, and rename
    // - enable on all Google top-level domains (only .com and .ca in Less Google)
    // - enable on new HTTPS search pages (HTTP still supported, just in case)
    // - remove deprecated @exclude patterns (search URLs have been changed)
    // - don't allow any "onmousedown" link modifications
    //
    //Version 1.1 (Less Google by @clump)
    // - change include to only apply to search results
    // (maps and images are too slow)
    //
    //Version 1.0 (Less Google by @clump)

    document.addEventListener('DOMSubtreeModified',doPage,false);

    function doPage() {
    var ts = document.evaluate('//a[@class="l"]',
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null);
    for (var i=0;i<ts.snapshotLength;i++) {
    var t = ts.snapshotItem(i);
    var href = t.getAttribute('href');
    if (href) {
    var m = href.match(/&url=([^&]*)/);
    if (m) {
    t.setAttribute('href',decodeURIComponent(m[1]));
    t.removeAttribute('onmousedown');
    break;
    }
    }
    }
    }

    doPage();