Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save grandsilence/9df871ea46e163ac683253a48fea21ac to your computer and use it in GitHub Desktop.
Save grandsilence/9df871ea46e163ac683253a48fea21ac to your computer and use it in GitHub Desktop.
Don't Track Me Google for Safari Extension: Tamper Monkey
// ==UserScript==
// @name Don't track me Google
// @namespace Rob W, Grand Silence
// @description Removes the annoying link-conversion at Google Search/maps/... The Referrer is also hidden to improve your privacy. Designed for Firefox and Google Chrome.
// @version 3.7
// @match *://*.google.com/*
// @match *://*.google.ad/*
// @match *://*.google.ae/*
// @match *://*.google.com.af/*
// @match *://*.google.com.ag/*
// @match *://*.google.com.ai/*
// @match *://*.google.am/*
// @match *://*.google.co.ao/*
// @match *://*.google.com.ar/*
// @match *://*.google.as/*
// @match *://*.google.at/*
// @match *://*.google.com.au/*
// @match *://*.google.az/*
// @match *://*.google.ba/*
// @match *://*.google.com.bd/*
// @match *://*.google.be/*
// @match *://*.google.bf/*
// @match *://*.google.bg/*
// @match *://*.google.com.bh/*
// @match *://*.google.bi/*
// @match *://*.google.bj/*
// @match *://*.google.com.bn/*
// @match *://*.google.com.bo/*
// @match *://*.google.com.br/*
// @match *://*.google.bs/*
// @match *://*.google.co.bw/*
// @match *://*.google.by/*
// @match *://*.google.com.bz/*
// @match *://*.google.ca/*
// @match *://*.google.cd/*
// @match *://*.google.cf/*
// @match *://*.google.cg/*
// @match *://*.google.ch/*
// @match *://*.google.ci/*
// @match *://*.google.co.ck/*
// @match *://*.google.cl/*
// @match *://*.google.cm/*
// @match *://*.google.cn/*
// @match *://*.google.com.co/*
// @match *://*.google.co.cr/*
// @match *://*.google.com.cu/*
// @match *://*.google.cv/*
// @match *://*.google.com.cy/*
// @match *://*.google.cz/*
// @match *://*.google.de/*
// @match *://*.google.dj/*
// @match *://*.google.dk/*
// @match *://*.google.dm/*
// @match *://*.google.com.do/*
// @match *://*.google.dz/*
// @match *://*.google.com.ec/*
// @match *://*.google.ee/*
// @match *://*.google.com.eg/*
// @match *://*.google.es/*
// @match *://*.google.com.et/*
// @match *://*.google.fi/*
// @match *://*.google.com.fj/*
// @match *://*.google.fm/*
// @match *://*.google.fr/*
// @match *://*.google.ga/*
// @match *://*.google.ge/*
// @match *://*.google.gg/*
// @match *://*.google.com.gh/*
// @match *://*.google.com.gi/*
// @match *://*.google.gl/*
// @match *://*.google.gm/*
// @match *://*.google.gp/*
// @match *://*.google.gr/*
// @match *://*.google.com.gt/*
// @match *://*.google.gy/*
// @match *://*.google.com.hk/*
// @match *://*.google.hn/*
// @match *://*.google.hr/*
// @match *://*.google.ht/*
// @match *://*.google.hu/*
// @match *://*.google.co.id/*
// @match *://*.google.ie/*
// @match *://*.google.co.il/*
// @match *://*.google.im/*
// @match *://*.google.co.in/*
// @match *://*.google.iq/*
// @match *://*.google.is/*
// @match *://*.google.it/*
// @match *://*.google.je/*
// @match *://*.google.com.jm/*
// @match *://*.google.jo/*
// @match *://*.google.co.jp/*
// @match *://*.google.co.ke/*
// @match *://*.google.com.kh/*
// @match *://*.google.ki/*
// @match *://*.google.kg/*
// @match *://*.google.co.kr/*
// @match *://*.google.com.kw/*
// @match *://*.google.kz/*
// @match *://*.google.la/*
// @match *://*.google.com.lb/*
// @match *://*.google.li/*
// @match *://*.google.lk/*
// @match *://*.google.co.ls/*
// @match *://*.google.lt/*
// @match *://*.google.lu/*
// @match *://*.google.lv/*
// @match *://*.google.com.ly/*
// @match *://*.google.co.ma/*
// @match *://*.google.md/*
// @match *://*.google.me/*
// @match *://*.google.mg/*
// @match *://*.google.mk/*
// @match *://*.google.ml/*
// @match *://*.google.mn/*
// @match *://*.google.ms/*
// @match *://*.google.com.mt/*
// @match *://*.google.mu/*
// @match *://*.google.mv/*
// @match *://*.google.mw/*
// @match *://*.google.com.mx/*
// @match *://*.google.com.my/*
// @match *://*.google.co.mz/*
// @match *://*.google.com.na/*
// @match *://*.google.com.nf/*
// @match *://*.google.com.ng/*
// @match *://*.google.com.ni/*
// @match *://*.google.ne/*
// @match *://*.google.nl/*
// @match *://*.google.no/*
// @match *://*.google.com.np/*
// @match *://*.google.nr/*
// @match *://*.google.nu/*
// @match *://*.google.co.nz/*
// @match *://*.google.com.om/*
// @match *://*.google.com.pa/*
// @match *://*.google.com.pe/*
// @match *://*.google.com.ph/*
// @match *://*.google.com.pk/*
// @match *://*.google.pl/*
// @match *://*.google.pn/*
// @match *://*.google.com.pr/*
// @match *://*.google.ps/*
// @match *://*.google.pt/*
// @match *://*.google.com.py/*
// @match *://*.google.com.qa/*
// @match *://*.google.ro/*
// @match *://*.google.ru/*
// @match *://*.google.rw/*
// @match *://*.google.com.sa/*
// @match *://*.google.com.sb/*
// @match *://*.google.sc/*
// @match *://*.google.se/*
// @match *://*.google.com.sg/*
// @match *://*.google.sh/*
// @match *://*.google.si/*
// @match *://*.google.sk/*
// @match *://*.google.com.sl/*
// @match *://*.google.sn/*
// @match *://*.google.so/*
// @match *://*.google.sm/*
// @match *://*.google.st/*
// @match *://*.google.com.sv/*
// @match *://*.google.td/*
// @match *://*.google.tg/*
// @match *://*.google.co.th/*
// @match *://*.google.com.tj/*
// @match *://*.google.tk/*
// @match *://*.google.tl/*
// @match *://*.google.tm/*
// @match *://*.google.tn/*
// @match *://*.google.to/*
// @match *://*.google.com.tr/*
// @match *://*.google.tt/*
// @match *://*.google.com.tw/*
// @match *://*.google.co.tz/*
// @match *://*.google.com.ua/*
// @match *://*.google.co.ug/*
// @match *://*.google.co.uk/*
// @match *://*.google.com.uy/*
// @match *://*.google.co.uz/*
// @match *://*.google.com.vc/*
// @match *://*.google.co.ve/*
// @match *://*.google.vg/*
// @match *://*.google.co.vi/*
// @match *://*.google.com.vn/*
// @match *://*.google.vu/*
// @match *://*.google.ws/*
// @match *://*.google.rs/*
// @match *://*.google.co.za/*
// @match *://*.google.co.zm/*
// @match *://*.google.co.zw/*
// @match *://*.google.cat/*
// @grant GM_getValue
// @homepageURL https://gist.github.com/grandsilence/9df871ea46e163ac683253a48fea21ac
// @updateURL https://gist.github.com/grandsilence/9df871ea46e163ac683253a48fea21ac/raw
// ==/UserScript==
// ### ### ### Configuration ### ### ###
/* Track removal level. See http://userscripts.org/topics/97940#row-418831
**** Recommended value for Firefox: 3 or 1
* Level 0 - Only remove Google's URL redirect. The referrer is NOT Hidden!
* Level 1 - Also hide the referrer on left and middle click
* Level 3 - Adds referrer-hiding for right-click (contextmenu)
* Level 5/7 Also hide referrer for downloadables (hide all referrers)
*/
var HIDE_REFERRER_LEVEL = 0;
/*
* Greasemonkey persistent setting OVERRIDES the HIDE_REFERRER_LEVEL variable.
* This preference can be modified manually by visiting about:config
* greasemonkey.scriptvals.Rob W/Don't track me Google.HIDE_REFERRER_LEVEL
* This feature is fully covered at: http://userscripts.org/topics/97940
*/
if (typeof GM_getValue === 'function') {
var user_pref = GM_getValue('HIDE_REFERRER_LEVEL');
if (+user_pref === user_pref || /^\d+$/.test(user_pref)) {
HIDE_REFERRER_LEVEL = user_pref & 3;
}
}
function main() {
preventURLRewrites();
// Cleans links on hover to show a clear URL in the statusbar
bind_cleanOnHover();
bind_referrerHider_webkit();
}
function preventURLRewrites() {
// To be inserted in the page itself
function injectedFunction() {
'use strict';
// This part disables the UGLY URI-converting
if (Object.defineProperty) { // FF 4+, Chrome 5+
Object.defineProperty(window, 'rwt', {
value: function() {return true;},
writable: false, configurable: false
});
} else { // FF (2-3.6), Chrome 1-4
window.__defineGetter__('rwt', function() {
return function() {return true;};
});
}
}
/* Create script tag to inject in Google Search page */
var s = document.createElement('script');
s.textContent = '(' + injectedFunction + ')()';
(document.head||document.documentElement).appendChild(s);
s.parentNode.removeChild(s);
}
// This method makes sure that the URL "looks good",
// ie replaces http://google.com/url?=<url> with <url>
// Returns false if a referrer hiding method is needed.
function noTracks(a) {
var url;
// Not a link? Bye!
if (!a.href) return true;
// Not on a search page? Don't bother changing the URL,
// as it may have unexpected side effects
if (!document.querySelector('[name=q]')) return true;
// A non-common http scheme? Don't try to redirect to avoid conflicts.
if (!/^(https?|ftps?):$/.test(a.protocol)) return true;
// <a href="#"> is an internal link/anchor, so referrer hiding is not needed
if (a.hash && a.href.split('#')[0] == location.href.split('#')[0]) return true;
// At this point, the URL is a Google link.
// Try to extract the target URL:
url = /[&?]url=([^&]+)/.exec(a.search);
if (url && /\/url$/.test(a.pathname)) {
a.href = decodeURIComponent(url[1]);
return false;
}
// Google Maps / Ditu
url = /[&?]q=(http[^&]+)/.exec(a.search);
if (url && /^\/local_url$/.test(a.pathname)) {
a.href = decodeURIComponent(url[1]);
return false;
}
// Remove mousedown event
a.removeAttribute('onmousedown');
return true;
}
function bind_cleanOnHover() {
// This part deals with already-converted URIs, by
// Replacing http://www.google.nl/url?url=<URI> with <URI>.
// Clean URL on hover (visual purposes only)
function cleanURL(e) {
var a = e.target, depth = 7;
while (a && a.tagName !== 'A' && --depth > 0) a = a.parentNode;
if (a && a.tagName === 'A') noTracks(a);
}
document.addEventListener('mouseover', cleanURL, true);
}
// <a rel=noreferrer> is supported in Webkit only.
function bind_referrerHider_webkit() {
function hideRefer(e) {
var a = e.target;
if (a && a.tagName !== 'A') a = a.parentNode;
if (a && a.tagName === 'A') {
a.rel = 'noreferrer';
noTracks(a);
}
}
// Left / middle / right (any) click
window.addEventListener('mousedown',hideRefer,true);
// Tab-tab-tab-Enter
window.addEventListener('keydown', hideRefer, true);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment