Last active
December 20, 2015 19:49
-
-
Save veltman/6186441 to your computer and use it in GitHub Desktop.
Bookmarklet, when executed on a google search results page it will cycle through everything in search_terms[] and record the suggestions to a big JSON object. After it cycles through all the terms, it will replace the document HTML with the stringified JSON. Minify it before using it.
This file contains hidden or 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
(function(){ | |
//get jQuery | |
if (window.jQuery === undefined) { | |
var done = false; | |
var script = document.createElement("script"); | |
script.src = "http:////ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"; | |
script.onload = script.onreadystatechange = function(){ | |
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) { | |
done = true; | |
initBookmarklet(); | |
} | |
}; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} else { | |
initBookmarklet(); | |
} | |
//List of search terms to try; fill this in | |
var search_terms = []; | |
//this will be the end result | |
var output = {"host": window.location.host, "results": {}}; | |
var current_term = ""; | |
var interval; | |
function initBookmarklet() { | |
$input = $("input#gbqfq"); | |
current_term = search_terms.shift(); | |
$input.val(current_term); | |
$input.focus(); | |
interval = setInterval(getResults,2000); | |
} | |
//Set the value of the search input and wait 2 seconds before checking for suggestions | |
//On a slow connection or a proxy you might need more time, change 2000 to something bigger | |
function getResults() { | |
var $spans = $("div.gsq_a span"); | |
var prefix = $("input#gbqfq").val(); | |
if (!prefix.length) alert("no search prefix found."); | |
else if (!$spans.length) alert("no suggestions found for "+prefix+"."); | |
else { | |
var temp = []; | |
$spans.each(function(i) { | |
if ($(this).text().indexOf(prefix) == -1) { | |
clearInterval(interval); | |
interval = setInterval(getResults,2000); | |
$input.focus(); | |
return true; | |
} | |
temp.push($(this).html()); | |
}); | |
output.results[prefix] = temp; | |
} | |
if (!search_terms.length) { | |
clearInterval(interval); | |
$("body").html(JSON.stringify(output)); | |
} else { | |
$input = $("input#gbqfq"); | |
current_term = search_terms.shift(); | |
$input.val(current_term); | |
$input.focus(); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment