Skip to main content

Writing your Custom Search Chrome Extension

Did you know, all that it takes to develop a Google Chrome Extension is HTML, CSS, JavaScript and an icon. Sounds doable right?

Each extension has the following files:
  • A manifest file
  • One or more HTML files (unless the extension is a theme)
  • Optional: One or more JavaScript files
  • Optional: Any other files your extension needs—for example, image files
Extensions will run as separate processes: one per extension.

  1. Create a folder on your computer and call it CompactSearch. Create a manifest file (text file) inside the folder and call it manifest.json. Add the following contents to the file 
    {
      "name": "CompactSearch",
      "version": "1.0",
      "authors": [ {
          "email": "your_email@address.com",
          "name": "Your Name"
       } ],
      "description": "Search without opening an extra tab",
      "permissions": ["http://*.google.com/"],
      "browser_action": {
        "default_icon": "icon.png",
        "default_title": "Compact Search",
        "popup": "popup.html"
      },
      "icons": {
          "16": "icon_16.png",
          "48": "icon_32.png"
       }
    }
    
  2. Create a file popup.html and create the basic html template. With a div with id "searchResults".
    <html>
      <head>
    
      </head>
      <body>
       <div id="searchResults"></div>
      </body>
    </html> 
    
  3. Get a Custom Search API key from here
  4. Add the following line in the head section replacing API_KEY by your Custom Search API key
    <script src="https://www.google.com/jsapi?key=<API_KEY>" type="text/javascript"></script>
  5. Paste the following code in header
    <script>
    //<![CDATA[
    
    google.load("search", "1");
    
    function fnSearch(sVar) {
    // Create a search control
    var searchControl = new google.search.SearchControl(); 
     
    // Add in a set of custom searchers 
    searchControl.addSearcher(new google.search.ImageSearch());
    searchControl.addSearcher(new google.search.WebSearch());
    searchControl.addSearcher(new google.search.VideoSearch());
    searchControl.addSearcher(new google.search.NewsSearch());
    searchControl.addSearcher(new google.search.BlogSearch());
    
    // Set the Local Search center point
    var drawOptions = new google.search.DrawOptions();
    drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
    searchControl.draw(document.getElementById("searchresult"), drawOptions);
         
    // Execute an inital search
    if (sVar==undefined){
      sVar="India";
    }
    searchControl.execute(sVar);
    }
    google.setOnLoadCallback(fnSearch,"India");
    //]]>
    </script>
    
  6. Load the extension.
    1. Bring up the extensions management page by clicking the wrench icon and choosing Tools > Extensions.
    2. Click the Load unpacked extension button. A file dialog appears.
    3. In the file dialog, navigate to your extension's folder and click OK.
If your extension is valid, its icon appears next to the address bar, and information about the extension appears in the extensions page. Now click on the icon and start searching.
Further Reading:
Hosting an Application

Comments

Popular posts from this blog

access logs to PDT

zgrep "text" /var/log/nginx/access.log | awk '{print $6}' | sed -e 's/\"/\ /g' | awk -F'[:/]' '{   # Build a new date string that GNU date can understand   timestamp = $1 " " $2 " " $3 " " $4 ":" $5 ":" $6   cmd = "TZ=\"America/Los_Angeles\" date -d \"" timestamp " UTC\" \"+%Y-%m-%d %H:%M:%S %Z\""   cmd | getline converted   close(cmd)   print converted }'

Using a SOAP service as DLL

By default, when you do an Add Service Reference operation, the WCF runtime will generate the client-side proxy for you. The simplest way to use it is to instantiate the client proxy with a constructor that takes no parameters, and just grab the info from the app.config : YourServiceClient proxy = new YourServiceClient(); This requires the config file to have a <client> entry with your service contract - if not, you'll get the error you have. But the client side proxy class generated by the WCF runtime also has additional constructors - one takes an endpoint address and a binding, for instance: BasicHttpBinding binding = new BasicHttpBinding(); binding.Security.Mode = BasicHttpSecurityMode.Transport;  EndpointAddress epa = new EndpointAddress("http://example.com/api/?wsdl"); YourServiceClient proxy = new YourServiceClient(binding, epa); With this setup, no config file at all is needed - you're defining everything in code. Of course, you can also s...

Installing Nginx for PHP, MySQL

Nginx is a high performance HTTP server. It provides very fast speed of delivering web pages, and uses fewer resources at the same time. With Nginx (Pronounced Engine X) A server with low resources will be able to serve many more clients, due to this, many popular websites use this (To conserve their resources, of course). In this blog post, I am going to discuss how to install Nginx, along with PHP, and MYSQL. You will need to follow very close attention to this article, else, one mistake and you may need to restart all over again. The first thing you will need to do of course is own a VPS/Dedicated server. You will also need to have an SSH Client (Putty), and your username and password. If you have all of this, the first thing you need to do is login to your panel, and rebuild the server with some version of CentOS (it does not matter what version, really). Once you have done so, login to your SSH client, supplying the required information. Next, we are going to begin the actu...