Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use the Google Search API and the gSearch jQuery plugin from a userscript?
    primarykey
    data
    text
    <p>I'm trying to put together a userscript (for use in Chrome) and I keep hitting a wall. My first goal is to have <a href="http://gsearch.scottreeddesign.com/documentation.html" rel="nofollow">Scott Reed's gSearch jQuery plugin</a> working on any page via the script.</p> <p>Here is the script I have from shoving snippets and examples, I find here and there, together:</p> <p>The error I'm getting with this is "<code>Uncaught TypeError: Cannot read property 'WebSearch' of undefined</code>".<br> <br> </p> <pre class="lang-js prettyprint-override"><code>// ==UserScript== // @name Example // @version 1.2 // @namespace // @description // @include * // ==/UserScript== function addScripts(callback) { var script = document.createElement("script"); script.setAttribute("src", "http://google.com/jsapi"); script.addEventListener('load', function() { var script = document.createElement("script"); script.textContent = "(" + callback.toString() + ")();"; document.body.appendChild(script); }, false); document.body.appendChild(script); var script = document.createElement("script"); script.setAttribute("src", "http://gsearch.scottreeddesign.com/js/jquery.gSearch-1.0-min.js"); script.addEventListener('load', function() { var script = document.createElement("script"); script.textContent = "(" + callback.toString() + ")();"; document.body.appendChild(script); }, false); document.body.appendChild(script); } function LoadGoogle() { if(typeof google != 'undefined' &amp;&amp; google &amp;&amp; google.load) { google.load("search", "1"); } else { // Retry later... setTimeout(LoadGoogle, 30); } } LoadGoogle(); function main() { $("#div").css("border", ".5em solid black"); $('head').append('&lt;link rel="stylesheet" href="http://gsearch.scottreeddesign.com/css/gSearch.css" type="text/css" /&gt;'); $('body').append('&lt;div id="search-results"&gt;&lt;/div&gt;'); $('#div').click( function() { $("#search-results").gSearch({search_text : 'example search'}); }); } // load scripts and execute the main function addScripts(main); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload