diff --git a/src/components/PlaylistPage.vue b/src/components/PlaylistPage.vue index 67e5e9a7..94543989 100644 --- a/src/components/PlaylistPage.vue +++ b/src/components/PlaylistPage.vue @@ -18,6 +18,9 @@ + @@ -133,6 +136,13 @@ export default { } else alert(resp.error); }); }, + downloadPlaylistAsTxt() { + var data = ""; + this.playlist.relatedStreams.forEach(element => { + data += "https://piped.kavin.rocks" + element.url + "\n"; + }); + this.download(data, this.playlist.name + ".txt", "text/plain"); + }, }, }; diff --git a/src/components/SubscriptionsPage.vue b/src/components/SubscriptionsPage.vue index 50c452a7..592efdf2 100644 --- a/src/components/SubscriptionsPage.vue +++ b/src/components/SubscriptionsPage.vue @@ -97,14 +97,7 @@ export default { subscriptions: subscriptions, }); - var file = new Blob([json], { type: "application/json" }); - - const elem = document.createElement("a"); - - elem.href = URL.createObjectURL(file); - elem.download = "subscriptions.json"; - elem.click(); - elem.remove(); + this.download(json, "subscriptions.json", "application/json"); }, }, }; diff --git a/src/locales/en.json b/src/locales/en.json index 64f403b3..229cacb5 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -88,7 +88,8 @@ "different_auth_instance": "Use a different instance for authentication", "instance_auth_selection": "Autentication Instance Selection", "clone_playlist": "Clone Playlist", - "clone_playlist_success": "Successfully cloned!" + "clone_playlist_success": "Successfully cloned!", + "download_as_txt": "Download as .txt" }, "comment": { "pinned_by": "Pinned by", diff --git a/src/main.js b/src/main.js index ed0f4fee..6a631ef6 100644 --- a/src/main.js +++ b/src/main.js @@ -220,6 +220,17 @@ const mixin = { const localSubscriptions = this.getLocalSubscriptions() ?? []; return localSubscriptions.join(","); }, + /* generate a temporary file and ask the user to download it */ + download(text, filename, type) { + var file = new Blob([text], { type: type }); + + const elem = document.createElement("a"); + + elem.href = URL.createObjectURL(file); + elem.download = filename; + elem.click(); + elem.remove(); + }, }, computed: { theme() {