mirror of
https://github.com/BlackLight/ultimate-guitar-mytabs.git
synced 2024-11-27 13:45:12 +01:00
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:
parent
35d50a7b98
commit
e7284e3c5d
1 changed files with 12 additions and 2 deletions
14
ug.js
14
ug.js
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue