1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #2618 from iwalton3/client-custom-css

Allow client custom css and disabling global server custom css.
This commit is contained in:
Bill Thornton 2021-07-30 22:34:32 -07:00 committed by GitHub
commit c4fc8e0145
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 101 additions and 14 deletions

View file

@ -36,6 +36,7 @@ import { playbackManager } from '../components/playback/playbackmanager';
import SyncPlayNoActivePlayer from '../components/syncPlay/ui/players/NoActivePlayer';
import SyncPlayHtmlVideoPlayer from '../components/syncPlay/ui/players/HtmlVideoPlayer';
import SyncPlayHtmlAudioPlayer from '../components/syncPlay/ui/players/HtmlAudioPlayer';
import { currentSettings } from './settings/userSettings';
// TODO: Move this elsewhere
window.getWindowLocationSearch = function(win) {
@ -173,7 +174,7 @@ function initSyncPlay() {
Events.on(ServerConnections, 'apiclientcreated', (e, newApiClient) => SyncPlay.Manager.init(newApiClient));
}
function onAppReady() {
async function onAppReady() {
console.debug('begin onAppReady');
console.debug('onAppReady: loading dependencies');
@ -216,27 +217,63 @@ function onAppReady() {
const apiClient = ServerConnections.currentApiClient();
if (apiClient) {
fetch(apiClient.getUrl('Branding/Css'))
const updateStyle = (css) => {
let style = document.querySelector('#cssBranding');
if (!style) {
// Inject the branding css as a dom element in body so it will take
// precedence over other stylesheets
style = document.createElement('style');
style.id = 'cssBranding';
document.body.appendChild(style);
}
style.textContent = css;
};
const style = fetch(apiClient.getUrl('Branding/Css'))
.then(function(response) {
if (!response.ok) {
throw new Error(response.status + ' ' + response.statusText);
}
return response.text();
})
.then(function(css) {
let style = document.querySelector('#cssBranding');
if (!style) {
// Inject the branding css as a dom element in body so it will take
// precedence over other stylesheets
style = document.createElement('style');
style.id = 'cssBranding';
document.body.appendChild(style);
}
style.textContent = css;
})
.catch(function(err) {
console.warn('Error applying custom css', err);
});
const handleStyleChange = async () => {
if (currentSettings.disableCustomCss()) {
updateStyle('');
} else {
updateStyle(await style);
}
const localCss = currentSettings.customCss();
let localStyle = document.querySelector('#localCssBranding');
if (localCss) {
if (!localStyle) {
// Inject the branding css as a dom element in body so it will take
// precedence over other stylesheets
localStyle = document.createElement('style');
localStyle.id = 'localCssBranding';
document.body.appendChild(localStyle);
}
localStyle.textContent = localCss;
} else {
if (localStyle) {
localStyle.textContent = '';
}
}
};
Events.on(ServerConnections, 'localusersignedin', handleStyleChange);
Events.on(ServerConnections, 'localusersignedout', handleStyleChange);
Events.on(currentSettings, 'change', (e, prop) => {
if (prop == 'disableCustomCss' || prop == 'customCss') {
handleStyleChange();
}
});
style.then(updateStyle);
}
}