Update better-xcloud.user.js

This commit is contained in:
redphx 2024-06-22 10:36:27 +07:00
parent cf546123db
commit d906de7803

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Better xCloud // @name Better xCloud
// @namespace https://github.com/redphx // @namespace https://github.com/redphx
// @version 5.0.0 // @version 5.0.1-beta
// @description Improve Xbox Cloud Gaming (xCloud) experience // @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx // @author redphx
// @license MIT // @license MIT
@ -124,7 +124,7 @@ class UserAgent {
} }
// src/utils/global.ts // src/utils/global.ts
var SCRIPT_VERSION = "5.0.0"; var SCRIPT_VERSION = "5.0.1-beta";
var AppInterface = window.AppInterface; var AppInterface = window.AppInterface;
UserAgent.init(); UserAgent.init();
var userAgent = window.navigator.userAgent.toLowerCase(); var userAgent = window.navigator.userAgent.toLowerCase();
@ -795,9 +795,10 @@ class SettingElement {
options.disabled = !!options.disabled; options.disabled = !!options.disabled;
options.hideSlider = !!options.hideSlider; options.hideSlider = !!options.hideSlider;
let $text; let $text;
let $decBtn; let $btnDec;
let $incBtn; let $btnInc;
let $range; let $range;
let controlValue = value;
const MIN = setting.min; const MIN = setting.min;
const MAX = setting.max; const MAX = setting.max;
const STEPS = Math.max(setting.steps || 1, 1); const STEPS = Math.max(setting.steps || 1, 1);
@ -812,11 +813,15 @@ class SettingElement {
} }
return textContent; return textContent;
}; };
const $wrapper = CE("div", { class: "bx-number-stepper", id: `bx_setting_${key}` }, $decBtn = CE("button", { const updateButtonsVisibility = () => {
$btnDec.classList.toggle("bx-hidden", controlValue === MIN);
$btnInc.classList.toggle("bx-hidden", controlValue === MAX);
};
const $wrapper = CE("div", { class: "bx-number-stepper", id: `bx_setting_${key}` }, $btnDec = CE("button", {
"data-type": "dec", "data-type": "dec",
type: "button", type: "button",
tabindex: -1 tabindex: -1
}, "-"), $text = CE("span", {}, renderTextValue(value)), $incBtn = CE("button", { }, "-"), $text = CE("span", {}, renderTextValue(value)), $btnInc = CE("button", {
"data-type": "inc", "data-type": "inc",
type: "button", type: "button",
tabindex: -1 tabindex: -1
@ -833,6 +838,8 @@ class SettingElement {
}); });
$range.addEventListener("input", (e) => { $range.addEventListener("input", (e) => {
value = parseInt(e.target.value); value = parseInt(e.target.value);
controlValue = value;
updateButtonsVisibility();
$text.textContent = renderTextValue(value); $text.textContent = renderTextValue(value);
!e.ignoreOnChange && onChange && onChange(e, value); !e.ignoreOnChange && onChange && onChange(e, value);
}); });
@ -858,12 +865,13 @@ class SettingElement {
} }
} }
if (options.disabled) { if (options.disabled) {
$incBtn.disabled = true; $btnInc.disabled = true;
$incBtn.classList.add("bx-hidden"); $btnInc.classList.add("bx-hidden");
$decBtn.disabled = true; $btnDec.disabled = true;
$decBtn.classList.add("bx-hidden"); $btnDec.classList.add("bx-hidden");
return $wrapper; return $wrapper;
} }
updateButtonsVisibility();
let interval; let interval;
let isHolding = false; let isHolding = false;
const onClick = (e) => { const onClick = (e) => {
@ -872,18 +880,16 @@ class SettingElement {
isHolding = false; isHolding = false;
return; return;
} }
let value2; const $btn = e.target;
if ($range) { let value2 = parseInt(controlValue);
value2 = parseInt($range.value); const btnType = $btn.dataset.type;
} else {
value2 = parseInt($text.textContent);
}
const btnType = e.target.getAttribute("data-type");
if (btnType === "dec") { if (btnType === "dec") {
value2 = Math.max(MIN, value2 - STEPS); value2 = Math.max(MIN, value2 - STEPS);
} else { } else {
value2 = Math.min(MAX, value2 + STEPS); value2 = Math.min(MAX, value2 + STEPS);
} }
controlValue = value2;
updateButtonsVisibility();
$text.textContent = renderTextValue(value2); $text.textContent = renderTextValue(value2);
$range && ($range.value = value2.toString()); $range && ($range.value = value2.toString());
isHolding = false; isHolding = false;
@ -907,17 +913,18 @@ class SettingElement {
}; };
const onContextMenu = (e) => e.preventDefault(); const onContextMenu = (e) => e.preventDefault();
$wrapper.setValue = (value2) => { $wrapper.setValue = (value2) => {
controlValue = parseInt(value2);
$text.textContent = renderTextValue(value2); $text.textContent = renderTextValue(value2);
$range && ($range.value = value2); $range && ($range.value = value2);
}; };
$decBtn.addEventListener("click", onClick); $btnDec.addEventListener("click", onClick);
$decBtn.addEventListener("pointerdown", onMouseDown); $btnDec.addEventListener("pointerdown", onMouseDown);
$decBtn.addEventListener("pointerup", onMouseUp); $btnDec.addEventListener("pointerup", onMouseUp);
$decBtn.addEventListener("contextmenu", onContextMenu); $btnDec.addEventListener("contextmenu", onContextMenu);
$incBtn.addEventListener("click", onClick); $btnInc.addEventListener("click", onClick);
$incBtn.addEventListener("pointerdown", onMouseDown); $btnInc.addEventListener("pointerdown", onMouseDown);
$incBtn.addEventListener("pointerup", onMouseUp); $btnInc.addEventListener("pointerup", onMouseUp);
$incBtn.addEventListener("contextmenu", onContextMenu); $btnInc.addEventListener("contextmenu", onContextMenu);
return $wrapper; return $wrapper;
} }
static #METHOD_MAP = { static #METHOD_MAP = {
@ -1674,7 +1681,11 @@ class Preferences {
min: 0, min: 0,
max: 10, max: 10,
params: { params: {
hideSlider: true hideSlider: true,
customTextValue: (value) => {
value = parseInt(value);
return value === 0 ? t("off") : value.toString();
}
} }
}, },
[PrefKey.VIDEO_RATIO]: { [PrefKey.VIDEO_RATIO]: {