I think you can recreate the element that makes up the name of the song, and get its width in pixels. If your width is greater than the width of your container, you can resolve to create a <marquee>
.
To apply the re-creation of the element simply remove one of the existing .som
, and then pull the new element to the same container.
Note: The width of the span is being broken by the container itself, preventing the comparison of its width with that of its container. Some style would solve that.
Remembering that you do not need to re-create the marquee / span element.
Example how to pre-store marquee / span:
var span = document.createElement('span');
span.className = 'som';
/* Desaplica a largura fixa de 300px: */
span.width = 'auto';
var marquee = document.createElement('marquee');
marquee.className = 'som';
Example of updating the song name:
/* Remove o marquee por precaução: */
marquee.remove();
var nomeDaMúsica = 'Nome da música';
var container = document.querySelector(
'.player .caixa-status'
);
span.textContent = nomeDaMúsica;
// Para obter a largura renderizada do span vai ser necessário
// adicioná-lo ao container (obs.: se ele já estiver adicionado
// ele não duplica, de acordo com meu navegador):
container.appendChild(span);
var largura = som.offsetWidth;
if (largura > container.offWidth) {
/* Transforma o elemento span em marquee: */
span.remove();
marquee.textContent = nomeDaMúsica;
container.appendChild(marquee);
}