Created
May 22, 2012 07:17
-
-
Save prajwalit/2767298 to your computer and use it in GitHub Desktop.
Code from redirection fix extension ( https://chrome.google.com/webstore/detail/onhdomkbnapoacbialllfpbcckckidck )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @include https://www.facebook.com/* | |
// @include https://facebook.com/* | |
// @include http://www.facebook.com/* | |
// @include http://facebook.com/* | |
// @run-at document-start | |
// ==/UserScript== | |
document.addEventListener ('DOMNodeInserted', checksearch, false); | |
function checksearch () { | |
if (window.location.hostname.match (/www\.facebook\.com/)) { | |
document.removeEventListener ('DOMNodeInserted', checksearch, false); | |
document.addEventListener ('DOMNodeInserted', huntForLinks, false); | |
} | |
} | |
var fixRedirect = function(event) { | |
var node = event.target; | |
node.removeEventListener ('mouseenter', fixRedirect, false); | |
var fbRedirectURL = "http://www.facebook.com/l.php?u="; | |
var refString = /&h=(.+)$/; | |
var realHref = node.href.replace (fbRedirectURL,""); | |
if (realHref && realHref != node.href) { | |
realHref = realHref.replace (refString, ""); | |
node.href = unescape (realHref); | |
} | |
}; | |
function huntForLinks () { | |
var items = document.getElementsByTagName ('a'); | |
for (var i = 0; i < items.length; i++) { | |
var hasMouseDown = items[i].getAttribute ('onmousedown'); | |
if (hasMouseDown && /^UntrustedLink/.test(hasMouseDown)) { | |
items [i].removeAttribute ('onmousedown'); | |
items [i].addEventListener ('mouseenter', fixRedirect, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment