Skip to content

Instantly share code, notes, and snippets.

@yaronv
Created January 19, 2015 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaronv/9c4175ef660a502027ef to your computer and use it in GitHub Desktop.
Save yaronv/9c4175ef660a502027ef to your computer and use it in GitHub Desktop.
;(function() {
$(document).ready(function(){
var searchInput = $("#search");
$("#searchButton").on("click", function(e) {
searchClick(e);
});
searchInput.keypress(function(e){
if (e.which == 13){
searchClick(e);
}
});
searchInput.focus();
});
function searchClick(e, val) {
val = val || $("#search").val().trim();
event.preventDefault();
if(val == '') {
$("#search").addClass("errorInput");
setTimeout(function() {
$("#search").removeClass("errorInput");
}, 200)
return;
}
var url = "https://www.google.com/search?q="+val.split(' ').join('+');
chrome.tabs.create({
url: url,
}, function(tab) {
//chrome.tabs.sendMessage(tab.id, {search: $("#search").val().trim()}, function(response) {
//});
});
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment