Skip to content

Instantly share code, notes, and snippets.

@Orangenhain
Created February 10, 2012 20:10
Show Gist options
  • Save Orangenhain/1792384 to your computer and use it in GitHub Desktop.
Save Orangenhain/1792384 to your computer and use it in GitHub Desktop.
Fix Safari links using Detox
If you use Safari and CMD+Click on a page to open it in a background tab,
the Safari History doesn't register the final URL, only the first step.
Leading to lots of links named "http://www.google.com/url?....12ASDF8234"
in your history, thus making it useless.
To fix this, one can change the Info.plist of Detox to also include the domains:
www.google.com, www.google.co.uk, www.google.XYZ, ...
( "www.google.*" apparently is an invalid pattern)
And add the following piece of code to end.js:
else if (window.location.href.match(/www\.google\./))
{
// to get around Google's "Instant Search" feature
// ( i.e. this code would only get executed once,
// and does not see subsequent searches ),
// we use a timer
window.setInterval(function()
{
var links = document.getElementsByClassName('l');
for (var i=0, link; link = links[i++];)
{
if ( ! link.onmousedown )
{
continue;
}
link.removeAttribute("onmousedown");
console.log("link: " + link.href);
}
}, 1000);
}
@toonetown
Copy link

If you change the document.getElementsByClassName('l'); part to read document.querySelectorAll('a[onmousedown]');, it will be a bit more robust (currently, the links don't have an 'l' class)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment