Skip to content

Instantly share code, notes, and snippets.

@kotas
Created October 27, 2013 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotas/7181047 to your computer and use it in GitHub Desktop.
Save kotas/7181047 to your computer and use it in GitHub Desktop.
module Resource {
export declare var html: {
[name: string]: string;
};
export declare var css: {
[name: string]: string;
};
var loadedCSS: { [name: string]: boolean } = {};
export function load(name: string): JQuery {
if (typeof html[name] === 'undefined') {
throw new Error('No such template');
}
if (typeof css[name] !== 'undefined' && !loadedCSS[name]) {
addCSS(css[name]);
loadedCSS[name] = true;
}
return $(html[name]);
}
function addCSS(css: string) {
if (typeof GM_addStyle !== 'undefined') {
GM_addStyle(css);
} else {
$('<style />').attr('type', 'text/css').html(css).appendTo($('head').eq(0));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment