50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
(function () {
|
|
function getAuthToken() {
|
|
try {
|
|
var creds = JSON.parse(localStorage.getItem('jellyfin_credentials'));
|
|
var server = creds && creds.Servers && creds.Servers[0];
|
|
return (server && server.AccessToken) || null;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function addButton() {
|
|
if (document.getElementById('jellylms-remote-btn')) {
|
|
return;
|
|
}
|
|
|
|
var btn = document.createElement('a');
|
|
btn.id = 'jellylms-remote-btn';
|
|
btn.href = '/JellyLms/RemoteControl';
|
|
btn.title = 'Multi-room Remote';
|
|
btn.textContent = '🔊';
|
|
btn.style.cssText = 'position:fixed;bottom:20px;right:20px;width:48px;height:48px;' +
|
|
'border-radius:50%;background:#00a4dc;color:#fff;display:flex;' +
|
|
'align-items:center;justify-content:center;font-size:22px;' +
|
|
'text-decoration:none;z-index:99999;box-shadow:0 2px 8px rgba(0,0,0,0.5);';
|
|
document.body.appendChild(btn);
|
|
}
|
|
|
|
function init() {
|
|
var token = getAuthToken();
|
|
if (!token) {
|
|
return;
|
|
}
|
|
|
|
fetch('/JellyLms/RemoteControl/Access', { headers: { 'X-Emby-Token': token } })
|
|
.then(function (resp) {
|
|
if (resp.ok) {
|
|
addButton();
|
|
}
|
|
})
|
|
.catch(function () {});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
})();
|