Skip to content

Instantly share code, notes, and snippets.

@basilfx
Created July 19, 2012 21:37
Show Gist options
  • Save basilfx/3147003 to your computer and use it in GitHub Desktop.
Save basilfx/3147003 to your computer and use it in GitHub Desktop.
Massive Music Quiz ft. Google Search
jQuery("body").append('<div><div id="google_search" style="width: 400px;margin-right: 0px;;margin-left: 1000px; border: 1px solid #000; background-color: white;"></div>');
jQuery("#container").css({ margin : "inherit"});
(function(e){e.fn.gSearch=function(h){var a=e.extend({},e.fn.gSearch.defaults,h);if(a.search_text==undefined)return this;if(a.search_text=="")return this;return this.each(function(){var f=e(this);f.addClass("google-search-results");a.pagination=a.pagination=="false"||a.pagination==false?false:true;f.html('<span style="text-decoration: blink;">Loading...</span>');_google_search=new google.search.WebSearch;var d="";a.count*1>4&&_google_search.setResultSetSize(google.search.Search.LARGE_RESULTSET);if(a.site.length> 0){a.site=a.site.substring(0,4)=="www."?a.site.substring(4,a.site.length):a.site;a.site.length>0&&_google_search.setSiteRestriction(a.site)}_google_search.setSearchCompleteCallback(this,function(){d="";if(_google_search.results&&_google_search.results.length>0){var c=_google_search.results;if(c.length>0){f.html("");d+='<div class="results">';for(var b=0;b<c.length;b++)d+='<div class="result"><div class="title"><a href="'+c[b].url+'"><span>'+c[b].title+'</span></a></div><div class="snippet"><span>'+ c[b].content+'</span></div><div class="url-cache"><span>'+c[b].url.replace("http://","")+'</span>&nbsp;-&nbsp;<a href="'+c[b].cacheUrl+'">Cached</a></div></div>';d+="</div>";if(a.pagination){c=_google_search.cursor;var g=c.currentPageIndex;d+='<div class="pagination"><ul>';if(g>0)d+=' <li class="prev-next prev"><a href="#" onclick="_google_search.gotoPage('+(g*1-1)+');return false;">Previous</a></li> \r';for(b=0;b<c.pages.length;b++)d+=' <li class="numbers '+(g==b?" selected":"")+'"><a href="#" onclick="_google_search.gotoPage('+ b+');return false;">'+c.pages[b].label+"</a></li> \r";if(g<c.pages.length-1)d+=' <li class="prev-next next"><a href="#" onclick="_google_search.gotoPage('+(g*1+1)+');return false;">Next</a></li> \r';d+="</ul></div>"}f.html(d)}}},null);_google_search.execute(a.search_text);d.length==0&&f.html('<div class="no-results"><p class="first-child">Your search - <b>'+a.search_text+'</b> - did not match any documents.</p><p class="second-child">Suggestions:</p><ul><li>Make sure all words are spelled correctly.</li><li>Try different keywords.</li><li>Try more general keywords.</li></ul></div>')})}; e.fn.gSearch.defaults={search_text:"",count:"4",site:"",pagination:true}})(jQuery);
google.load("search", "1", { callback : function() {
jQuery("#guess").keypress(function(event) {
if (event.which == 13 ) {
jQuery("#google_search").gSearch({
search_text : jQuery(this).val() + ' lyrics',
count : 10,
pagination : false
});
setTimeout(function() {
jQuery("#google_search .results a").dblclick(function(e) {
e.preventDefault();
jQuery(this).click();
setTimeout(function() {
jQuery("#send-button").click();
}, 100);
});
jQuery("#google_search .results a").click(function(e) {
e.preventDefault();
var guess = jQuery(this).text() + "";
guess = guess.toLowerCase();
guess = guess.replace("-", "");
guess = guess.replace(" lyrics", "");
guess = guess.replace(" - youtube");
var removeAfter = guess.indexOf("|");
if (removeAfter != -1) {
guess = guess.substring(0, removeAfter - 1);
}
jQuery("#guess").val(guess);
});
}, 750);
}
});
}});
@basilfx
Copy link
Author

basilfx commented Jul 19, 2012

Just copy/paste in the Element Inspector JavaScript Console when you are in-game. Then, the input box will search Google too. Click a result title to use as an answer.

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