The UG header may be rendered dynamically now and not on page load, so set a timer to check when it is available

This commit is contained in:
Fabio Manganiello 2023-01-18 20:12:40 +01:00
parent 35d50a7b98
commit e7284e3c5d

14
ug.js
View file

@ -20,6 +20,8 @@
*/ */
let downloadButtonPoll = null
function getTabs() { function getTabs() {
let artist = null; let artist = null;
return [ return [
@ -57,7 +59,12 @@ function addDownloadButton() {
if (!header) if (!header)
return; return;
if (header.querySelector('button.__download-btn')) if (downloadButtonPoll) {
clearInterval(downloadButtonPoll);
downloadButtonPoll = null;
}
if (header.querySelector('a.__download-btn'))
return; return;
const tabs = 'data:application/json,' + encodeURIComponent(JSON.stringify(getTabs())); const tabs = 'data:application/json,' + encodeURIComponent(JSON.stringify(getTabs()));
@ -66,8 +73,11 @@ function addDownloadButton() {
btn.innerHTML = 'Download tabs as JSON'; btn.innerHTML = 'Download tabs as JSON';
btn.style = 'color: #ffc600; text-decoration: underline'; btn.style = 'color: #ffc600; text-decoration: underline';
btn.href = tabs; btn.href = tabs;
btn.className = '__download-btn';
header.querySelector('section').appendChild(btn); header.querySelector('section').appendChild(btn);
} }
window.onload = addDownloadButton; window.onload = () => {
downloadButtonPoll = setInterval(addDownloadButton, 1000);
}