avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 1 | 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 | |
| 9 | function injectStyles(css) { |
| 10 | injectStylesheet('data:text/css;charset=UTF-8,' + encodeURIComponent(css)); |
| 11 | } |
| 12 | |
| 13 | function injectScript(scriptName) { |
| 14 | var script = document.createElement('script'); |
| 15 | script.src = scriptName; |
| 16 | document.head.appendChild(script); |
| 17 | } |
avm99963 | 943b849 | 2020-08-31 23:40:43 +0200 | [diff] [blame] | 18 | |
| 19 | function escapeUsername(username) { |
| 20 | var quoteRegex = /"/g; |
| 21 | var commentRegex = /<!---->/g; |
| 22 | return username.replace(quoteRegex, '\\"').replace(commentRegex, ''); |
| 23 | } |