From fa82f4c50ddf6daca6f0f328c854ac49e37f4c1f Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Sun, 22 May 2022 08:54:04 -0400 Subject: [PATCH] iOS Legacy Mode + Responsive Text Scaling @mcguirepr89 Try this out on your iOS device(s) and let me know how/if it works! --- scripts/spectrogram.php | 46 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/scripts/spectrogram.php b/scripts/spectrogram.php index c710bd7..8b61cc0 100644 --- a/scripts/spectrogram.php +++ b/scripts/spectrogram.php @@ -7,6 +7,29 @@ var started = null; var player = null; const ctx = null; window.onload = function(){ + // if user agent includes iPhone or Mac, AND is not chrome, use legacy mode + if( (window.navigator.userAgent.includes("iPhone") || window.navigator.userAgent.includes("Mac")) && !window.navigator.userAgent.includes("CriOS")) { + document.getElementById("spectrogramimage").style.display=""; + document.body.querySelector('canvas').remove(); + document.getElementById('player').remove(); + document.body.querySelector('h1').remove(); + + + // every $refresh seconds, this loop will run and refresh the spectrogram image + window.setInterval(function(){ + document.getElementById("spectrogramimage").src = "/spectrogram.png?nocache="+Date.now(); + }, *1000); + } else { + document.getElementById("spectrogramimage").remove(); + var audioelement = window.parent.document.getElementsByTagName("audio")[0]; if (typeof(audioelement) != 'undefined') { @@ -16,15 +39,27 @@ window.onload = function(){ } else { player = document.getElementById('player'); } + player.play(); if (started) return; - started = true; - initialize(); + started = true; + initialize(); + } }; +function fitTextOnCanvas(text,fontface,yPosition){ + var fontsize=300; + do{ + fontsize--; + CTX.font=fontsize+"px "+fontface; + }while(CTX.measureText(text).width>document.body.querySelector('canvas').width) + CTX.font = CTX.font=(fontsize*0.35)+"px "+fontface; + CTX.fillText(text,document.body.querySelector('canvas').width - (document.body.querySelector('canvas').width * 0.50),yPosition); +} + function applyText(text) { CTX.fillStyle = 'white'; CTX.font = '25px Roboto Flex'; - CTX.fillText(text, document.body.querySelector('canvas').scrollWidth - (document.body.querySelector('canvas').scrollWidth * 0.20), document.body.querySelector('canvas').scrollHeight * 0.35); + fitTextOnCanvas(text,"Roboto Flex",document.body.querySelector('canvas').scrollHeight * 0.35) CTX.fillStyle = 'hsl(280, 100%, 10%)'; } @@ -46,7 +81,7 @@ function loadDetectionIfNewExists() { window.setInterval(function(){ loadDetectionIfNewExists(); -}, 5000); +}, 2500); function initialize() { document.body.querySelector('h1').remove(); @@ -118,7 +153,8 @@ h1 { } + - +

Loading...