Update app.js

This commit is contained in:
Eduard Prigoana 2025-10-21 18:49:51 +03:00
parent 2c04d69edb
commit aca4aadf91

View file

@ -403,14 +403,26 @@ document.addEventListener('DOMContentLoaded', async () => {
scrobbler.disconnect();
updateLastFMUI();
}
} else {
try {
return;
}
const authWindow = window.open('', '_blank');
lastfmConnectBtn.disabled = true;
lastfmConnectBtn.textContent = 'Opening Last.fm...';
try {
const { token, url } = await scrobbler.getAuthUrl();
const authWindow = window.open(url, '_blank');
if (authWindow) {
authWindow.location.href = url;
} else {
alert('Popup blocked! Please allow popups.');
lastfmConnectBtn.textContent = 'Connect Last.fm';
lastfmConnectBtn.disabled = false;
return;
}
lastfmConnectBtn.textContent = 'Waiting for authorization...';
@ -424,6 +436,7 @@ document.addEventListener('DOMContentLoaded', async () => {
clearInterval(checkAuth);
lastfmConnectBtn.textContent = 'Connect Last.fm';
lastfmConnectBtn.disabled = false;
if (authWindow && !authWindow.closed) authWindow.close();
alert('Authorization timed out. Please try again.');
return;
}
@ -433,9 +446,7 @@ document.addEventListener('DOMContentLoaded', async () => {
if (result.success) {
clearInterval(checkAuth);
if (authWindow && !authWindow.closed) {
authWindow.close();
}
if (authWindow && !authWindow.closed) authWindow.close();
updateLastFMUI();
lastfmConnectBtn.disabled = false;
lastFMStorage.setEnabled(true);
@ -451,10 +462,11 @@ document.addEventListener('DOMContentLoaded', async () => {
alert('Failed to connect to Last.fm: ' + error.message);
lastfmConnectBtn.textContent = 'Connect Last.fm';
lastfmConnectBtn.disabled = false;
}
if (authWindow && !authWindow.closed) authWindow.close();
}
});
lastfmToggle?.addEventListener('change', (e) => {
lastFMStorage.setEnabled(e.target.checked);
});