From 3079b86b80beab013e342ebac6e9de767f7ec4cb Mon Sep 17 00:00:00 2001 From: Eva Date: Fri, 19 May 2023 13:13:45 +0200 Subject: [PATCH] client/posts: use ruffle polyfill for swf playback in modern browsers --- client/html/index.htm | 1 + client/js/main.js | 15 +++++++++++++++ client/js/views/settings_view.js | 1 + 3 files changed, 17 insertions(+) diff --git a/client/html/index.htm b/client/html/index.htm index 00728903..781b4521 100644 --- a/client/html/index.htm +++ b/client/html/index.htm @@ -28,5 +28,6 @@
+ diff --git a/client/js/main.js b/client/js/main.js index c5bdc537..cb37fb42 100644 --- a/client/js/main.js +++ b/client/js/main.js @@ -42,6 +42,17 @@ const pools = require("./pools.js"); const api = require("./api.js"); const settings = require("./models/settings.js"); +const rgb2hex = (rgb) => `#${rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/).slice(1).map(n => parseInt(n, 10).toString(16).padStart(2, '0')).join('')}` + +window.RufflePlayer = window.RufflePlayer || {}; +window.RufflePlayer.config = { + "polyfills": true, + "autoplay": "off", + "backgroundColor": rgb2hex(window.getComputedStyle(document.body).backgroundColor), + "warnOnUnsupportedContent": false, + "splashScreen": false, +}; + Promise.resolve() .then(() => api.fetchConfig()) .then( @@ -99,6 +110,10 @@ Promise.resolve() if (settings.get().darkTheme) { document.body.classList.add("darktheme"); } + + window.RufflePlayer.config.autoplay = settings.get().autoplayVideos ? "auto" : "off" + const topNav = document.getElementById("top-navigation") + if (topNav) window.RufflePlayer.config.backgroundColor = rgb2hex(window.getComputedStyle(topNav).backgroundColor) }) .then(() => api.loginFromCookies()) .then( diff --git a/client/js/views/settings_view.js b/client/js/views/settings_view.js index b7f69d55..0a4e34dc 100644 --- a/client/js/views/settings_view.js +++ b/client/js/views/settings_view.js @@ -30,6 +30,7 @@ class SettingsView extends events.EventTarget { _evtSubmit(e) { e.preventDefault(); + window.RufflePlayer.config.autoplay = this._find("autoplay-videos").checked ? "auto" : "off" this.dispatchEvent( new CustomEvent("submit", { detail: {