Last active
August 29, 2015 14:19
-
-
Save danguilherme/2e6e913ebdd491b06225 to your computer and use it in GitHub Desktop.
All my public user scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Useful Scripts | |
// @version 1.3.0 | |
// @description Useful scripts for developers, to be loaded and used in every page | |
// @match http://**/* | |
// @author Guilherme Ventura | |
// @downloadURL https://rawgit.com/danguilherme/2e6e913ebdd491b06225/raw/useful_scripts.user.js | |
// @grant unsafeWindow | |
// ==/UserScript== | |
unsafeWindow.us = { | |
loadScript: function(url,callback) { | |
var element = document.createElement("script"); | |
element.src = url; | |
unsafeWindow.document.body.appendChild(element); | |
element.onload=callback; | |
}, | |
loadStyle: function(url,callback) { | |
var element = document.createElement("link"); | |
element.href = url; | |
element.rel = 'stylesheet'; | |
element.type = 'text/css'; | |
unsafeWindow.document.body.appendChild(element); | |
element.onload=callback; | |
}, | |
addScript: function(text) { | |
var element = document.createElement("script"); | |
element.textContent = text; | |
unsafeWindow.document.body.appendChild(element); | |
}, | |
jqplz: function(callback) { | |
var me = this; | |
me.loadScript('//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js', function() { | |
callback = callback || function() { unsafeWindow.console.info('jQuery loaded'); }; | |
me.addScript('window.jQ=jQuery.noConflict(true);(function($) {(' + callback.toString() + ')()})(window.jQ);'); | |
}); | |
}, | |
prettify: function(selector, lang) { | |
var me = this; | |
var doc = unsafeWindow.document; | |
var els = doc.querySelectorAll(selector); | |
for (var i = 0; i < els.length; i++) { | |
var el = els[i]; | |
el.classList.add('prettyprint'); | |
if(lang) el.classList.add('lang-' + lang); | |
} | |
this.loadScript('//cdnjs.cloudflare.com/ajax/libs/prettify/r298/run_prettify.min.js', function() { | |
// if(!me.prettifyStyleLoaded) { | |
// me.loadStyle('//google-code-prettify.googlecode.com/svn/trunk/styles/sons-of-obsidian.css'); | |
// me.prettifyStyleLoaded = true; | |
//} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment