blob: 00bc556e089a4c379c43c41fb15d287b2eb0bbbf [file] [log] [blame]
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02001export function injectStylesheet(stylesheetName, attributes = {}) {
avm999634c1a6792020-08-31 21:30:42 +02002 var link = document.createElement('link');
3 link.setAttribute('rel', 'stylesheet');
4 link.setAttribute('href', stylesheetName);
avm999630bc113a2020-09-07 13:02:11 +02005 if ('media' in attributes) link.setAttribute('media', attributes['media']);
avm999634c1a6792020-08-31 21:30:42 +02006 document.head.appendChild(link);
7}
8
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02009export function injectStyles(css) {
avm999634c1a6792020-08-31 21:30:42 +020010 injectStylesheet('data:text/css;charset=UTF-8,' + encodeURIComponent(css));
11}
12
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020013export function injectScript(scriptName) {
avm999634c1a6792020-08-31 21:30:42 +020014 var script = document.createElement('script');
15 script.src = scriptName;
16 document.head.appendChild(script);
17}