Skip to content

Instantly share code, notes, and snippets.

@chbrown
Created October 21, 2012 17:23
Show Gist options
  • Select an option

  • Save chbrown/3927682 to your computer and use it in GitHub Desktop.

Select an option

Save chbrown/3927682 to your computer and use it in GitHub Desktop.
Google Faster

Problem and Motivation

Google uses onmousedown="..." in-line javascript to track outgoing clicks on their search results page. Anchor tags (<a>) handle the onmousedown event before handling the href, so hijacking the user's intent is quite easy. This is usually a good thing, because Google uses clickthroughs to measure success of their search results, and the better Google is at getting me good search results, the happier I am.

But lately, I have been using a slower than usual internet connection when at home, and since apparently nobody at Google tests the usability of anything Google on a slower than 1T connection, they simply don't give a shit that SPDY sometimes breaks down for slow connections like mine. The solution? Pretend like I don't have javascript. This will let me click through with clean hrefs, like with normal links on normal websites. They should be measuring mouseovers anyway, not mousedown's.

Also, this will give you a little more privacy.

Instructions

  1. Install Tampermonkey from the chrome web store.
  2. Bring up the Tampermonkey preferences and create a new extension.
  3. Paste in the javascript code above. You may want to trigger on insecure http://, too. Would not recommend matching mail.google.com, though. setInterval instead of setTimeout is a bit of overkill, but since there's no such thing as document.onchange, and Google instant is pretty great, setInterval is the only thing that gets the job done.
  4. Save.
  5. Reload your Google search. Command+Alt+i then click the magnifying glass, and then one of the search links, to show the DOM and ensure there is no onmousedown attribute. Not there? Great!
// ==UserScript==
// @name Google Direct Links
// @namespace http://blog.teusink.net/
// @description Script that changes annoying new-style Google links to direct links
// @include https://google.com/*
// @include https://www.google.com/*
// ==/UserScript==
function removeMouseDowns() {
//console.log('removing mousedowns from google results');
var allElements = document.evaluate('//*[@onmousedown]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
for (var i = 0; i < allElements.snapshotLength; i++) {
var thisElement = allElements.snapshotItem(i);
if(thisElement.nodeName.toUpperCase() == 'A') {
thisElement.removeAttribute('onmousedown');
}
}
}
setInterval(removeMouseDowns, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment