sjehuda / Flash Player (ruffle)

// ==UserScript==
// @name        Flash Player (ruffle)
// @namespace   i2p.schimon.ruffle
// @description Play flash (.swf) files
// @homepageURL https://openuserjs.org/scripts/sjehuda/Flash_Player_(ruffle)
// @supportURL  https://openuserjs.org/scripts/sjehuda/Flash_Player_(ruffle)/issues
// @updateURL   https://openuserjs.org/meta/sjehuda/Flash_Player_(ruffle).meta.js
// @downloadURL https://openuserjs.org/install/sjehuda/Flash_Player_(ruffle).user.js
// @copyright   2024, Schimon Jehudah (http://schimon.i2p)
// @license     MIT; https://opensource.org/licenses/MIT
// @match       file:///*
// @match       *://*/*
// @version     24.04
// @grant       none
// @icon        data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7imqE8L3RleHQ+PC9zdmc+Cg==
// ==/UserScript==

// Please help  https://openuserjs.org/garage/Help_making_ruffle_to_work
// @require     https://unpkg.com/@ruffle-rs/ruffle/ruffle.js

function activateRuffle() {

  // The @require directive will automatically load Ruffle, so no further action is needed.
  'use strict';

  // The following code is used as a backup system.
  let ruffleScript = document.createElement('script');

  // Use the CDN version of Ruffle
  ruffleScript.src = 'https://unpkg.com/@ruffle-rs/ruffle';

  document.head.appendChild(ruffleScript);

};

function infoBar() {
  let namespace = 'i2p-schimon-ruffle';
  let bar = document.createElement(namespace);
  document.body.append(bar);
  bar.innerHTML = '⚡ Activate Ruffle Flash Player</b>';
  bar.title = 'Flash elements have been detected on this page. Click this bar to activate Ruffle player.';
  bar.id = namespace;
  bar.style.backgroundColor = '#37528c';
  bar.style.color = '#ffad33';
  bar.style.fontFamily = 'system-ui';
  bar.style.fontSize = 'larger';
  bar.style.fontWeight = 'bold';
  bar.style.right = 0;
  bar.style.left = 0;
  bar.style.top = 0;
  bar.style.zIndex = 10000000000;
  bar.style.padding = '6px'; //13px //15px //11px //9px //3px //1px
  bar.style.position = 'fixed';
  bar.style.textAlign = 'center'; // justify
  bar.style.direction = 'ltr';
  bar.style.userSelect = 'none';
  // set bar behaviour
  bar.onclick = () => {
    bar.style.display = 'none';
    activateRuffle();
  };
}

(function() {

  if (document.querySelector('embed[src$=".swf"]')) {
    infoBar();
  }

})();