googletracking-be-gone/googletracking-b-gone.user.js

91 lines
3.0 KiB
JavaScript
Raw Normal View History

2012-07-10 01:23:28 +04:00
// Google Tracking-B-Gone - FIXED version (by Vitaliy Filippov)
2023-03-12 15:21:26 +03:00
// version 2.9
// Release Date: 2023-03-12
2023-03-12 15:39:42 +03:00
// Published on https://openuserjs.org/scripts/vitalif/Google_Tracking-B-Gone
// Published on https://greasyfork.org/en/scripts/1810-google-tracking-b-gone
2012-07-10 01:23:28 +04:00
//
// ===== INSTRUCTIONS =====
//
// This is a Greasemonkey user script.
2014-01-23 22:17:39 +04:00
// Now supports Opera (Presto).
2012-07-10 01:23:28 +04:00
//
2014-06-23 16:22:10 +04:00
// === FIREFOX ===
//
2012-07-10 01:23:28 +04:00
// To use this script in Firefox, get Greasemonkey: http://greasemonkey.mozdev.org/
// After you've installed it, come back to this page. A dialog box will
// appear asking you if you want to install this script.
//
// To uninstall, go to Tools->Greasemonkey->Manage User Scripts, select
// "Google Tracking-B-Gone" from the list on the left, and click
// Uninstall.
//
2014-06-23 16:22:10 +04:00
// === OPERA ===
//
2012-07-10 01:23:28 +04:00
// To use it in Opera, create a directory for userscripts, put this file into it,
// then go to Settings -> Content -> JS and point userscript directory to the
// newly created directory.
2014-01-23 22:17:39 +04:00
// Also set 'User JavaScript on HTTPS' = on in about:config.
//
2014-06-23 16:22:10 +04:00
// === CHROME/CHROMIUM ===
//
// To use it in Chrome, open Settings -> Extensions, enter developer mode by setting the checkbox,
// drag-and-drop this file to chrome window and confirm installation.
//
2012-07-10 01:23:28 +04:00
// ==UserScript==
// @name Google Tracking-B-Gone
// @namespace http://sbdev.org
// @description Strips click tracking from Google search results
2023-03-12 15:27:23 +03:00
// @license MIT
2012-07-10 01:23:28 +04:00
// @include http://*.google.*
// @include https://*.google.*
2023-03-12 15:27:23 +03:00
// @version 2.9
2012-07-10 01:23:28 +04:00
// ==/UserScript==
// make sure we run at least once, regardless of search results page version
if (!document.body)
document.addEventListener('DOMContentLoaded', function() { doIt(); });
else
doIt();
2012-07-10 01:23:28 +04:00
document.addEventListener('DOMAttrModified', function (event) {
doIt(event.target);
2012-07-10 01:23:28 +04:00
if (event.target.id == 'xfoot' || event.target.parentNode.id == 'bfoot') {
doIt();
}
}, false);
document.addEventListener('DOMSubtreeModified', function (event) {
doIt(event.target);
2012-07-10 01:23:28 +04:00
if (event.target.id == 'xfoot') {
doIt();
}
}, false);
document.addEventListener('DOMNodeInserted', function (event) {
2013-02-06 19:47:00 +04:00
if (event.target.parentNode.id == 'gsr') {
doIt();
2012-07-10 01:23:28 +04:00
}
}, false);
function doIt(e) {
2018-12-16 14:57:26 +03:00
var resultLinks = e ? e.querySelectorAll('h3') : document.body.querySelectorAll('h3');
for (var i = 0; i < resultLinks.length; i++) {
2018-12-16 14:57:26 +03:00
var link = resultLinks[i].parentNode.nodeName == 'A' ? resultLinks[i].parentNode : resultLinks[i].childNodes[0];
2023-03-12 15:21:26 +03:00
if (link.nodeName != 'A') {
continue;
}
var oldLink = link.href;
if (/^(https?:\/\/(www\.|encrypted\.)?google\.[^\/]*)?\/?url/.test(oldLink)) {
2021-12-21 02:17:33 +03:00
var matches = /[\?&]url=(.+?)&/.exec(oldLink);
2012-07-10 01:23:28 +04:00
if (matches != null) {
2021-12-21 02:17:33 +03:00
link.href = unescape(matches[1]);
2012-07-10 01:23:28 +04:00
}
}
// Clear attached event listeners so google can't mangle urls on mouse click
2013-02-06 19:47:00 +04:00
if (link.getAttribute('onmousedown')) {
link.removeAttribute('onmousedown');
}
resultLinks[i].innerHTML = resultLinks[i].innerHTML;
2012-07-10 01:23:28 +04:00
}
}