Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 1 | export function injectStylesheet(stylesheetName, attributes = {}) { |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 2 | var link = document.createElement('link'); |
| 3 | link.setAttribute('rel', 'stylesheet'); |
| 4 | link.setAttribute('href', stylesheetName); |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 5 | if ('media' in attributes) link.setAttribute('media', attributes['media']); |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 6 | document.head.appendChild(link); |
| 7 | } |
| 8 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 9 | export function injectStyles(css) { |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 10 | injectStylesheet('data:text/css;charset=UTF-8,' + encodeURIComponent(css)); |
| 11 | } |
| 12 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 13 | export function injectScript(scriptName) { |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 14 | var script = document.createElement('script'); |
| 15 | script.src = scriptName; |
| 16 | document.head.appendChild(script); |
| 17 | } |