Update app.js
This commit is contained in:
parent
2c04d69edb
commit
aca4aadf91
1 changed files with 65 additions and 53 deletions
30
js/app.js
30
js/app.js
|
|
@ -397,20 +397,32 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
|
||||||
updateLastFMUI();
|
updateLastFMUI();
|
||||||
|
|
||||||
lastfmConnectBtn?.addEventListener('click', async () => {
|
lastfmConnectBtn?.addEventListener('click', async () => {
|
||||||
if (scrobbler.isAuthenticated()) {
|
if (scrobbler.isAuthenticated()) {
|
||||||
if (confirm('Disconnect from Last.fm?')) {
|
if (confirm('Disconnect from Last.fm?')) {
|
||||||
scrobbler.disconnect();
|
scrobbler.disconnect();
|
||||||
updateLastFMUI();
|
updateLastFMUI();
|
||||||
}
|
}
|
||||||
} else {
|
return;
|
||||||
try {
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const authWindow = window.open('', '_blank');
|
||||||
|
|
||||||
lastfmConnectBtn.disabled = true;
|
lastfmConnectBtn.disabled = true;
|
||||||
lastfmConnectBtn.textContent = 'Opening Last.fm...';
|
lastfmConnectBtn.textContent = 'Opening Last.fm...';
|
||||||
|
|
||||||
|
try {
|
||||||
const { token, url } = await scrobbler.getAuthUrl();
|
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...';
|
lastfmConnectBtn.textContent = 'Waiting for authorization...';
|
||||||
|
|
||||||
|
|
@ -424,6 +436,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
clearInterval(checkAuth);
|
clearInterval(checkAuth);
|
||||||
lastfmConnectBtn.textContent = 'Connect Last.fm';
|
lastfmConnectBtn.textContent = 'Connect Last.fm';
|
||||||
lastfmConnectBtn.disabled = false;
|
lastfmConnectBtn.disabled = false;
|
||||||
|
if (authWindow && !authWindow.closed) authWindow.close();
|
||||||
alert('Authorization timed out. Please try again.');
|
alert('Authorization timed out. Please try again.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -433,9 +446,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
clearInterval(checkAuth);
|
clearInterval(checkAuth);
|
||||||
if (authWindow && !authWindow.closed) {
|
if (authWindow && !authWindow.closed) authWindow.close();
|
||||||
authWindow.close();
|
|
||||||
}
|
|
||||||
updateLastFMUI();
|
updateLastFMUI();
|
||||||
lastfmConnectBtn.disabled = false;
|
lastfmConnectBtn.disabled = false;
|
||||||
lastFMStorage.setEnabled(true);
|
lastFMStorage.setEnabled(true);
|
||||||
|
|
@ -451,9 +462,10 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
alert('Failed to connect to Last.fm: ' + error.message);
|
alert('Failed to connect to Last.fm: ' + error.message);
|
||||||
lastfmConnectBtn.textContent = 'Connect Last.fm';
|
lastfmConnectBtn.textContent = 'Connect Last.fm';
|
||||||
lastfmConnectBtn.disabled = false;
|
lastfmConnectBtn.disabled = false;
|
||||||
|
if (authWindow && !authWindow.closed) authWindow.close();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
lastfmToggle?.addEventListener('change', (e) => {
|
lastfmToggle?.addEventListener('change', (e) => {
|
||||||
lastFMStorage.setEnabled(e.target.checked);
|
lastFMStorage.setEnabled(e.target.checked);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue