How to disable Google search result link redirect (on right-click) in Chrome?
Now when I know what you wanted, I wrote a little script which deletes onmousedown
attribute from link.
Here it is:
// ==UserScript==
// @name Delete onmousedown
// @namespace google
// @include http://www.google.*/*
// ==/UserScript==
var runOnce = function(){
var items = document.querySelectorAll('li.g h3.r a');
for(var i = 0, len = items.length; i< len; i++){
items[i].removeAttribute('onmousedown');
}
}
document.body.appendChild(document.createElement("script")).innerHTML = "("+runOnce+")()";
Save it as some file which ends with .user.js and drop it on Google Chrome and let me know if it helped.
PS. English is not my spoken language so sorry for misunderstanding you.
Edit: I added extra logic so it should work with Google Instant. Tell me if it works for you.
Edit: I rolled back to version "without" Google Instant support.
Try to use "Undirect" Chrome extension.
It removes this tracking and redirection from google search results. Supports using google over both HTTP and HTTPS.
If you are using Firefox, you are lucky as the following answer applies to you. If you are using Chrome, you are much less lucky, see the bottom of this answer.
Greasemonkey fires the user scripts once the DOM is loaded, thus you don't need to implement a "DOM ready" listener.
Also you are on Firefox, so you can use some modern candy: for...of
, let
.
Here is the resulting Greasemonkey script:
// ==UserScript==
// @name Remove Google redirects
// @namespace google
// @description Remove redirects from Google Search result links.
// @include https://www.google.*/*
// @version 1
// @grant none
// ==/UserScript==
for (let element of document.querySelectorAll('#res .r > a')) {
element.removeAttribute('onmousedown');
}
Thanks to the let
there are no local declarations, therefore you don't need to enclose the above code in an IIFE.
For the unfortunate Chrome (Tampermonkey) users:
Links are not found at the time the script is executed, even though document.readyState === 'complete'
… as a result you have to implement some loop with timer.
Therefore, you end up with:
// ==UserScript==
// @name Remove Google redirects
// @namespace google
// @description Remove redirects from Google Search result links.
// @include https://www.google.*/*
// @version 1
// @grant none
// ==/UserScript==
(function removeGoogleRedirects() {
var links = document.querySelectorAll('#res .r > a');
if (links.length === 0) {
setTimeout(removeGoogleRedirects, 100);
return;
}
for (var link of links) {
link.removeAttribute('onmousedown');
}
})();
Update October 2018:
Because of a markup change in the Google page, the h3.r
needed to be changed to div.r
.
I went farther and replaced h3.r > a
with #res .r > a
(replaced "tag.class" with just ".class", and added a parent as a security so that the selector is not too generic).