From 8071e18c65d0a0ccfad708e7010ed6dfacb40971 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 11 Mar 2018 03:00:06 +0100 Subject: [PATCH] Added play in background button --- pages/soundtrack/soundtrack.pixy | 6 ++++++ scripts/Actions.ts | 1 + scripts/Actions/Audio.ts | 13 +++++++++++++ scripts/AnimeNotifier.ts | 1 + 4 files changed, 21 insertions(+) create mode 100644 scripts/Actions/Audio.ts diff --git a/pages/soundtrack/soundtrack.pixy b/pages/soundtrack/soundtrack.pixy index 0beb9b26..11f44b09 100644 --- a/pages/soundtrack/soundtrack.pixy +++ b/pages/soundtrack/soundtrack.pixy @@ -13,6 +13,12 @@ component Track(track *arn.SoundTrack, user *arn.User) h3.widget-title= media.Service .sound-track-media.video-container iframe.lazy.video(data-src=media.EmbedLink(), allowfullscreen="allowfullscreen") + + if user != nil && media.Service == "Youtube" && (user.Role == "admin" || user.Role == "editor") && track.File != "" + .buttons + button.action(data-action="playAudio", data-trigger="click", data-src="/audio/" + track.File) + Icon("play") + span Play in background .widget.mountable h3.widget-title Anime diff --git a/scripts/Actions.ts b/scripts/Actions.ts index ed7cb936..3e20ba96 100644 --- a/scripts/Actions.ts +++ b/scripts/Actions.ts @@ -1,3 +1,4 @@ +export * from "./Actions/Audio" export * from "./Actions/AnimeList" export * from "./Actions/Diff" export * from "./Actions/Editor" diff --git a/scripts/Actions/Audio.ts b/scripts/Actions/Audio.ts new file mode 100644 index 00000000..7f90de38 --- /dev/null +++ b/scripts/Actions/Audio.ts @@ -0,0 +1,13 @@ +import { AnimeNotifier } from "../AnimeNotifier" + +// Play audio file +export function playAudio(arn: AnimeNotifier, button: HTMLButtonElement) { + if(!arn.audio) { + arn.audio = document.createElement("audio") as HTMLAudioElement + let source = document.createElement("source") as HTMLSourceElement + source.src = button.dataset.src + arn.audio.appendChild(source) + } + + arn.audio.play() +} \ No newline at end of file diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 26aa69f3..ce6f340a 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -32,6 +32,7 @@ export class AnimeNotifier { mainPageLoaded: boolean isLoading: boolean lastReloadContentPath: string + audio: HTMLAudioElement elementFound: MutationQueue elementNotFound: MutationQueue