X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Froot-helpers%2Futils.ts;h=af94ed6cac82f0d3039e7609a2482e663417fae1;hb=d73786b5798fcfdfbe7e42919a8cde72de97feba;hp=e32187ddb0d5b9e5a8cbfe9375bdcc62252d2e98;hpb=afff310e50f2fa8419bb4242470cbde46ab54463;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/root-helpers/utils.ts b/client/src/root-helpers/utils.ts index e32187ddb..af94ed6ca 100644 --- a/client/src/root-helpers/utils.ts +++ b/client/src/root-helpers/utils.ts @@ -1,14 +1,3 @@ -import { environment } from '../environments/environment' - -function objectToUrlEncoded (obj: any) { - const str: string[] = [] - for (const key of Object.keys(obj)) { - str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])) - } - - return str.join('&') -} - function copyToClipboard (text: string) { const el = document.createElement('textarea') el.value = text @@ -21,50 +10,13 @@ function copyToClipboard (text: string) { document.body.removeChild(el) } -// Thanks: https://github.com/uupaa/dynamic-import-polyfill -function importModule (path: string) { - return new Promise((resolve, reject) => { - const vector = '$importModule$' + Math.random().toString(32).slice(2) - const script = document.createElement('script') - - const destructor = () => { - delete window[ vector ] - script.onerror = null - script.onload = null - script.remove() - URL.revokeObjectURL(script.src) - script.src = '' - } - - script.defer = true - script.type = 'module' - - script.onerror = () => { - reject(new Error(`Failed to import: ${path}`)) - destructor() - } - script.onload = () => { - resolve(window[ vector ]) - destructor() - } - const absURL = (environment.apiUrl || window.location.origin) + path - const loader = `import * as m from "${absURL}"; window.${vector} = m;` // export Module - const blob = new Blob([ loader ], { type: 'text/javascript' }) - script.src = URL.createObjectURL(blob) - - document.head.appendChild(script) - }) -} - function wait (ms: number) { - return new Promise(res => { + return new Promise(res => { setTimeout(() => res(), ms) }) } export { copyToClipboard, - importModule, - objectToUrlEncoded, wait }