Chrome Userscript Extension Template

Write a Greasemonkey userscript for Chrome and Chromium.

// ==UserScript==
// @name           My Script
// @match          https://www.example.com/
// ==/UserScript==
 
console.log('included');
 
function addJQuery(callback) {
    var script = document.createElement('script');
    script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
    script.addEventListener('load', function() {
        var script = document.createElement('script');
        script.textContent = 'window.jQ=jQuery.noConflict(true);(' + callback.toString() + ')();';
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}
 
addJQuery(function() {
    console.log('jQuery added', jQ);
    jQ('.selector').find('button').click();
});
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment