Skip to content

Instantly share code, notes, and snippets.

@jordam
Created February 5, 2016 11:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordam/10dae2a6fe774d4cd890 to your computer and use it in GitHub Desktop.
Save jordam/10dae2a6fe774d4cd890 to your computer and use it in GitHub Desktop.
//Paste this into a chrome console to dump out a list of the search urls on the page
function fixLinksOfClassL() {
// fix old-style class="l" links
var ts = document.getElementsByClassName("l");
for (var i=0; i < ts.length; i++) {
var t = ts[i];
if (t.tagName == "A") {
// remove javascript callback first
t.removeAttribute("onmousedown");
// fix link if necessary
var href = t.getAttribute("href");
var m = href.match(/&url=([^&]*)/);
if (m) {
t.setAttribute('href',decodeURIComponent(m[1]));
}
}
}
return ts.length;
}
function fixClasslessLinks() {
// fix new classless links (noticed in some search results)
var results = document.getElementById("search");
var ts = results.getElementsByTagName("A");
for (var i=0; i < ts.length; i++) {
t = ts[i];
t.removeAttribute("onmousedown");
var href = t.getAttribute("href");
var m = href.match(/\/url?.*q=([^&]*)/)
if (m) {
t.setAttribute('href',decodeURIComponent(m[1]));
}
}
return ts.length;
}
function Dump() {
var n = fixLinksOfClassL();
if (n == 0) {
fixClasslessLinks();
}
var ids = [];
$('h3.r a[href]').each(function () {
ids.push($(this).attr('href')); // ids.push(this.id) would work as well.
});
document.body.innerHTML = ids.join('<br>');
}
var script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-1.11.0.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
document.addEventListener('DOMNodeInserted',Dump,false);
Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment