Monday, May 9, 2016

Google Chrome extension development tips

1) Get manifest.json properties of running chrome extension
chrome.runtime.getManifest() 

2) Integrate live google search in google chrome extension

Sample code below, supposingly using jQuery.UI widget with <input id="googleSearch">:

$("#googleSearch").autocomplete({
   source: function(request, response) { 
    $.ajax({ url: "https://suggestqueries.google.com/complete/search?client=chrome&q=",
  dataType: "jsonp",
  data: { q: request.term },
  success: function(data) { response(data[2].splice(0, 15)); } }); },
  minLength: 1,
  select: function(event, ui) { 
   var value = ui.item.label;
   if (ui.item.label.indexOf("http://") === -1 &&      ui.item.label.indexOf("https://") === -1)
  { 
   value = "http://google.com/search?q=" + value }
   document.location = value; 
 }
});

No comments:

Post a Comment