From cf8f383e45cf4d279891b4e727bf30e91cc85919 Mon Sep 17 00:00:00 2001 From: ThinLiquid Date: Wed, 15 May 2024 17:47:00 +0100 Subject: [PATCH] Update metadata.ts --- src/metadata.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/metadata.ts b/src/metadata.ts index 0f2e965..c8cfe7d 100644 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -80,6 +80,11 @@ class Metadata { .classOn('material-symbols-sharp') .text('add') + this.download = new HTML('button') + .attr({ title: 'Download' }) + .classOn('material-symbols-sharp') + .text('download') + this.options = new HTML('div').classOn('options') this.menu = new HTML('button') .attr({ title: 'Menu' }) @@ -132,6 +137,7 @@ class Metadata { this.playPause.appendTo(this.icons) this.nextTrack.appendTo(this.icons) if (this.sdk != null) this.like.appendTo(this.icons) // Only show the like button if the SDK is available + this.download.appendTo(this.icons) this.options.appendTo(document.body) this.menu.appendTo(this.options) @@ -215,11 +221,19 @@ class Metadata { this.player.prev().catch(console.error) }) - // Register the click events for the buttons this.nextTrack.on('click', () => { this.player.next().catch(console.error) }) + this.download.on('click', () => { + var link = document.createElement("a"); + link.href = this.player.audio.src; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + delete link; + }) + // Register the click events for the like button if (this.sdk != null) { this.like.on('click', () => {