From 15b93060c76ee4d59eb8ef90f6e1f8dea4c34ac9 Mon Sep 17 00:00:00 2001 From: guidocella Date: Sat, 16 Dec 2017 19:56:53 +0100 Subject: Add option to play audio automatically --- ext/fg/js/float.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ext/fg/js/float.js') diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index ff50483d..1f08702d 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -20,6 +20,8 @@ class DisplayFloat extends Display { constructor() { super($('#spinner'), $('#definitions')); + this.autoPlayAudioTimer = null; + $(window).on('message', utilAsync(this.onMessage.bind(this))); } @@ -54,6 +56,10 @@ class DisplayFloat extends Display { this.kanjiShow(definitions, options, context); }, + clearAutoPlayTimer: () => { + this.clearAutoPlayTimer(); + }, + orphaned: () => { this.onOrphaned(); } @@ -83,6 +89,18 @@ class DisplayFloat extends Display { super.onKeyDown(e); } } + + autoPlayAudio() { + this.clearAutoPlayTimer(); + this.autoPlayAudioTimer = window.setTimeout(() => super.autoPlayAudio(), 400); + } + + clearAutoPlayTimer() { + if (this.autoPlayAudioTimer) { + window.clearTimeout(this.autoPlayAudioTimer); + this.autoPlayAudioTimer = null; + } + } } window.yomichan_display = new DisplayFloat(); -- cgit v1.2.3