Skip to content

Instantly share code, notes, and snippets.

@leeramsay
Forked from k-barton/remove-fb-tracking.user.js
Last active July 8, 2016 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeramsay/0a8dcd00d32e38a4a4e9a6494aac1fa0 to your computer and use it in GitHub Desktop.
Save leeramsay/0a8dcd00d32e38a4a4e9a6494aac1fa0 to your computer and use it in GitHub Desktop.
Greasemonkey user script: Remove Facebook's external link tracking
// ==UserScript==
// @name Remove Facebook's external link tracking
// @description Removes redirection from external FB links
// @namespace https://gist.github.com/k-barton
// @include https://*.facebook.com*
// @include http://*.facebook.com*
// @version 0.1.0
// @grant none
// ==/UserScript==
(function () {
var redirectionUrl = 'https://l.facebook.com/l.php';
var fix_link = function (el) {
var isFixed = false;
var onclick = el.getAttribute('onclick');
if (onclick !== null && onclick.indexOf('LinkshimAsyncLink') != - 1) {
el.removeAttribute('onclick');
el.removeAttribute('onmouseover');
isFixed = true;
}
if (el.href.indexOf(redirectionUrl) > - 1) {
var href = el.href;
var s = href.substring(href.indexOf('?') + 1);
s = s.split('&');
for (var i in s) {
if (s[i].indexOf('u=') === 0) {
s = s[i];
el.href = decodeURIComponent(s.substring(s.indexOf('=') + 1));
isFixed = true;
break;
}
}
}
if (isFixed && el.textContent !== '') el.style.backgroundColor = '#FFEE22';
};
document.addEventListener('DOMContentLoaded', function (event) {
document.onmouseover = function (event) {
if (event.target.tagName == 'A')
fix_link(event.target);
};
}, false);
}) ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment