Created
October 27, 2013 12:03
-
-
Save kotas/7181047 to your computer and use it in GitHub Desktop.
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
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