From 5b35595fea62e9019940bcfe32018fa4bcb706ef Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 16 May 2024 20:16:32 +0000 Subject: [PATCH] Added option to automatically play media upon embed. --- src/mami.js/main.js | 1 + src/mami.js/parsing.js | 15 ++++++++++++--- src/mami.js/ui/settings.jsx | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/mami.js/main.js b/src/mami.js/main.js index cb88da8..625ab22 100644 --- a/src/mami.js/main.js +++ b/src/mami.js/main.js @@ -94,6 +94,7 @@ window.Umi = { UI: {} }; settings.define('expandTextBox').default(false).create(); settings.define('eepromAutoInsert').default(true).create(); settings.define('autoEmbedV1').default(false).create(); + settings.define('autoEmbedPlay').default(false).create(); settings.define('soundEnable').default(true).critical().create(); settings.define('soundPack').default('').create(); settings.define('soundVolume').default(80).min(0).max(100).create(); diff --git a/src/mami.js/parsing.js b/src/mami.js/parsing.js index 755b871..eabc82b 100644 --- a/src/mami.js/parsing.js +++ b/src/mami.js/parsing.js @@ -262,7 +262,8 @@ Umi.Parsing = (function() { element.dataset.embed = '1'; element.textContent = 'Remove'; container.textContent = ''; - container.appendChild($e({ + + let media = $e({ tag: 'audio', attrs: { src: url, @@ -270,9 +271,13 @@ Umi.Parsing = (function() { onloadedmetadata: () => { if(mami.settings.get('autoScroll')) container.scrollIntoView({ inline: 'end' }); + if(mami.settings.get('autoEmbedPlay')) + media.play(); }, }, - })); + }); + + container.appendChild(media); } }; const toggleVideo = function(element) { @@ -300,7 +305,7 @@ Umi.Parsing = (function() { element.dataset.embed = '1'; element.textContent = 'Remove'; - let html = $e({ + let media = $e({ tag: 'video', attrs: { src: url, @@ -312,10 +317,14 @@ Umi.Parsing = (function() { onloadedmetadata: () => { if(mami.settings.get('autoScroll')) container.scrollIntoView({ inline: 'end' }); + if(mami.settings.get('autoEmbedPlay')) + media.play(); }, }, }); + let html = media; + if(mami.settings.get('motivationalVideos')) html = motivFrame( extractMotiv(element), diff --git a/src/mami.js/ui/settings.jsx b/src/mami.js/ui/settings.jsx index fc5d643..98f8904 100644 --- a/src/mami.js/ui/settings.jsx +++ b/src/mami.js/ui/settings.jsx @@ -74,6 +74,11 @@ Umi.UI.Settings = (function() { title: 'Auto-embed media', type: 'checkbox', }, + { + name: 'autoEmbedPlay', + title: 'Auto-play media', + type: 'checkbox', + }, ], }, {