From: Martin Pitt Date: Sun, 2 Jul 2023 06:37:16 +0000 (+0200) Subject: Add loading via URL X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;ds=inline;p=chordpro-web.git Add loading via URL --- diff --git a/chordpro-web.js b/chordpro-web.js index 45f800d..a37c833 100644 --- a/chordpro-web.js +++ b/chordpro-web.js @@ -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();