]> piware.de Git - chordpro-web.git/commitdiff
Add loading via URL main
authorMartin Pitt <martin@piware.de>
Sun, 2 Jul 2023 06:37:16 +0000 (08:37 +0200)
committerMartin Pitt <martin@piware.de>
Sun, 2 Jul 2023 07:08:19 +0000 (09:08 +0200)
chordpro-web.js

index 45f800dc35ca9aeea9164957ff43bae7e159fa82..a37c833a451afb11c28ccc4b9768d60a37ad13c9 100644 (file)
@@ -57,4 +57,23 @@ function renderChordpro(text) {
     render(song, el_song);
 }
 
-document.getElementById('open').addEventListener('change', async ev => renderChordpro(await ev.target.files[0].text()));
+async function main() {
+    document.getElementById('open').addEventListener('change', async ev => renderChordpro(await ev.target.files[0].text()));
+
+    const params = new URLSearchParams(document.location.search);
+    const loadURL = params.get('l');
+    if (loadURL) {
+        try {
+            const response = await fetch(loadURL);
+            if (response.ok) {
+                renderChordpro(await response.text());
+            } else {
+                console.warn('Failed to fetch', loadURL, ':', response.status, response.statusText);
+            }
+        } catch (error) {
+            console.warn('Failed to fetch', loadURL, ':', error);
+        }
+    }
+}
+
+main();