Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save v2keener/9665787 to your computer and use it in GitHub Desktop.
Save v2keener/9665787 to your computer and use it in GitHub Desktop.
Snippet: Base TamperMonkey injection script with jQuery via Google APIs
// ==UserScript==
// @name ${1:Some fancy name}
// @namespace ${2:https://gist.github.com/9665787}
// @version 0.1
// @description ${3:Some description}
// @match /* ALLOW TAMPERMONKEY TO FILL THIS IN *OR* COPY FROM TAMPERMONKEY */
// @copyright 2014+, ${4:Gustavo Keener}
// ==/UserScript==
// Add jQuery, unless it already exists
if(typeof jQuery === 'undefined'|| !jQuery){
(function(){
var s=document.createElement('script');
s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js');
if(typeof jQuery=='undefined'){
document.getElementsByTagName('head')[0].appendChild(s);
}
})();
}
(function(){
var codeToExecute = function(){
/***********************/
// YOUR CODE HERE
/***********************/
${5:alert('This is a message from a TamperMonkey script!');}
};
var intervalInt = window.setInterval(function(){
if(typeof jQuery !== 'undefined' && jQuery){
// Clear this interval
window.clearInterval(intervalInt);
codeToExecute();
}
}, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment