Skip to content

Instantly share code, notes, and snippets.

@erikvold
Created June 14, 2010 10:06
Show Gist options
  • Save erikvold/437513 to your computer and use it in GitHub Desktop.
Save erikvold/437513 to your computer and use it in GitHub Desktop.

Revisions

  1. erikvold revised this gist Jun 14, 2010. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion jQueryForChromeExample.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@
    // @namespace jQueryForChromeExample
    // @include *
    // @author Erik Vergobbi Vold
    // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
    // @description This userscript is meant to be an example on how to use jQuery in a userscript on Google Chrome.
    // ==/UserScript==

  2. erikvold revised this gist Jun 14, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jQueryForChromeExample.user.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // ==UserScript==
    // @name jQuery For Chrome Example
    // @name jQuery For Chrome (A Cross Browser Example)
    // @namespace jQueryForChromeExample
    // @include *
    // @author Erik Vergobbi Vold
  3. erikvold revised this gist Jun 14, 2010. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions jQueryForChromeExample.user.js
    Original file line number Diff line number Diff line change
    @@ -11,13 +11,17 @@
    function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    script.addEventListener('load', function() {callback();}, false);
    script.addEventListener('load', function() {
    var script = document.createElement("script");
    script.textContent = "(" + callback.toString() + ")();";
    document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
    }

    // the guts of this userscript
    function main() {
    alert("There are " + (unsafeWindow || window).$('a').length + " links on this page.");
    alert("There are " + $('a').length + " links on this page.");
    }

    // load jQuery and execute the main function
  4. erikvold revised this gist Jun 14, 2010. 1 changed file with 15 additions and 6 deletions.
    21 changes: 15 additions & 6 deletions jQueryForChromeExample.user.js
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,23 @@
    // @name jQuery For Chrome Example
    // @namespace jQueryForChromeExample
    // @include *
    // @version 0.1
    // @author Erik Vergobbi Vold
    // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
    // @description This userscript is meant to be an example on how to use jQuery in a userscript on Google Chrome.
    // ==/UserScript==

    var script = document.createElement("script");
    script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    script.setAttribute("async", "true");
    script.onload = function() {alert("There are " + window.$('a').length + " links on this page.");};
    document.body.appendChild(script);
    // a function that loads jQuery and calls a callback function when jQuery has finished loading
    function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    script.addEventListener('load', function() {callback();}, false);
    document.body.appendChild(script);
    }

    // the guts of this userscript
    function main() {
    alert("There are " + (unsafeWindow || window).$('a').length + " links on this page.");
    }

    // load jQuery and execute the main function
    addJQuery(main);
  5. erikvold revised this gist Jun 14, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jQueryForChromeExample.user.js
    Original file line number Diff line number Diff line change
    @@ -11,5 +11,5 @@
    var script = document.createElement("script");
    script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    script.setAttribute("async", "true");
    script.onload = function() {alert("There are " + $('a').length + " links on this page.");};
    script.onload = function() {alert("There are " + window.$('a').length + " links on this page.");};
    document.body.appendChild(script);
  6. erikvold created this gist Jun 14, 2010.
    15 changes: 15 additions & 0 deletions jQueryForChromeExample.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // ==UserScript==
    // @name jQuery For Chrome Example
    // @namespace jQueryForChromeExample
    // @include *
    // @version 0.1
    // @author Erik Vergobbi Vold
    // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
    // @description This userscript is meant to be an example on how to use jQuery in a userscript on Google Chrome.
    // ==/UserScript==

    var script = document.createElement("script");
    script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    script.setAttribute("async", "true");
    script.onload = function() {alert("There are " + $('a').length + " links on this page.");};
    document.body.appendChild(script);