mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-07-04 13:21:43 +02:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
2fcf14c5b9 | |||
c1af19072d | |||
5dc6f0c2f6 | |||
3ba9565c3e | |||
2d6c56e25c | |||
95d5fb8ed7 | |||
7dfe61f4ca | |||
3f66c1298e | |||
6ab24e9231 |
2
dist/better-xcloud.meta.js
vendored
2
dist/better-xcloud.meta.js
vendored
@ -1,5 +1,5 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Better xCloud
|
// @name Better xCloud
|
||||||
// @namespace https://github.com/redphx
|
// @namespace https://github.com/redphx
|
||||||
// @version 5.5.2
|
// @version 5.5.3
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
415
dist/better-xcloud.user.js
vendored
415
dist/better-xcloud.user.js
vendored
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Better xCloud
|
// @name Better xCloud
|
||||||
// @namespace https://github.com/redphx
|
// @namespace https://github.com/redphx
|
||||||
// @version 5.5.3-beta
|
// @version 5.5.4-beta
|
||||||
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||||
// @author redphx
|
// @author redphx
|
||||||
// @license MIT
|
// @license MIT
|
||||||
@ -120,7 +120,7 @@ function deepClone(obj) {
|
|||||||
return {};
|
return {};
|
||||||
return JSON.parse(JSON.stringify(obj));
|
return JSON.parse(JSON.stringify(obj));
|
||||||
}
|
}
|
||||||
var SCRIPT_VERSION = "5.5.3-beta", AppInterface = window.AppInterface;
|
var SCRIPT_VERSION = "5.5.4-beta", AppInterface = window.AppInterface;
|
||||||
UserAgent.init();
|
UserAgent.init();
|
||||||
var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = {
|
var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = {
|
||||||
supportedRegion: !0,
|
supportedRegion: !0,
|
||||||
@ -813,6 +813,79 @@ class StreamStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BaseSettingsStore {
|
||||||
|
storage;
|
||||||
|
storageKey;
|
||||||
|
_settings;
|
||||||
|
definitions;
|
||||||
|
constructor(storageKey, definitions) {
|
||||||
|
this.storage = window.localStorage, this.storageKey = storageKey;
|
||||||
|
for (let settingId in definitions) {
|
||||||
|
const setting = definitions[settingId];
|
||||||
|
setting.ready && setting.ready.call(this, setting);
|
||||||
|
}
|
||||||
|
this.definitions = definitions, this._settings = null;
|
||||||
|
}
|
||||||
|
get settings() {
|
||||||
|
if (this._settings)
|
||||||
|
return this._settings;
|
||||||
|
const settings = JSON.parse(this.storage.getItem(this.storageKey) || "{}");
|
||||||
|
return this._settings = settings, settings;
|
||||||
|
}
|
||||||
|
getDefinition(key) {
|
||||||
|
if (!this.definitions[key]) {
|
||||||
|
const error = "Request invalid definition: " + key;
|
||||||
|
throw alert(error), Error(error);
|
||||||
|
}
|
||||||
|
return this.definitions[key];
|
||||||
|
}
|
||||||
|
getSetting(key) {
|
||||||
|
if (typeof key === "undefined") {
|
||||||
|
debugger;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.definitions[key].unsupported)
|
||||||
|
return this.definitions[key].default;
|
||||||
|
if (!(key in this.settings))
|
||||||
|
this.settings[key] = this.validateValue(key, null);
|
||||||
|
return this.settings[key];
|
||||||
|
}
|
||||||
|
setSetting(key, value, emitEvent = !1) {
|
||||||
|
return value = this.validateValue(key, value), this.settings[key] = value, this.saveSettings(), emitEvent && BxEvent.dispatch(window, BxEvent.SETTINGS_CHANGED, {
|
||||||
|
storageKey: this.storageKey,
|
||||||
|
settingKey: key,
|
||||||
|
settingValue: value
|
||||||
|
}), value;
|
||||||
|
}
|
||||||
|
saveSettings() {
|
||||||
|
this.storage.setItem(this.storageKey, JSON.stringify(this.settings));
|
||||||
|
}
|
||||||
|
validateValue(key, value) {
|
||||||
|
const def = this.definitions[key];
|
||||||
|
if (!def)
|
||||||
|
return value;
|
||||||
|
if (typeof value === "undefined" || value === null)
|
||||||
|
value = def.default;
|
||||||
|
if ("min" in def)
|
||||||
|
value = Math.max(def.min, value);
|
||||||
|
if ("max" in def)
|
||||||
|
value = Math.min(def.max, value);
|
||||||
|
if ("options" in def && !(value in def.options))
|
||||||
|
value = def.default;
|
||||||
|
else if ("multipleOptions" in def) {
|
||||||
|
if (value.length) {
|
||||||
|
const validOptions = Object.keys(def.multipleOptions);
|
||||||
|
value.forEach((item2, idx) => {
|
||||||
|
validOptions.indexOf(item2) === -1 && value.splice(idx, 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!value.length)
|
||||||
|
value = def.default;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SettingElement {
|
class SettingElement {
|
||||||
static #renderOptions(key, setting, currentValue, onChange) {
|
static #renderOptions(key, setting, currentValue, onChange) {
|
||||||
const $control = CE("select", {
|
const $control = CE("select", {
|
||||||
@ -985,7 +1058,9 @@ class SettingElement {
|
|||||||
type = "number";
|
type = "number";
|
||||||
else
|
else
|
||||||
type = "checkbox";
|
type = "checkbox";
|
||||||
const params = Object.assign(overrideParams, definition.params || {});
|
let params = {};
|
||||||
|
if ("params" in definition)
|
||||||
|
params = Object.assign(overrideParams, definition.params || {});
|
||||||
if (params.disabled)
|
if (params.disabled)
|
||||||
currentValue = definition.default;
|
currentValue = definition.default;
|
||||||
return SettingElement.render(type, key, definition, currentValue, (e, value) => {
|
return SettingElement.render(type, key, definition, currentValue, (e, value) => {
|
||||||
@ -994,79 +1069,6 @@ class SettingElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BaseSettingsStore {
|
|
||||||
storage;
|
|
||||||
storageKey;
|
|
||||||
_settings;
|
|
||||||
definitions;
|
|
||||||
constructor(storageKey, definitions) {
|
|
||||||
this.storage = window.localStorage, this.storageKey = storageKey;
|
|
||||||
for (let settingId in definitions) {
|
|
||||||
const setting = definitions[settingId];
|
|
||||||
setting.ready && setting.ready.call(this, setting);
|
|
||||||
}
|
|
||||||
this.definitions = definitions, this._settings = null;
|
|
||||||
}
|
|
||||||
get settings() {
|
|
||||||
if (this._settings)
|
|
||||||
return this._settings;
|
|
||||||
const settings = JSON.parse(this.storage.getItem(this.storageKey) || "{}");
|
|
||||||
return this._settings = settings, settings;
|
|
||||||
}
|
|
||||||
getDefinition(key) {
|
|
||||||
if (!this.definitions[key]) {
|
|
||||||
const error = "Request invalid definition: " + key;
|
|
||||||
throw alert(error), Error(error);
|
|
||||||
}
|
|
||||||
return this.definitions[key];
|
|
||||||
}
|
|
||||||
getSetting(key) {
|
|
||||||
if (typeof key === "undefined") {
|
|
||||||
debugger;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.definitions[key].unsupported)
|
|
||||||
return this.definitions[key].default;
|
|
||||||
if (!(key in this.settings))
|
|
||||||
this.settings[key] = this.validateValue(key, null);
|
|
||||||
return this.settings[key];
|
|
||||||
}
|
|
||||||
setSetting(key, value, emitEvent = !1) {
|
|
||||||
return value = this.validateValue(key, value), this.settings[key] = value, this.saveSettings(), emitEvent && BxEvent.dispatch(window, BxEvent.SETTINGS_CHANGED, {
|
|
||||||
storageKey: this.storageKey,
|
|
||||||
settingKey: key,
|
|
||||||
settingValue: value
|
|
||||||
}), value;
|
|
||||||
}
|
|
||||||
saveSettings() {
|
|
||||||
this.storage.setItem(this.storageKey, JSON.stringify(this.settings));
|
|
||||||
}
|
|
||||||
validateValue(key, value) {
|
|
||||||
const def = this.definitions[key];
|
|
||||||
if (!def)
|
|
||||||
return value;
|
|
||||||
if (typeof value === "undefined" || value === null)
|
|
||||||
value = def.default;
|
|
||||||
if ("min" in def)
|
|
||||||
value = Math.max(def.min, value);
|
|
||||||
if ("max" in def)
|
|
||||||
value = Math.min(def.max, value);
|
|
||||||
if ("options" in def && !(value in def.options))
|
|
||||||
value = def.default;
|
|
||||||
else if ("multipleOptions" in def) {
|
|
||||||
if (value.length) {
|
|
||||||
const validOptions = Object.keys(def.multipleOptions);
|
|
||||||
value.forEach((item2, idx) => {
|
|
||||||
validOptions.indexOf(item2) === -1 && value.splice(idx, 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (!value.length)
|
|
||||||
value = def.default;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSupportedCodecProfiles() {
|
function getSupportedCodecProfiles() {
|
||||||
const options = {
|
const options = {
|
||||||
default: t("default")
|
default: t("default")
|
||||||
@ -4358,12 +4360,6 @@ class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
"game_fortnite_force_console",
|
"game_fortnite_force_console",
|
||||||
"stream_combine_sources"
|
"stream_combine_sources"
|
||||||
]
|
]
|
||||||
}, {
|
|
||||||
group: "game-bar",
|
|
||||||
label: t("game-bar"),
|
|
||||||
items: [
|
|
||||||
"game_bar_position"
|
|
||||||
]
|
|
||||||
}, {
|
}, {
|
||||||
group: "co-op",
|
group: "co-op",
|
||||||
label: t("local-co-op"),
|
label: t("local-co-op"),
|
||||||
@ -4390,14 +4386,6 @@ class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
"stream_touch_controller_style_standard",
|
"stream_touch_controller_style_standard",
|
||||||
"stream_touch_controller_style_custom"
|
"stream_touch_controller_style_custom"
|
||||||
]
|
]
|
||||||
}, {
|
|
||||||
group: "loading-screen",
|
|
||||||
label: t("loading-screen"),
|
|
||||||
items: [
|
|
||||||
"ui_loading_screen_game_art",
|
|
||||||
"ui_loading_screen_wait_time",
|
|
||||||
"ui_loading_screen_rocket"
|
|
||||||
]
|
|
||||||
}, {
|
}, {
|
||||||
group: "ui",
|
group: "ui",
|
||||||
label: t("ui"),
|
label: t("ui"),
|
||||||
@ -4414,6 +4402,20 @@ class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
"block_social_features",
|
"block_social_features",
|
||||||
"ui_hide_sections"
|
"ui_hide_sections"
|
||||||
]
|
]
|
||||||
|
}, {
|
||||||
|
group: "game-bar",
|
||||||
|
label: t("game-bar"),
|
||||||
|
items: [
|
||||||
|
"game_bar_position"
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
group: "loading-screen",
|
||||||
|
label: t("loading-screen"),
|
||||||
|
items: [
|
||||||
|
"ui_loading_screen_game_art",
|
||||||
|
"ui_loading_screen_wait_time",
|
||||||
|
"ui_loading_screen_rocket"
|
||||||
|
]
|
||||||
}, {
|
}, {
|
||||||
group: "other",
|
group: "other",
|
||||||
label: t("other"),
|
label: t("other"),
|
||||||
@ -6975,7 +6977,7 @@ class WebGL2Player {
|
|||||||
}
|
}
|
||||||
#setupShaders() {
|
#setupShaders() {
|
||||||
BxLogger.info(LOG_TAG7, "Setting up", getPref("video_power_preference"));
|
BxLogger.info(LOG_TAG7, "Setting up", getPref("video_power_preference"));
|
||||||
const gl = this.#$canvas.getContext("webgl2", {
|
const gl = this.#$canvas.getContext("webgl", {
|
||||||
isBx: !0,
|
isBx: !0,
|
||||||
antialias: !0,
|
antialias: !0,
|
||||||
alpha: !1,
|
alpha: !1,
|
||||||
@ -7326,100 +7328,6 @@ function patchPointerLockApi() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function cloneStreamHudButton($orgButton, label, svgIcon) {
|
|
||||||
const $container = $orgButton.cloneNode(!0);
|
|
||||||
let timeout;
|
|
||||||
const onTransitionStart = (e) => {
|
|
||||||
if (e.propertyName !== "opacity")
|
|
||||||
return;
|
|
||||||
timeout && clearTimeout(timeout), $container.style.pointerEvents = "none";
|
|
||||||
}, onTransitionEnd = (e) => {
|
|
||||||
if (e.propertyName !== "opacity")
|
|
||||||
return;
|
|
||||||
if (document.getElementById("StreamHud")?.style.left === "0px")
|
|
||||||
timeout && clearTimeout(timeout), timeout = window.setTimeout(() => {
|
|
||||||
$container.style.pointerEvents = "auto";
|
|
||||||
}, 100);
|
|
||||||
};
|
|
||||||
if (STATES.browser.capabilities.touch)
|
|
||||||
$container.addEventListener("transitionstart", onTransitionStart), $container.addEventListener("transitionend", onTransitionEnd);
|
|
||||||
const $button = $container.querySelector("button");
|
|
||||||
$button.setAttribute("title", label);
|
|
||||||
const $orgSvg = $button.querySelector("svg"), $svg = createSvgIcon(svgIcon);
|
|
||||||
return $svg.style.fill = "none", $svg.setAttribute("class", $orgSvg.getAttribute("class") || ""), $svg.ariaHidden = "true", $orgSvg.replaceWith($svg), $container;
|
|
||||||
}
|
|
||||||
function cloneCloseButton($$btnOrg, icon, className, onChange) {
|
|
||||||
const $btn = $$btnOrg.cloneNode(!0), $svg = createSvgIcon(icon);
|
|
||||||
return $svg.setAttribute("class", $btn.firstElementChild.getAttribute("class") || ""), $svg.style.fill = "none", $btn.classList.add(className), $btn.removeChild($btn.firstElementChild), $btn.appendChild($svg), $btn.addEventListener("click", onChange), $btn;
|
|
||||||
}
|
|
||||||
function injectStreamMenuButtons() {
|
|
||||||
const $screen = document.querySelector("#PageContent section[class*=PureScreens]");
|
|
||||||
if (!$screen)
|
|
||||||
return;
|
|
||||||
if ($screen.xObserving)
|
|
||||||
return;
|
|
||||||
$screen.xObserving = !0;
|
|
||||||
let $btnStreamSettings, $btnStreamStats;
|
|
||||||
const streamStats = StreamStats.getInstance();
|
|
||||||
new MutationObserver((mutationList) => {
|
|
||||||
mutationList.forEach((item2) => {
|
|
||||||
if (item2.type !== "childList")
|
|
||||||
return;
|
|
||||||
item2.addedNodes.forEach(async ($node) => {
|
|
||||||
if (!$node || $node.nodeType !== Node.ELEMENT_NODE)
|
|
||||||
return;
|
|
||||||
let $elm = $node;
|
|
||||||
if ($elm instanceof SVGSVGElement)
|
|
||||||
return;
|
|
||||||
if ($elm.className?.includes("PureErrorPage")) {
|
|
||||||
BxEvent.dispatch(window, BxEvent.STREAM_ERROR_PAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ($elm.className?.startsWith("StreamMenu-module__container")) {
|
|
||||||
const $btnCloseHud = document.querySelector("button[class*=StreamMenu-module__backButton]");
|
|
||||||
if (!$btnCloseHud)
|
|
||||||
return;
|
|
||||||
const $btnRefresh = cloneCloseButton($btnCloseHud, BxIcon.REFRESH, "bx-stream-refresh-button", () => {
|
|
||||||
confirm(t("confirm-reload-stream")) && window.location.reload();
|
|
||||||
}), $btnHome = cloneCloseButton($btnCloseHud, BxIcon.HOME, "bx-stream-home-button", () => {
|
|
||||||
confirm(t("back-to-home-confirm")) && (window.location.href = window.location.href.substring(0, 31));
|
|
||||||
});
|
|
||||||
$btnCloseHud.insertAdjacentElement("afterend", $btnRefresh), $btnRefresh.insertAdjacentElement("afterend", $btnHome), document.querySelector("div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module]")?.appendChild(await StreamBadges.getInstance().render());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ($elm.className?.startsWith("Overlay-module_") || $elm.className?.startsWith("InProgressScreen"))
|
|
||||||
$elm = $elm.querySelector("#StreamHud");
|
|
||||||
if (!$elm || ($elm.id || "") !== "StreamHud")
|
|
||||||
return;
|
|
||||||
const $gripHandle = $elm.querySelector("button[class^=GripHandle]"), hideGripHandle = () => {
|
|
||||||
if (!$gripHandle)
|
|
||||||
return;
|
|
||||||
$gripHandle.dispatchEvent(new PointerEvent("pointerdown")), $gripHandle.click(), $gripHandle.dispatchEvent(new PointerEvent("pointerdown")), $gripHandle.click();
|
|
||||||
}, $orgButton = $elm.querySelector("div[class^=HUDButton]");
|
|
||||||
if (!$orgButton)
|
|
||||||
return;
|
|
||||||
if (!$btnStreamSettings)
|
|
||||||
$btnStreamSettings = cloneStreamHudButton($orgButton, t("better-xcloud"), BxIcon.BETTER_XCLOUD), $btnStreamSettings.addEventListener("click", (e) => {
|
|
||||||
hideGripHandle(), e.preventDefault(), SettingsNavigationDialog.getInstance().show();
|
|
||||||
});
|
|
||||||
if (!$btnStreamStats)
|
|
||||||
$btnStreamStats = cloneStreamHudButton($orgButton, t("stream-stats"), BxIcon.STREAM_STATS), $btnStreamStats.addEventListener("click", (e) => {
|
|
||||||
hideGripHandle(), e.preventDefault(), streamStats.toggle();
|
|
||||||
const btnStreamStatsOn2 = !streamStats.isHidden() && !streamStats.isGlancing();
|
|
||||||
$btnStreamStats.classList.toggle("bx-stream-menu-button-on", btnStreamStatsOn2);
|
|
||||||
});
|
|
||||||
const btnStreamStatsOn = !streamStats.isHidden() && !streamStats.isGlancing();
|
|
||||||
if ($btnStreamStats.classList.toggle("bx-stream-menu-button-on", btnStreamStatsOn), $orgButton) {
|
|
||||||
const $btnParent = $orgButton.parentElement;
|
|
||||||
$btnParent.insertBefore($btnStreamStats, $btnParent.lastElementChild), $btnParent.insertBefore($btnStreamSettings, $btnStreamStats);
|
|
||||||
const $dotsButton = $btnParent.lastElementChild;
|
|
||||||
$dotsButton.parentElement.insertBefore($dotsButton, $dotsButton.parentElement.firstElementChild);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}).observe($screen, { subtree: !0, childList: !0 });
|
|
||||||
}
|
|
||||||
|
|
||||||
class BaseGameBarAction {
|
class BaseGameBarAction {
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
@ -7798,6 +7706,141 @@ class ProductDetailsPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StreamUiHandler {
|
||||||
|
static $btnStreamSettings;
|
||||||
|
static $btnStreamStats;
|
||||||
|
static $btnRefresh;
|
||||||
|
static $btnHome;
|
||||||
|
static observer;
|
||||||
|
static cloneStreamHudButton($btnOrg, label, svgIcon) {
|
||||||
|
if (!$btnOrg)
|
||||||
|
return null;
|
||||||
|
const $container = $btnOrg.cloneNode(!0);
|
||||||
|
let timeout;
|
||||||
|
if (STATES.browser.capabilities.touch) {
|
||||||
|
const onTransitionStart = (e) => {
|
||||||
|
if (e.propertyName !== "opacity")
|
||||||
|
return;
|
||||||
|
timeout && clearTimeout(timeout), e.target.style.pointerEvents = "none";
|
||||||
|
}, onTransitionEnd = (e) => {
|
||||||
|
if (e.propertyName !== "opacity")
|
||||||
|
return;
|
||||||
|
const $streamHud = e.target.closest("#StreamHud");
|
||||||
|
if (!$streamHud)
|
||||||
|
return;
|
||||||
|
if ($streamHud.style.left === "0px") {
|
||||||
|
const $target = e.target;
|
||||||
|
timeout && clearTimeout(timeout), timeout = window.setTimeout(() => {
|
||||||
|
$target.style.pointerEvents = "auto";
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$container.addEventListener("transitionstart", onTransitionStart), $container.addEventListener("transitionend", onTransitionEnd);
|
||||||
|
}
|
||||||
|
const $button = $container.querySelector("button");
|
||||||
|
if (!$button)
|
||||||
|
return null;
|
||||||
|
$button.setAttribute("title", label);
|
||||||
|
const $orgSvg = $button.querySelector("svg");
|
||||||
|
if (!$orgSvg)
|
||||||
|
return null;
|
||||||
|
const $svg = createSvgIcon(svgIcon);
|
||||||
|
return $svg.style.fill = "none", $svg.setAttribute("class", $orgSvg.getAttribute("class") || ""), $svg.ariaHidden = "true", $orgSvg.replaceWith($svg), $container;
|
||||||
|
}
|
||||||
|
static cloneCloseButton($btnOrg, icon, className, onChange) {
|
||||||
|
if (!$btnOrg)
|
||||||
|
return null;
|
||||||
|
const $btn = $btnOrg.cloneNode(!0), $svg = createSvgIcon(icon);
|
||||||
|
return $svg.setAttribute("class", $btn.firstElementChild.getAttribute("class") || ""), $svg.style.fill = "none", $btn.classList.add(className), $btn.removeChild($btn.firstElementChild), $btn.appendChild($svg), $btn.addEventListener("click", onChange), $btn;
|
||||||
|
}
|
||||||
|
static async handleStreamMenu() {
|
||||||
|
const $btnCloseHud = document.querySelector("button[class*=StreamMenu-module__backButton]");
|
||||||
|
if (!$btnCloseHud)
|
||||||
|
return;
|
||||||
|
let { $btnRefresh, $btnHome } = StreamUiHandler;
|
||||||
|
if (typeof $btnRefresh === "undefined")
|
||||||
|
$btnRefresh = StreamUiHandler.cloneCloseButton($btnCloseHud, BxIcon.REFRESH, "bx-stream-refresh-button", () => {
|
||||||
|
confirm(t("confirm-reload-stream")) && window.location.reload();
|
||||||
|
});
|
||||||
|
if (typeof $btnHome === "undefined")
|
||||||
|
$btnHome = StreamUiHandler.cloneCloseButton($btnCloseHud, BxIcon.HOME, "bx-stream-home-button", () => {
|
||||||
|
confirm(t("back-to-home-confirm")) && (window.location.href = window.location.href.substring(0, 31));
|
||||||
|
});
|
||||||
|
if ($btnRefresh && $btnHome)
|
||||||
|
$btnCloseHud.insertAdjacentElement("afterend", $btnRefresh), $btnRefresh.insertAdjacentElement("afterend", $btnHome);
|
||||||
|
document.querySelector("div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module]")?.appendChild(await StreamBadges.getInstance().render());
|
||||||
|
}
|
||||||
|
static handleSystemMenu($streamHud) {
|
||||||
|
const $gripHandle = $streamHud.querySelector("button[class^=GripHandle]");
|
||||||
|
if (!$gripHandle)
|
||||||
|
return;
|
||||||
|
const $orgButton = $streamHud.querySelector("div[class^=HUDButton]");
|
||||||
|
if (!$orgButton)
|
||||||
|
return;
|
||||||
|
const hideGripHandle = () => {
|
||||||
|
if (!$gripHandle)
|
||||||
|
return;
|
||||||
|
$gripHandle.dispatchEvent(new PointerEvent("pointerdown")), $gripHandle.click(), $gripHandle.dispatchEvent(new PointerEvent("pointerdown")), $gripHandle.click();
|
||||||
|
};
|
||||||
|
let $btnStreamSettings = StreamUiHandler.$btnStreamSettings;
|
||||||
|
if (typeof $btnStreamSettings === "undefined")
|
||||||
|
$btnStreamSettings = StreamUiHandler.cloneStreamHudButton($orgButton, t("better-xcloud"), BxIcon.BETTER_XCLOUD), $btnStreamSettings?.addEventListener("click", (e) => {
|
||||||
|
hideGripHandle(), e.preventDefault(), SettingsNavigationDialog.getInstance().show();
|
||||||
|
}), StreamUiHandler.$btnStreamSettings = $btnStreamSettings;
|
||||||
|
const streamStats = StreamStats.getInstance();
|
||||||
|
let $btnStreamStats = StreamUiHandler.$btnStreamStats;
|
||||||
|
if (typeof $btnStreamStats === "undefined")
|
||||||
|
$btnStreamStats = StreamUiHandler.cloneStreamHudButton($orgButton, t("stream-stats"), BxIcon.STREAM_STATS), $btnStreamStats?.addEventListener("click", (e) => {
|
||||||
|
hideGripHandle(), e.preventDefault(), streamStats.toggle();
|
||||||
|
const btnStreamStatsOn = !streamStats.isHidden() && !streamStats.isGlancing();
|
||||||
|
$btnStreamStats.classList.toggle("bx-stream-menu-button-on", btnStreamStatsOn);
|
||||||
|
}), StreamUiHandler.$btnStreamStats = $btnStreamStats;
|
||||||
|
const $btnParent = $orgButton.parentElement;
|
||||||
|
if ($btnStreamSettings && $btnStreamStats) {
|
||||||
|
const btnStreamStatsOn = !streamStats.isHidden() && !streamStats.isGlancing();
|
||||||
|
$btnStreamStats.classList.toggle("bx-stream-menu-button-on", btnStreamStatsOn), $btnParent.insertBefore($btnStreamStats, $btnParent.lastElementChild), $btnParent.insertBefore($btnStreamSettings, $btnStreamStats);
|
||||||
|
}
|
||||||
|
const $dotsButton = $btnParent.lastElementChild;
|
||||||
|
$dotsButton.parentElement.insertBefore($dotsButton, $dotsButton.parentElement.firstElementChild);
|
||||||
|
}
|
||||||
|
static reset() {
|
||||||
|
StreamUiHandler.$btnStreamSettings = void 0, StreamUiHandler.$btnStreamStats = void 0, StreamUiHandler.$btnRefresh = void 0, StreamUiHandler.$btnHome = void 0, StreamUiHandler.observer && StreamUiHandler.observer.disconnect(), StreamUiHandler.observer = void 0;
|
||||||
|
}
|
||||||
|
static observe() {
|
||||||
|
StreamUiHandler.reset();
|
||||||
|
const $screen = document.querySelector("#PageContent section[class*=PureScreens]");
|
||||||
|
if (!$screen)
|
||||||
|
return;
|
||||||
|
new MutationObserver((mutationList) => {
|
||||||
|
mutationList.forEach((item2) => {
|
||||||
|
if (item2.type !== "childList")
|
||||||
|
return;
|
||||||
|
item2.addedNodes.forEach(async ($node) => {
|
||||||
|
if (!$node || $node.nodeType !== Node.ELEMENT_NODE)
|
||||||
|
return;
|
||||||
|
let $elm = $node;
|
||||||
|
if (!($elm instanceof HTMLElement))
|
||||||
|
return;
|
||||||
|
const className = $elm.className || "";
|
||||||
|
if (className.includes("PureErrorPage")) {
|
||||||
|
BxEvent.dispatch(window, BxEvent.STREAM_ERROR_PAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (className.startsWith("StreamMenu-module__container")) {
|
||||||
|
StreamUiHandler.handleStreamMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (className.startsWith("Overlay-module_") || className.startsWith("InProgressScreen"))
|
||||||
|
$elm = $elm.querySelector("#StreamHud");
|
||||||
|
if (!$elm || ($elm.id || "") !== "StreamHud")
|
||||||
|
return;
|
||||||
|
StreamUiHandler.handleSystemMenu($elm);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).observe($screen, { subtree: !0, childList: !0 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function unload() {
|
function unload() {
|
||||||
if (!STATES.isPlaying)
|
if (!STATES.isPlaying)
|
||||||
return;
|
return;
|
||||||
@ -7920,7 +7963,7 @@ window.addEventListener(BxEvent.STREAM_STARTING, (e) => {
|
|||||||
MouseCursorHider.start(), MouseCursorHider.hide();
|
MouseCursorHider.start(), MouseCursorHider.hide();
|
||||||
});
|
});
|
||||||
window.addEventListener(BxEvent.STREAM_PLAYING, (e) => {
|
window.addEventListener(BxEvent.STREAM_PLAYING, (e) => {
|
||||||
if (STATES.isPlaying = !0, injectStreamMenuButtons(), getPref("game_bar_position") !== "off") {
|
if (STATES.isPlaying = !0, StreamUiHandler.observe(), getPref("game_bar_position") !== "off") {
|
||||||
const gameBar = GameBar.getInstance();
|
const gameBar = GameBar.getInstance();
|
||||||
gameBar.reset(), gameBar.enable(), gameBar.showBar();
|
gameBar.reset(), gameBar.enable(), gameBar.showBar();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import { VibrationManager } from "@modules/vibration-manager";
|
|||||||
import { overridePreloadState } from "@utils/preload-state";
|
import { overridePreloadState } from "@utils/preload-state";
|
||||||
import { disableAdobeAudienceManager, patchAudioContext, patchCanvasContext, patchMeControl, patchPointerLockApi, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches";
|
import { disableAdobeAudienceManager, patchAudioContext, patchCanvasContext, patchMeControl, patchPointerLockApi, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches";
|
||||||
import { AppInterface, STATES } from "@utils/global";
|
import { AppInterface, STATES } from "@utils/global";
|
||||||
import { injectStreamMenuButtons } from "@modules/stream/stream-ui";
|
|
||||||
import { BxLogger } from "@utils/bx-logger";
|
import { BxLogger } from "@utils/bx-logger";
|
||||||
import { GameBar } from "./modules/game-bar/game-bar";
|
import { GameBar } from "./modules/game-bar/game-bar";
|
||||||
import { Screenshot } from "./utils/screenshot";
|
import { Screenshot } from "./utils/screenshot";
|
||||||
@ -38,6 +37,7 @@ import { PrefKey } from "./enums/pref-keys";
|
|||||||
import { getPref } from "./utils/settings-storages/global-settings-storage";
|
import { getPref } from "./utils/settings-storages/global-settings-storage";
|
||||||
import { compressCss } from "@macros/build" with {type: "macro"};
|
import { compressCss } from "@macros/build" with {type: "macro"};
|
||||||
import { SettingsNavigationDialog } from "./modules/ui/dialog/settings-dialog";
|
import { SettingsNavigationDialog } from "./modules/ui/dialog/settings-dialog";
|
||||||
|
import { StreamUiHandler } from "./modules/stream/stream-ui";
|
||||||
|
|
||||||
|
|
||||||
// Handle login page
|
// Handle login page
|
||||||
@ -186,7 +186,7 @@ window.addEventListener(BxEvent.STREAM_STARTING, e => {
|
|||||||
|
|
||||||
window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
||||||
STATES.isPlaying = true;
|
STATES.isPlaying = true;
|
||||||
injectStreamMenuButtons();
|
StreamUiHandler.observe();
|
||||||
|
|
||||||
if (getPref(PrefKey.GAME_BAR_POSITION) !== 'off') {
|
if (getPref(PrefKey.GAME_BAR_POSITION) !== 'off') {
|
||||||
const gameBar = GameBar.getInstance();
|
const gameBar = GameBar.getInstance();
|
||||||
|
@ -124,7 +124,7 @@ export class WebGL2Player {
|
|||||||
#setupShaders() {
|
#setupShaders() {
|
||||||
BxLogger.info(LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE));
|
BxLogger.info(LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE));
|
||||||
|
|
||||||
const gl = this.#$canvas.getContext('webgl2', {
|
const gl = this.#$canvas.getContext('webgl', {
|
||||||
isBx: true,
|
isBx: true,
|
||||||
antialias: true,
|
antialias: true,
|
||||||
alpha: false,
|
alpha: false,
|
||||||
|
@ -8,17 +8,30 @@ import { StreamStats } from "./stream-stats.ts";
|
|||||||
import { SettingsNavigationDialog } from "../ui/dialog/settings-dialog.ts";
|
import { SettingsNavigationDialog } from "../ui/dialog/settings-dialog.ts";
|
||||||
|
|
||||||
|
|
||||||
function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: typeof BxIcon) {
|
export class StreamUiHandler {
|
||||||
const $container = $orgButton.cloneNode(true) as HTMLElement;
|
private static $btnStreamSettings: HTMLElement | null | undefined;
|
||||||
|
private static $btnStreamStats: HTMLElement | null | undefined;
|
||||||
|
private static $btnRefresh: HTMLElement | null | undefined;
|
||||||
|
private static $btnHome: HTMLElement | null | undefined;
|
||||||
|
private static observer: MutationObserver | undefined;
|
||||||
|
|
||||||
|
private static cloneStreamHudButton($btnOrg: HTMLElement, label: string, svgIcon: typeof BxIcon): HTMLElement | null {
|
||||||
|
if (!$btnOrg) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $container = $btnOrg.cloneNode(true) as HTMLElement;
|
||||||
let timeout: number | null;
|
let timeout: number | null;
|
||||||
|
|
||||||
|
// Prevent touching other button while the bar is showing/hiding
|
||||||
|
if (STATES.browser.capabilities.touch) {
|
||||||
const onTransitionStart = (e: TransitionEvent) => {
|
const onTransitionStart = (e: TransitionEvent) => {
|
||||||
if (e.propertyName !== 'opacity') {
|
if (e.propertyName !== 'opacity') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout && clearTimeout(timeout);
|
timeout && clearTimeout(timeout);
|
||||||
$container.style.pointerEvents = 'none';
|
(e.target as HTMLElement).style.pointerEvents = 'none';
|
||||||
};
|
};
|
||||||
|
|
||||||
const onTransitionEnd = (e: TransitionEvent) => {
|
const onTransitionEnd = (e: TransitionEvent) => {
|
||||||
@ -26,24 +39,36 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: t
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const left = document.getElementById('StreamHud')?.style.left;
|
const $streamHud = (e.target as HTMLElement).closest('#StreamHud') as HTMLElement;
|
||||||
|
if (!$streamHud) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const left = $streamHud.style.left;
|
||||||
if (left === '0px') {
|
if (left === '0px') {
|
||||||
|
const $target = e.target as HTMLElement;
|
||||||
timeout && clearTimeout(timeout);
|
timeout && clearTimeout(timeout);
|
||||||
timeout = window.setTimeout(() => {
|
timeout = window.setTimeout(() => {
|
||||||
$container.style.pointerEvents = 'auto';
|
$target.style.pointerEvents = 'auto';
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (STATES.browser.capabilities.touch) {
|
|
||||||
$container.addEventListener('transitionstart', onTransitionStart);
|
$container.addEventListener('transitionstart', onTransitionStart);
|
||||||
$container.addEventListener('transitionend', onTransitionEnd);
|
$container.addEventListener('transitionend', onTransitionEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
const $button = $container.querySelector('button')!;
|
const $button = $container.querySelector('button') as HTMLElement;
|
||||||
|
if (!$button) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
$button.setAttribute('title', label);
|
$button.setAttribute('title', label);
|
||||||
|
|
||||||
const $orgSvg = $button.querySelector('svg')!;
|
const $orgSvg = $button.querySelector('svg') as SVGElement;
|
||||||
|
if (!$orgSvg) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const $svg = createSvgIcon(svgIcon);
|
const $svg = createSvgIcon(svgIcon);
|
||||||
$svg.style.fill = 'none';
|
$svg.style.fill = 'none';
|
||||||
$svg.setAttribute('class', $orgSvg.getAttribute('class') || '');
|
$svg.setAttribute('class', $orgSvg.getAttribute('class') || '');
|
||||||
@ -51,14 +76,15 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: t
|
|||||||
|
|
||||||
$orgSvg.replaceWith($svg);
|
$orgSvg.replaceWith($svg);
|
||||||
return $container;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static cloneCloseButton($btnOrg: HTMLElement, icon: typeof BxIcon, className: string, onChange: any): HTMLElement | null {
|
||||||
function cloneCloseButton($$btnOrg: HTMLElement, icon: typeof BxIcon, className: string, onChange: any) {
|
if (!$btnOrg) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// Create button from the Close button
|
// Create button from the Close button
|
||||||
const $btn = $$btnOrg.cloneNode(true) as HTMLElement;
|
const $btn = $btnOrg.cloneNode(true) as HTMLElement;
|
||||||
|
|
||||||
// Refresh SVG
|
|
||||||
const $svg = createSvgIcon(icon);
|
const $svg = createSvgIcon(icon);
|
||||||
// Copy classes
|
// Copy classes
|
||||||
$svg.setAttribute('class', $btn.firstElementChild!.getAttribute('class') || '');
|
$svg.setAttribute('class', $btn.firstElementChild!.getAttribute('class') || '');
|
||||||
@ -73,25 +99,133 @@ function cloneCloseButton($$btnOrg: HTMLElement, icon: typeof BxIcon, className:
|
|||||||
$btn.addEventListener('click', onChange);
|
$btn.addEventListener('click', onChange);
|
||||||
|
|
||||||
return $btn;
|
return $btn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async handleStreamMenu() {
|
||||||
|
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]') as HTMLElement;
|
||||||
|
if (!$btnCloseHud) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let $btnRefresh = StreamUiHandler.$btnRefresh;
|
||||||
|
let $btnHome = StreamUiHandler.$btnHome;
|
||||||
|
|
||||||
|
// Create Refresh button from the Close button
|
||||||
|
if (typeof $btnRefresh === 'undefined') {
|
||||||
|
$btnRefresh = StreamUiHandler.cloneCloseButton($btnCloseHud, BxIcon.REFRESH, 'bx-stream-refresh-button', () => {
|
||||||
|
confirm(t('confirm-reload-stream')) && window.location.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof $btnHome === 'undefined') {
|
||||||
|
$btnHome = StreamUiHandler.cloneCloseButton($btnCloseHud, BxIcon.HOME, 'bx-stream-home-button', () => {
|
||||||
|
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to website
|
||||||
|
if ($btnRefresh && $btnHome) {
|
||||||
|
$btnCloseHud.insertAdjacentElement('afterend', $btnRefresh);
|
||||||
|
$btnRefresh.insertAdjacentElement('afterend', $btnHome);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render stream badges
|
||||||
|
const $menu = document.querySelector('div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module]');
|
||||||
|
$menu?.appendChild(await StreamBadges.getInstance().render());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static handleSystemMenu($streamHud: HTMLElement) {
|
||||||
|
// Grip handle
|
||||||
|
const $gripHandle = $streamHud.querySelector('button[class^=GripHandle]') as HTMLElement;
|
||||||
|
if (!$gripHandle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the last button
|
||||||
|
const $orgButton = $streamHud.querySelector('div[class^=HUDButton]') as HTMLElement;
|
||||||
|
if (!$orgButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hideGripHandle = () => {
|
||||||
|
if (!$gripHandle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
||||||
|
$gripHandle.click();
|
||||||
|
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
||||||
|
$gripHandle.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Stream Settings button
|
||||||
|
let $btnStreamSettings = StreamUiHandler.$btnStreamSettings;
|
||||||
|
if (typeof $btnStreamSettings === 'undefined') {
|
||||||
|
$btnStreamSettings = StreamUiHandler.cloneStreamHudButton($orgButton, t('better-xcloud'), BxIcon.BETTER_XCLOUD);
|
||||||
|
$btnStreamSettings?.addEventListener('click', e => {
|
||||||
|
hideGripHandle();
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Show Stream Settings dialog
|
||||||
|
SettingsNavigationDialog.getInstance().show();
|
||||||
|
});
|
||||||
|
|
||||||
|
StreamUiHandler.$btnStreamSettings = $btnStreamSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Stream Stats button
|
||||||
|
const streamStats = StreamStats.getInstance();
|
||||||
|
let $btnStreamStats = StreamUiHandler.$btnStreamStats;
|
||||||
|
if (typeof $btnStreamStats === 'undefined') {
|
||||||
|
$btnStreamStats = StreamUiHandler.cloneStreamHudButton($orgButton, t('stream-stats'), BxIcon.STREAM_STATS);
|
||||||
|
$btnStreamStats?.addEventListener('click', e => {
|
||||||
|
hideGripHandle();
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Toggle Stream Stats
|
||||||
|
streamStats.toggle();
|
||||||
|
|
||||||
|
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
|
||||||
|
$btnStreamStats!.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
|
||||||
|
});
|
||||||
|
|
||||||
|
StreamUiHandler.$btnStreamStats = $btnStreamStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $btnParent = $orgButton.parentElement!;
|
||||||
|
|
||||||
|
if ($btnStreamSettings && $btnStreamStats) {
|
||||||
|
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
|
||||||
|
$btnStreamStats.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
|
||||||
|
|
||||||
|
// Insert buttons after Stream Settings button
|
||||||
|
$btnParent.insertBefore($btnStreamStats, $btnParent.lastElementChild);
|
||||||
|
$btnParent.insertBefore($btnStreamSettings, $btnStreamStats);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move the Dots button to the beginning
|
||||||
|
const $dotsButton = $btnParent.lastElementChild!;
|
||||||
|
$dotsButton.parentElement!.insertBefore($dotsButton, $dotsButton.parentElement!.firstElementChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static reset() {
|
||||||
|
StreamUiHandler.$btnStreamSettings = undefined;
|
||||||
|
StreamUiHandler.$btnStreamStats = undefined;
|
||||||
|
StreamUiHandler.$btnRefresh = undefined;
|
||||||
|
StreamUiHandler.$btnHome = undefined;
|
||||||
|
|
||||||
|
StreamUiHandler.observer && StreamUiHandler.observer.disconnect();
|
||||||
|
StreamUiHandler.observer = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
static observe() {
|
||||||
|
StreamUiHandler.reset();
|
||||||
|
|
||||||
export function injectStreamMenuButtons() {
|
|
||||||
const $screen = document.querySelector('#PageContent section[class*=PureScreens]');
|
const $screen = document.querySelector('#PageContent section[class*=PureScreens]');
|
||||||
if (!$screen) {
|
if (!$screen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($screen as any).xObserving) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
($screen as any).xObserving = true;
|
|
||||||
|
|
||||||
let $btnStreamSettings: HTMLElement;
|
|
||||||
let $btnStreamStats: HTMLElement;
|
|
||||||
const streamStats = StreamStats.getInstance();
|
|
||||||
|
|
||||||
const observer = new MutationObserver(mutationList => {
|
const observer = new MutationObserver(mutationList => {
|
||||||
mutationList.forEach(item => {
|
mutationList.forEach(item => {
|
||||||
if (item.type !== 'childList') {
|
if (item.type !== 'childList') {
|
||||||
@ -105,45 +239,26 @@ export function injectStreamMenuButtons() {
|
|||||||
|
|
||||||
let $elm: HTMLElement | null = $node as HTMLElement;
|
let $elm: HTMLElement | null = $node as HTMLElement;
|
||||||
|
|
||||||
// Ignore SVG elements
|
// Ignore non-HTML elements
|
||||||
if ($elm instanceof SVGSVGElement) {
|
if (!($elm instanceof HTMLElement)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const className = $elm.className || '';
|
||||||
|
|
||||||
// Error Page: .PureErrorPage.ErrorScreen
|
// Error Page: .PureErrorPage.ErrorScreen
|
||||||
if ($elm.className?.includes('PureErrorPage')) {
|
if (className.includes('PureErrorPage')) {
|
||||||
BxEvent.dispatch(window, BxEvent.STREAM_ERROR_PAGE);
|
BxEvent.dispatch(window, BxEvent.STREAM_ERROR_PAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render badges
|
// Render badges
|
||||||
if ($elm.className?.startsWith('StreamMenu-module__container')) {
|
if (className.startsWith('StreamMenu-module__container')) {
|
||||||
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]') as HTMLElement;
|
StreamUiHandler.handleStreamMenu();
|
||||||
if (!$btnCloseHud) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Refresh button from the Close button
|
if (className.startsWith('Overlay-module_') || className.startsWith('InProgressScreen')) {
|
||||||
const $btnRefresh = cloneCloseButton($btnCloseHud, BxIcon.REFRESH, 'bx-stream-refresh-button', () => {
|
|
||||||
confirm(t('confirm-reload-stream')) && window.location.reload();
|
|
||||||
});
|
|
||||||
|
|
||||||
const $btnHome = cloneCloseButton($btnCloseHud, BxIcon.HOME, 'bx-stream-home-button', () => {
|
|
||||||
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add to website
|
|
||||||
$btnCloseHud.insertAdjacentElement('afterend', $btnRefresh);
|
|
||||||
$btnRefresh.insertAdjacentElement('afterend', $btnHome);
|
|
||||||
|
|
||||||
// Render stream badges
|
|
||||||
const $menu = document.querySelector('div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module]');
|
|
||||||
$menu?.appendChild(await StreamBadges.getInstance().render());
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($elm.className?.startsWith('Overlay-module_') || $elm.className?.startsWith('InProgressScreen')) {
|
|
||||||
$elm = $elm.querySelector('#StreamHud');
|
$elm = $elm.querySelector('#StreamHud');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,69 +266,12 @@ export function injectStreamMenuButtons() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grip handle
|
// Handle System Menu bar
|
||||||
const $gripHandle = $elm.querySelector('button[class^=GripHandle]') as HTMLElement;
|
StreamUiHandler.handleSystemMenu($elm);
|
||||||
|
|
||||||
const hideGripHandle = () => {
|
|
||||||
if (!$gripHandle) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
|
||||||
$gripHandle.click();
|
|
||||||
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
|
||||||
$gripHandle.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the second last button
|
|
||||||
const $orgButton = $elm.querySelector('div[class^=HUDButton]') as HTMLElement;
|
|
||||||
if (!$orgButton) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Stream Settings button
|
|
||||||
if (!$btnStreamSettings) {
|
|
||||||
$btnStreamSettings = cloneStreamHudButton($orgButton, t('better-xcloud'), BxIcon.BETTER_XCLOUD);
|
|
||||||
$btnStreamSettings.addEventListener('click', e => {
|
|
||||||
hideGripHandle();
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
// Show Stream Settings dialog
|
|
||||||
SettingsNavigationDialog.getInstance().show();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Stream Stats button
|
|
||||||
if (!$btnStreamStats) {
|
|
||||||
$btnStreamStats = cloneStreamHudButton($orgButton, t('stream-stats'), BxIcon.STREAM_STATS);
|
|
||||||
$btnStreamStats.addEventListener('click', e => {
|
|
||||||
hideGripHandle();
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
// Toggle Stream Stats
|
|
||||||
streamStats.toggle();
|
|
||||||
|
|
||||||
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
|
|
||||||
$btnStreamStats.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
|
|
||||||
$btnStreamStats.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
|
|
||||||
|
|
||||||
if ($orgButton) {
|
|
||||||
const $btnParent = $orgButton.parentElement!;
|
|
||||||
|
|
||||||
// Insert buttons after Stream Settings button
|
|
||||||
$btnParent.insertBefore($btnStreamStats, $btnParent.lastElementChild);
|
|
||||||
$btnParent.insertBefore($btnStreamSettings, $btnStreamStats);
|
|
||||||
|
|
||||||
// Move the Dots button to the beginning
|
|
||||||
const $dotsButton = $btnParent.lastElementChild!;
|
|
||||||
$dotsButton.parentElement!.insertBefore($dotsButton, $dotsButton.parentElement!.firstElementChild);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe($screen, {subtree: true, childList: true});
|
observer.observe($screen, {subtree: true, childList: true});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,12 +176,6 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
PrefKey.GAME_FORTNITE_FORCE_CONSOLE,
|
PrefKey.GAME_FORTNITE_FORCE_CONSOLE,
|
||||||
PrefKey.STREAM_COMBINE_SOURCES,
|
PrefKey.STREAM_COMBINE_SOURCES,
|
||||||
],
|
],
|
||||||
}, {
|
|
||||||
group: 'game-bar',
|
|
||||||
label: t('game-bar'),
|
|
||||||
items: [
|
|
||||||
PrefKey.GAME_BAR_POSITION,
|
|
||||||
],
|
|
||||||
}, {
|
}, {
|
||||||
group: 'co-op',
|
group: 'co-op',
|
||||||
label: t('local-co-op'),
|
label: t('local-co-op'),
|
||||||
@ -208,14 +202,6 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD,
|
PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD,
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM,
|
PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM,
|
||||||
],
|
],
|
||||||
}, {
|
|
||||||
group: 'loading-screen',
|
|
||||||
label: t('loading-screen'),
|
|
||||||
items: [
|
|
||||||
PrefKey.UI_LOADING_SCREEN_GAME_ART,
|
|
||||||
PrefKey.UI_LOADING_SCREEN_WAIT_TIME,
|
|
||||||
PrefKey.UI_LOADING_SCREEN_ROCKET,
|
|
||||||
],
|
|
||||||
}, {
|
}, {
|
||||||
group: 'ui',
|
group: 'ui',
|
||||||
label: t('ui'),
|
label: t('ui'),
|
||||||
@ -232,6 +218,20 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
PrefKey.BLOCK_SOCIAL_FEATURES,
|
PrefKey.BLOCK_SOCIAL_FEATURES,
|
||||||
PrefKey.UI_HIDE_SECTIONS,
|
PrefKey.UI_HIDE_SECTIONS,
|
||||||
],
|
],
|
||||||
|
}, {
|
||||||
|
group: 'game-bar',
|
||||||
|
label: t('game-bar'),
|
||||||
|
items: [
|
||||||
|
PrefKey.GAME_BAR_POSITION,
|
||||||
|
],
|
||||||
|
}, {
|
||||||
|
group: 'loading-screen',
|
||||||
|
label: t('loading-screen'),
|
||||||
|
items: [
|
||||||
|
PrefKey.UI_LOADING_SCREEN_GAME_ART,
|
||||||
|
PrefKey.UI_LOADING_SCREEN_WAIT_TIME,
|
||||||
|
PrefKey.UI_LOADING_SCREEN_ROCKET,
|
||||||
|
],
|
||||||
}, {
|
}, {
|
||||||
group: 'other',
|
group: 'other',
|
||||||
label: t('other'),
|
label: t('other'),
|
||||||
|
49
src/types/setting-definition.d.ts
vendored
49
src/types/setting-definition.d.ts
vendored
@ -1,19 +1,42 @@
|
|||||||
export type SettingDefinition = {
|
export type SettingDefinition = {
|
||||||
default: any;
|
default: any;
|
||||||
optionsGroup?: string;
|
} & Partial<{
|
||||||
options?: {[index: string]: string};
|
label: string;
|
||||||
multipleOptions?: {[index: string]: string};
|
note: string | HTMLElement;
|
||||||
unsupported?: string | boolean;
|
experimental: boolean;
|
||||||
note?: string | HTMLElement;
|
unsupported: string | boolean;
|
||||||
type?: SettingElementType;
|
ready: (setting: SettingDefinition) => void;
|
||||||
ready?: (setting: SettingDefinition) => void;
|
|
||||||
// migrate?: (this: Preferences, savedPrefs: any, value: any) => void;
|
// migrate?: (this: Preferences, savedPrefs: any, value: any) => void;
|
||||||
min?: number;
|
}> & (
|
||||||
max?: number;
|
{} | {
|
||||||
|
options: {[index: string]: string};
|
||||||
|
optionsGroup?: string;
|
||||||
|
} | {
|
||||||
|
multipleOptions: {[index: string]: string};
|
||||||
|
params: MultipleOptionsParams;
|
||||||
|
} | {
|
||||||
|
type: SettingElementType.NUMBER_STEPPER;
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
params: NumberStepperParams;
|
||||||
|
|
||||||
steps?: number;
|
steps?: number;
|
||||||
experimental?: boolean;
|
}
|
||||||
params?: any;
|
);
|
||||||
label?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type SettingDefinitions = {[index in PrefKey]: SettingDefinition};
|
export type SettingDefinitions = {[index in PrefKey]: SettingDefinition};
|
||||||
|
|
||||||
|
export type MultipleOptionsParams = Partial<{
|
||||||
|
size?: number;
|
||||||
|
}>
|
||||||
|
|
||||||
|
export type NumberStepperParams = Partial<{
|
||||||
|
suffix: string;
|
||||||
|
disabled: boolean;
|
||||||
|
hideSlider: boolean;
|
||||||
|
|
||||||
|
ticks: number;
|
||||||
|
exactTicks: number;
|
||||||
|
|
||||||
|
customTextValue: (value: any) => string | null;
|
||||||
|
}>
|
||||||
|
@ -3,21 +3,7 @@ import { CE } from "@utils/html";
|
|||||||
import { setNearby } from "./navigation-utils";
|
import { setNearby } from "./navigation-utils";
|
||||||
import type { PrefKey } from "@/enums/pref-keys";
|
import type { PrefKey } from "@/enums/pref-keys";
|
||||||
import type { BaseSettingsStore } from "./settings-storages/base-settings-storage";
|
import type { BaseSettingsStore } from "./settings-storages/base-settings-storage";
|
||||||
|
import { type MultipleOptionsParams, type NumberStepperParams } from "@/types/setting-definition";
|
||||||
type MultipleOptionsParams = {
|
|
||||||
size?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
type NumberStepperParams = {
|
|
||||||
suffix?: string;
|
|
||||||
disabled?: boolean;
|
|
||||||
hideSlider?: boolean;
|
|
||||||
|
|
||||||
ticks?: number;
|
|
||||||
exactTicks?: number;
|
|
||||||
|
|
||||||
customTextValue?: (value: any) => string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum SettingElementType {
|
export enum SettingElementType {
|
||||||
OPTIONS = 'options',
|
OPTIONS = 'options',
|
||||||
@ -381,7 +367,11 @@ export class SettingElement {
|
|||||||
type = SettingElementType.CHECKBOX;
|
type = SettingElementType.CHECKBOX;
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = Object.assign(overrideParams, definition.params || {});
|
let params: any = {};
|
||||||
|
if ('params' in definition) {
|
||||||
|
params = Object.assign(overrideParams, definition.params || {});
|
||||||
|
}
|
||||||
|
|
||||||
if (params.disabled) {
|
if (params.disabled) {
|
||||||
currentValue = definition.default;
|
currentValue = definition.default;
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,14 @@ import { UiSection } from "@/enums/ui-sections";
|
|||||||
import { UserAgentProfile } from "@/enums/user-agent";
|
import { UserAgentProfile } from "@/enums/user-agent";
|
||||||
import { StreamStat } from "@/modules/stream/stream-stats";
|
import { StreamStat } from "@/modules/stream/stream-stats";
|
||||||
import type { PreferenceSetting } from "@/types/preferences";
|
import type { PreferenceSetting } from "@/types/preferences";
|
||||||
import type { SettingDefinitions } from "@/types/setting-definition";
|
import { type SettingDefinitions } from "@/types/setting-definition";
|
||||||
import { BX_FLAGS } from "../bx-flags";
|
import { BX_FLAGS } from "../bx-flags";
|
||||||
import { STATES, AppInterface, STORAGE } from "../global";
|
import { STATES, AppInterface, STORAGE } from "../global";
|
||||||
import { CE } from "../html";
|
import { CE } from "../html";
|
||||||
import { SettingElementType } from "../setting-element";
|
|
||||||
import { t, SUPPORTED_LANGUAGES } from "../translation";
|
import { t, SUPPORTED_LANGUAGES } from "../translation";
|
||||||
import { UserAgent } from "../user-agent";
|
import { UserAgent } from "../user-agent";
|
||||||
import { BaseSettingsStore as BaseSettingsStorage } from "./base-settings-storage";
|
import { BaseSettingsStore as BaseSettingsStorage } from "./base-settings-storage";
|
||||||
|
import { SettingElementType } from "../setting-element";
|
||||||
|
|
||||||
|
|
||||||
function getSupportedCodecProfiles() {
|
function getSupportedCodecProfiles() {
|
||||||
|
Reference in New Issue
Block a user