Skip to content

Instantly share code, notes, and snippets.

@idettman
idettman / add-css-dynamically.js
Created September 26, 2017 13:06
Add CSS dynamically using JS
// Add a new stylesheet to the document;
// url [optional] A url to an external stylesheet to use
// idx [optional] The index in document.styleSheets to insert the new sheet before
function AddStyleSheet(url,idx){
var css,before=null,head=document.getElementsByTagName("head")[0];
if (document.createElement){
if (url){
css = document.createElement('link');
css.rel = 'stylesheet';
@BrockA
BrockA / waitForKeyElements.js
Created May 7, 2012 04:21
A utility function, for Greasemonkey scripts, that detects and handles AJAXed content.
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);