template.user.js
// ==UserScript==
// @name Stack Exchange Userscript (Template)
// @grant none
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.askububtuaskubuntu.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// ==/UserScript==
var userscript = function($) {
// INSERT YOUR USERSCRIPT CODE HERE
};
var el = document.createElement('script');
el.type = 'text/javascript';
el.text = '(' + userscript + ')(jQuery);';
document.head.appendChild(el);
This template will
- Guarantee that your script can only run on Stack Exchange sites
- Run on all Stack Exchange sites (as of 7-10-2014, will be updated as necessary if new sites with unique URLs are added)
- Allow you to reliably use
$
asjQuery
within your userscript - Be compatible with all major browsers (really not that fancy; should work virtually anywhere)