Skip to content

Instantly share code, notes, and snippets.

@efreed
Last active August 29, 2015 14:00
Show Gist options
  • Save efreed/11303977 to your computer and use it in GitHub Desktop.
Save efreed/11303977 to your computer and use it in GitHub Desktop.
Google Search Results Mockup Bookmarklet
<!DOCTYPE html>
<html>
<head>
<title>Install and use the Google Results Mockup Bookmarklet</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
a.bookmarklet {
display: -moz-inline-box;
display: inline-block;
padding: 1px 6px;
height: 18px;
color: #fff;
background: #32a0eb;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
</style>
</head>
<body>
<h1>Install and use the Google Results Mockup Bookmarklet</h1>
First, drag this button to your bookmark bar:
<a class="bookmarklet" href="javascript:(function()%7Bvar%20rewriter%20%3D%20document.createElement(%22div%22)%3Brewriter.id%20%3D%20%22rewriter%22%3Brewriter.style.cssText%3D%22position%3Aabsolute%3B%20top%3A0%3B%20right%3A0%3B%20border%3A2px%20solid%20gold%3B%20padding%3A5px%3B%20z-index%3A999%3B%20background%3Awhite%3B%22%3Bdocument.querySelector(%22body%22).appendChild(rewriter)%3Bdocument.querySelector(%22%23rewriter%22).innerHTML%3D'Which%20Result%3A%20%3Cselect%20id%3D%22reI%22%20onchange%3D%22document.reselect(this.selectedIndex)%22%3E%3C%2Fselect%3E%3Ca%20href%3D%22javascript%3Avoid(document.querySelector(%5C'%23rewriter%5C').remove())%22%20style%3D%22float%3Aright%22%3Eclose%3C%2Fa%3E%3Cbr%3ETitle%3A%3Cinput%20id%3D%22reTitle%22%20size%3D%2299%22%20onKeyUp%3D%22document.rewrite(%5C'a%5C'%2Cthis.value)%22%3E%3Cbr%3EURL%3A%20%3Cinput%20id%3D%22reUrl%22%20%20size%3D%2298%22%20onKeyUp%3D%22document.rewrite(%5C'cite%5C'%2Cthis.value)%22%3E%3Cbr%3EDesc%3A%20%3Cinput%20id%3D%22reDesc%22%20%20size%3D%2297%22%20onKeyUp%3D%22document.rewrite(%5C'.st%5C'%2Cthis.value)%22%3E%3Cbr%3E'%3Bdocument.results%20%3D%20document.querySelectorAll(%22%23rso%20li.g%22)%3Bdocument.rewrite%20%3D%20function(sel%2Cval)%20%7Bdocument.results%5Bdocument.querySelector(%22%23reI%22).selectedIndex%5D.querySelector(sel).innerHTML%20%3D%20val%3B%7D%3Bdocument.reread%20%3D%20function(sel)%20%7Bconsole.log(document.results%5Bdocument.querySelector(%22%23reI%22).selectedIndex%5D)%3Breturn%20document.results%5Bdocument.querySelector(%22%23reI%22).selectedIndex%5D.querySelector(sel).innerHTML%3B%7D%3Bdocument.reinit%20%3D%20function()%20%7Bvar%20found%20%3D%20%22%22%3Bfor%20(var%20i%20%3D%200%3B%20i%20%3C%20document.results.length%3B%20i%2B%2B)%20%7Bfound%20%2B%3D%20%22%3Coption%3E%22%20%2B(i%2B1)%20%2B%22%3C%2Foption%3E%22%3B%7D%3Bdocument.querySelector(%22%23reI%22).innerHTML%20%3D%20found%3Bdocument.querySelector(%22%23reI%22).selectedIndex%20%3D%201%3Bdocument.reselect(1)%3B%7D%3Bdocument.reselect%20%3D%20function(i)%20%7Bdocument.querySelector(%22%23reTitle%22).value%20%3D%20document.reread(%22a%22)%3Bdocument.querySelector(%22%23reUrl%22).value%20%3D%20document.reread(%22cite%22)%3Bdocument.querySelector(%22%23reDesc%22).value%20%3D%20document.reread(%22.st%22)%3B%7D%3Bdocument.reinit()%7D)()"
>Edit Google Results</a>
<br><br>
Second, while on a google results page, click the toolbar button to make an edit form will appear in the top right.<br>
Select the search result number you want to edit from the pulldown and edit it's content using the input boxes.<br>
The google result will update immediately as you type.<br>
When done, there's a "close" link on the top right to remove the edit form.<br>
<!--
// this supposed to set the favicon for the bookmarklet if it's clicked on a non-google site... but tests aren't working.
if (window.location.href.indexOf('google.com') < 0) {
return '<!DOCTYPE html><html><head><link rel="shortcut icon" href="http://www.fivetalent.com/favicon.ico"></head><body>This works on a Google search results page</body></html>';
}
// Raw source .. ugly .. I walked into this backwards and in a rush
var rewriter = document.createElement("div");
rewriter.id = "rewriter";
rewriter.style.cssText="position:absolute; top:0; right:0; border:2px solid gold; padding:5px; z-index:999; background:white;";
document.querySelector("body").appendChild(rewriter);
document.querySelector("#rewriter").innerHTML='Which Result: <select id="reI" onchange="document.reselect(this.selectedIndex)"></select><a href="javascript:void(document.querySelector(\'#rewriter\').remove())" style="float:right">close</a><br>Title:<input id="reTitle" size="99" onKeyUp="document.rewrite(\'a\',this.value)"><br>URL: <input id="reUrl" size="98" onKeyUp="document.rewrite(\'cite\',this.value)"><br>Desc: <input id="reDesc" size="97" onKeyUp="document.rewrite(\'.st\',this.value)"><br>';
document.results = document.querySelectorAll("#rso li.g");
document.rewrite = function(sel,val) {
document.results[document.querySelector("#reI").selectedIndex].querySelector(sel).innerHTML = val;
};
document.reread = function(sel) {
console.log(document.results[document.querySelector("#reI").selectedIndex]);
return document.results[document.querySelector("#reI").selectedIndex].querySelector(sel).innerHTML;
};
document.reinit = function() {
var found = "";
for (var i = 0; i < document.results.length; i++) {
found += "<option>" +(i+1) +"</option>";
};
document.querySelector("#reI").innerHTML = found;
document.querySelector("#reI").selectedIndex = 1;
document.reselect(1);
};
document.reselect = function(i) {
document.querySelector("#reTitle").value = document.reread("a");
document.querySelector("#reUrl").value = document.reread("cite");
document.querySelector("#reDesc").value = document.reread(".st");
};
document.reinit();
-->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment