mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-07 08:07:18 +02:00
Only init Settings UI when necessary
This commit is contained in:
parent
351cb0204b
commit
1a2fb6c89a
@ -10367,59 +10367,17 @@ function interceptHttpRequests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function injectSettingsButton($parent) {
|
function setupSettingsUi() {
|
||||||
if (!$parent) {
|
// Avoid rendering the Settings multiple times
|
||||||
|
if (document.querySelector('.bx-settings-container')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PREF_PREFERRED_REGION = getPreferredServerRegion();
|
const PREF_PREFERRED_REGION = getPreferredServerRegion();
|
||||||
const PREF_LATEST_VERSION = getPref(Preferences.LATEST_VERSION);
|
const PREF_LATEST_VERSION = getPref(Preferences.LATEST_VERSION);
|
||||||
|
|
||||||
const $headerFragment = document.createDocumentFragment();
|
|
||||||
let $reloadBtnWrapper;
|
let $reloadBtnWrapper;
|
||||||
|
|
||||||
// Remote Play button
|
|
||||||
if (getPref(Preferences.REMOTE_PLAY_ENABLED)) {
|
|
||||||
const $remotePlayBtn = createButton({
|
|
||||||
classes: ['bx-remote-play-button'],
|
|
||||||
icon: Icon.REMOTE_PLAY,
|
|
||||||
title: t('remote-play'),
|
|
||||||
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE,
|
|
||||||
onClick: e => {
|
|
||||||
RemotePlay.togglePopup();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
$headerFragment.appendChild($remotePlayBtn);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Setup Settings button
|
|
||||||
const $settingsBtn = createButton({
|
|
||||||
classes: ['bx-settings-button'],
|
|
||||||
label: PREF_PREFERRED_REGION,
|
|
||||||
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE | ButtonStyle.FULL_HEIGHT,
|
|
||||||
onClick: e => {
|
|
||||||
const $settings = document.querySelector('.bx-settings-container');
|
|
||||||
$settings.classList.toggle('bx-gone');
|
|
||||||
window.scrollTo(0, 0);
|
|
||||||
document.activeElement && document.activeElement.blur();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Show new update status
|
|
||||||
if (PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) {
|
|
||||||
$settingsBtn.setAttribute('data-update-available', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the Settings button to the web page
|
|
||||||
$headerFragment.appendChild($settingsBtn);
|
|
||||||
$parent.appendChild($headerFragment);
|
|
||||||
|
|
||||||
// Avoid rendering the Settings multiple times
|
|
||||||
if (document.querySelector('.bx-settings-container')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup Settings UI
|
// Setup Settings UI
|
||||||
const $container = CE('div', {
|
const $container = CE('div', {
|
||||||
'class': 'bx-settings-container bx-gone',
|
'class': 'bx-settings-container bx-gone',
|
||||||
@ -10713,6 +10671,57 @@ function injectSettingsButton($parent) {
|
|||||||
$pageContent.parentNode.insertBefore($container, $pageContent);
|
$pageContent.parentNode.insertBefore($container, $pageContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function injectSettingsButton($parent) {
|
||||||
|
if (!$parent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PREF_PREFERRED_REGION = getPreferredServerRegion();
|
||||||
|
const PREF_LATEST_VERSION = getPref(Preferences.LATEST_VERSION);
|
||||||
|
|
||||||
|
const $headerFragment = document.createDocumentFragment();
|
||||||
|
|
||||||
|
// Remote Play button
|
||||||
|
if (getPref(Preferences.REMOTE_PLAY_ENABLED)) {
|
||||||
|
const $remotePlayBtn = createButton({
|
||||||
|
classes: ['bx-remote-play-button'],
|
||||||
|
icon: Icon.REMOTE_PLAY,
|
||||||
|
title: t('remote-play'),
|
||||||
|
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE,
|
||||||
|
onClick: e => {
|
||||||
|
RemotePlay.togglePopup();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
$headerFragment.appendChild($remotePlayBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Setup Settings button
|
||||||
|
const $settingsBtn = createButton({
|
||||||
|
classes: ['bx-settings-button'],
|
||||||
|
label: PREF_PREFERRED_REGION,
|
||||||
|
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE | ButtonStyle.FULL_HEIGHT,
|
||||||
|
onClick: e => {
|
||||||
|
setupSettingsUi();
|
||||||
|
|
||||||
|
const $settings = document.querySelector('.bx-settings-container');
|
||||||
|
$settings.classList.toggle('bx-gone');
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
document.activeElement && document.activeElement.blur();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Show new update status
|
||||||
|
if (PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) {
|
||||||
|
$settingsBtn.setAttribute('data-update-available', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the Settings button to the web page
|
||||||
|
$headerFragment.appendChild($settingsBtn);
|
||||||
|
$parent.appendChild($headerFragment);
|
||||||
|
}
|
||||||
|
|
||||||
function getVideoPlayerFilterStyle() {
|
function getVideoPlayerFilterStyle() {
|
||||||
const filters = [];
|
const filters = [];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user