mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-07 16:17:20 +02:00
Fix issue with <select multiple> and BxSelect element
This commit is contained in:
parent
6a8eecab06
commit
7db004ede3
27
dist/better-xcloud.user.js
vendored
27
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.4.1
|
// @version 5.4.2-beta
|
||||||
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||||
// @author redphx
|
// @author redphx
|
||||||
// @license MIT
|
// @license MIT
|
||||||
@ -138,7 +138,7 @@ function deepClone(obj) {
|
|||||||
return {};
|
return {};
|
||||||
return JSON.parse(JSON.stringify(obj));
|
return JSON.parse(JSON.stringify(obj));
|
||||||
}
|
}
|
||||||
var SCRIPT_VERSION = "5.4.1", AppInterface = window.AppInterface;
|
var SCRIPT_VERSION = "5.4.2-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,
|
||||||
@ -3388,7 +3388,7 @@ class BxSelectElement {
|
|||||||
tabindex: 0
|
tabindex: 0
|
||||||
}
|
}
|
||||||
}), isMultiple = $select.multiple;
|
}), isMultiple = $select.multiple;
|
||||||
let $checkBox, $label, $content;
|
let $checkBox, $label, visibleIndex = $select.selectedIndex, $content;
|
||||||
if (isMultiple)
|
if (isMultiple)
|
||||||
$content = CE("button", {
|
$content = CE("button", {
|
||||||
class: "bx-select-value bx-focusable",
|
class: "bx-select-value bx-focusable",
|
||||||
@ -3396,15 +3396,18 @@ class BxSelectElement {
|
|||||||
}, $checkBox = CE("input", { type: "checkbox" }), $label = CE("span", {}, "")), $content.addEventListener("click", (e) => {
|
}, $checkBox = CE("input", { type: "checkbox" }), $label = CE("span", {}, "")), $content.addEventListener("click", (e) => {
|
||||||
$checkBox.click();
|
$checkBox.click();
|
||||||
}), $checkBox.addEventListener("input", (e) => {
|
}), $checkBox.addEventListener("input", (e) => {
|
||||||
const $option = getOptionAtIndex($select.selectedIndex);
|
const $option = getOptionAtIndex(visibleIndex);
|
||||||
$option && ($option.selected = e.target.checked), $select.dispatchEvent(new Event("input"));
|
$option && ($option.selected = e.target.checked), $select.dispatchEvent(new Event("input"));
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
$content = CE("div", {}, $label = CE("label", { for: $select.id + "_checkbox" }, ""));
|
$content = CE("div", {}, $label = CE("label", { for: $select.id + "_checkbox" }, ""));
|
||||||
const getOptionAtIndex = (index) => {
|
const getOptionAtIndex = (index) => {
|
||||||
return Array.from($select.querySelectorAll("option"))[index];
|
return Array.from($select.querySelectorAll("option"))[index];
|
||||||
}, render = () => {
|
}, render = (e) => {
|
||||||
const visibleIndex = normalizeIndex($select.selectedIndex), $option = getOptionAtIndex(visibleIndex);
|
if (e && e.manualTrigger)
|
||||||
|
visibleIndex = $select.selectedIndex;
|
||||||
|
visibleIndex = normalizeIndex(visibleIndex);
|
||||||
|
const $option = getOptionAtIndex(visibleIndex);
|
||||||
let content = "";
|
let content = "";
|
||||||
if ($option)
|
if ($option)
|
||||||
if (content = $option.textContent || "", content && $option.parentElement.tagName === "OPTGROUP") {
|
if (content = $option.textContent || "", content && $option.parentElement.tagName === "OPTGROUP") {
|
||||||
@ -3422,13 +3425,16 @@ class BxSelectElement {
|
|||||||
}, normalizeIndex = (index) => {
|
}, normalizeIndex = (index) => {
|
||||||
return Math.min(Math.max(index, 0), $select.querySelectorAll("option").length - 1);
|
return Math.min(Math.max(index, 0), $select.querySelectorAll("option").length - 1);
|
||||||
}, onPrevNext = (e) => {
|
}, onPrevNext = (e) => {
|
||||||
const goNext = e.target === $btnNext, currentIndex = $select.selectedIndex;
|
const goNext = e.target === $btnNext, currentIndex = visibleIndex;
|
||||||
let newIndex = goNext ? currentIndex + 1 : currentIndex - 1;
|
let newIndex = goNext ? currentIndex + 1 : currentIndex - 1;
|
||||||
if (newIndex = normalizeIndex(newIndex), !isMultiple && newIndex !== currentIndex)
|
if (newIndex = normalizeIndex(newIndex), visibleIndex = newIndex, !isMultiple && newIndex !== currentIndex)
|
||||||
$select.selectedIndex = newIndex;
|
$select.selectedIndex = newIndex;
|
||||||
|
if (isMultiple)
|
||||||
|
render();
|
||||||
|
else
|
||||||
$select.dispatchEvent(new Event("input"));
|
$select.dispatchEvent(new Event("input"));
|
||||||
};
|
};
|
||||||
return $select.addEventListener("input", (e) => render()), $btnPrev.addEventListener("click", onPrevNext), $btnNext.addEventListener("click", onPrevNext), new MutationObserver((mutationList, observer2) => {
|
return $select.addEventListener("input", render), $btnPrev.addEventListener("click", onPrevNext), $btnNext.addEventListener("click", onPrevNext), new MutationObserver((mutationList, observer2) => {
|
||||||
mutationList.forEach((mutation) => {
|
mutationList.forEach((mutation) => {
|
||||||
if (mutation.type === "childList" || mutation.type === "attributes")
|
if (mutation.type === "childList" || mutation.type === "attributes")
|
||||||
render();
|
render();
|
||||||
@ -4509,7 +4515,8 @@ class ControllerShortcut {
|
|||||||
for (button in ControllerShortcut.#$selectActions) {
|
for (button in ControllerShortcut.#$selectActions) {
|
||||||
const $select = ControllerShortcut.#$selectActions[button];
|
const $select = ControllerShortcut.#$selectActions[button];
|
||||||
$select.value = actions[button] || "", BxEvent.dispatch($select, "input", {
|
$select.value = actions[button] || "", BxEvent.dispatch($select, "input", {
|
||||||
ignoreOnChange: !0
|
ignoreOnChange: !0,
|
||||||
|
manualTrigger: !0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,7 @@ export class ControllerShortcut {
|
|||||||
|
|
||||||
BxEvent.dispatch($select, 'input', {
|
BxEvent.dispatch($select, 'input', {
|
||||||
ignoreOnChange: true,
|
ignoreOnChange: true,
|
||||||
|
manualTrigger: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ export class BxSelectElement {
|
|||||||
const isMultiple = $select.multiple;
|
const isMultiple = $select.multiple;
|
||||||
let $checkBox: HTMLInputElement;
|
let $checkBox: HTMLInputElement;
|
||||||
let $label: HTMLElement;
|
let $label: HTMLElement;
|
||||||
|
let visibleIndex = $select.selectedIndex;
|
||||||
|
|
||||||
let $content;
|
let $content;
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ export class BxSelectElement {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$checkBox.addEventListener('input', e => {
|
$checkBox.addEventListener('input', e => {
|
||||||
const $option = getOptionAtIndex($select.selectedIndex);
|
const $option = getOptionAtIndex(visibleIndex);
|
||||||
$option && ($option.selected = (e.target as HTMLInputElement).checked);
|
$option && ($option.selected = (e.target as HTMLInputElement).checked);
|
||||||
|
|
||||||
$select.dispatchEvent(new Event('input'));
|
$select.dispatchEvent(new Event('input'));
|
||||||
@ -57,11 +58,13 @@ export class BxSelectElement {
|
|||||||
return options[index];
|
return options[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
const render = () => {
|
const render = (e?: Event) => {
|
||||||
// console.log('options', this.options, 'selectedIndices', this.selectedIndices, 'selectedOptions', this.selectedOptions);
|
// console.log('options', this.options, 'selectedIndices', this.selectedIndices, 'selectedOptions', this.selectedOptions);
|
||||||
|
if (e && (e as any).manualTrigger) {
|
||||||
|
visibleIndex = $select.selectedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
const visibleIndex = normalizeIndex($select.selectedIndex);
|
visibleIndex = normalizeIndex(visibleIndex);
|
||||||
|
|
||||||
const $option = getOptionAtIndex(visibleIndex);
|
const $option = getOptionAtIndex(visibleIndex);
|
||||||
let content = '';
|
let content = '';
|
||||||
if ($option) {
|
if ($option) {
|
||||||
@ -107,18 +110,23 @@ export class BxSelectElement {
|
|||||||
const onPrevNext = (e: Event) => {
|
const onPrevNext = (e: Event) => {
|
||||||
const goNext = e.target === $btnNext;
|
const goNext = e.target === $btnNext;
|
||||||
|
|
||||||
const currentIndex = $select.selectedIndex;
|
const currentIndex = visibleIndex;
|
||||||
let newIndex = goNext ? currentIndex + 1 : currentIndex - 1;
|
let newIndex = goNext ? currentIndex + 1 : currentIndex - 1;
|
||||||
newIndex = normalizeIndex(newIndex);
|
newIndex = normalizeIndex(newIndex);
|
||||||
|
|
||||||
|
visibleIndex = newIndex;
|
||||||
if (!isMultiple && newIndex !== currentIndex) {
|
if (!isMultiple && newIndex !== currentIndex) {
|
||||||
$select.selectedIndex = newIndex;
|
$select.selectedIndex = newIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isMultiple) {
|
||||||
|
render();
|
||||||
|
} else {
|
||||||
$select.dispatchEvent(new Event('input'));
|
$select.dispatchEvent(new Event('input'));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$select.addEventListener('input', e => render());
|
$select.addEventListener('input', render);
|
||||||
$btnPrev.addEventListener('click', onPrevNext);
|
$btnPrev.addEventListener('click', onPrevNext);
|
||||||
$btnNext.addEventListener('click', onPrevNext);
|
$btnNext.addEventListener('click', onPrevNext);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user