mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-07-06 06:11:43 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
033ac31333 | |||
1f754d4a1d | |||
0d39ccf8bf | |||
966d7f2f6c | |||
fdbf618253 | |||
aaa7612293 |
@ -1,5 +1,5 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Better xCloud
|
// @name Better xCloud
|
||||||
// @namespace https://github.com/redphx
|
// @namespace https://github.com/redphx
|
||||||
// @version 3.1.2
|
// @version 3.1.3
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Better xCloud
|
// @name Better xCloud
|
||||||
// @namespace https://github.com/redphx
|
// @namespace https://github.com/redphx
|
||||||
// @version 3.1.2
|
// @version 3.1.3
|
||||||
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||||
// @author redphx
|
// @author redphx
|
||||||
// @license MIT
|
// @license MIT
|
||||||
@ -13,7 +13,7 @@
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const SCRIPT_VERSION = '3.1.2';
|
const SCRIPT_VERSION = '3.1.3';
|
||||||
const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud';
|
const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud';
|
||||||
|
|
||||||
const ENABLE_XCLOUD_LOGGER = false;
|
const ENABLE_XCLOUD_LOGGER = false;
|
||||||
@ -49,6 +49,10 @@ const BxEvent = {
|
|||||||
STREAM_STARTED: 'bx-stream-started',
|
STREAM_STARTED: 'bx-stream-started',
|
||||||
STREAM_PLAYING: 'bx-stream-playing',
|
STREAM_PLAYING: 'bx-stream-playing',
|
||||||
STREAM_STOPPED: 'bx-stream-stopped',
|
STREAM_STOPPED: 'bx-stream-stopped',
|
||||||
|
STREAM_ERROR_PAGE: 'bx-stream-error-page',
|
||||||
|
|
||||||
|
STREAM_MENU_SHOWN: 'bx-stream-menu-shown',
|
||||||
|
STREAM_MENU_HIDDEN: 'bx-stream-menu-hidden',
|
||||||
|
|
||||||
STREAM_WEBRTC_CONNECTED: 'bx-stream-webrtc-connected',
|
STREAM_WEBRTC_CONNECTED: 'bx-stream-webrtc-connected',
|
||||||
STREAM_WEBRTC_DISCONNECTED: 'bx-stream-webrtc-disconnected',
|
STREAM_WEBRTC_DISCONNECTED: 'bx-stream-webrtc-disconnected',
|
||||||
@ -58,6 +62,11 @@ const BxEvent = {
|
|||||||
DATA_CHANNEL_CREATED: 'bx-data-channel-created',
|
DATA_CHANNEL_CREATED: 'bx-data-channel-created',
|
||||||
|
|
||||||
dispatch: (target, eventName, data) => {
|
dispatch: (target, eventName, data) => {
|
||||||
|
if (!eventName) {
|
||||||
|
alert('BxEvent.dispatch(): eventName is null');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const event = new Event(eventName);
|
const event = new Event(eventName);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -3431,14 +3440,12 @@ class TouchController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static #show() {
|
static #show() {
|
||||||
document.querySelector('#BabylonCanvasContainer-main').parentElement.classList.remove('bx-gone');
|
document.querySelector('#BabylonCanvasContainer-main').parentElement.classList.remove('bx-offscreen');
|
||||||
// TouchController.loadCustomLayout(GAME_XBOX_TITLE_ID, TouchController.#currentLayoutId, 0);
|
|
||||||
TouchController.#showing = true;
|
TouchController.#showing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #hide() {
|
static #hide() {
|
||||||
document.querySelector('#BabylonCanvasContainer-main').parentElement.classList.add('bx-gone');
|
document.querySelector('#BabylonCanvasContainer-main').parentElement.classList.add('bx-offscreen');
|
||||||
// TouchController.#dispatchMessage(TouchController.#EVENT_HIDE_CONTROLLER);
|
|
||||||
TouchController.#showing = false;
|
TouchController.#showing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3489,11 +3496,7 @@ class TouchController {
|
|||||||
url += `${xboxTitleId}.json`;
|
url += `${xboxTitleId}.json`;
|
||||||
}
|
}
|
||||||
NATIVE_FETCH(url)
|
NATIVE_FETCH(url)
|
||||||
.then(resp => resp.json(), () => {
|
.then(resp => resp.json())
|
||||||
TouchController.#customLayouts[xboxTitleId] = null;
|
|
||||||
// Wait for BX_EXPOSED.touch_layout_manager
|
|
||||||
setTimeout(() => dispatchLayouts(null), 1000);
|
|
||||||
})
|
|
||||||
.then(json => {
|
.then(json => {
|
||||||
// Normalize data
|
// Normalize data
|
||||||
const schema_version = json.schema_version || 1;
|
const schema_version = json.schema_version || 1;
|
||||||
@ -3515,6 +3518,11 @@ class TouchController {
|
|||||||
|
|
||||||
// Wait for BX_EXPOSED.touch_layout_manager
|
// Wait for BX_EXPOSED.touch_layout_manager
|
||||||
setTimeout(() => dispatchLayouts(json), 1000);
|
setTimeout(() => dispatchLayouts(json), 1000);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
TouchController.#customLayouts[xboxTitleId] = null;
|
||||||
|
// Wait for BX_EXPOSED.touch_layout_manager
|
||||||
|
setTimeout(() => dispatchLayouts(null), 1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4781,8 +4789,8 @@ class MkbHandler {
|
|||||||
this.#$message.addEventListener('click', this.#onActivatePointerLock);
|
this.#$message.addEventListener('click', this.#onActivatePointerLock);
|
||||||
document.documentElement.appendChild(this.#$message);
|
document.documentElement.appendChild(this.#$message);
|
||||||
|
|
||||||
window.addEventListener('bx-stream-menu-shown', this.#onStreamMenuShown);
|
window.addEventListener(BxEvent.STREAM_MENU_SHOWN, this.#onStreamMenuShown);
|
||||||
window.addEventListener('bx-stream-menu-hidden', this.#onStreamMenuHidden);
|
window.addEventListener(BxEvent.STREAM_MENU_HIDDEN, this.#onStreamMenuHidden);
|
||||||
|
|
||||||
this.#waitForPointerLock(true);
|
this.#waitForPointerLock(true);
|
||||||
}
|
}
|
||||||
@ -4799,8 +4807,8 @@ class MkbHandler {
|
|||||||
document.removeEventListener('pointerlockchange', this.#onPointerLockChange);
|
document.removeEventListener('pointerlockchange', this.#onPointerLockChange);
|
||||||
document.removeEventListener('pointerlockerror', this.#onPointerLockError);
|
document.removeEventListener('pointerlockerror', this.#onPointerLockError);
|
||||||
|
|
||||||
window.removeEventListener('bx-stream-menu-shown', this.#onStreamMenuShown);
|
window.removeEventListener(BxEvent.STREAM_MENU_SHOWN, this.#onStreamMenuShown);
|
||||||
window.removeEventListener('bx-stream-menu-hidden', this.#onStreamMenuHidden);
|
window.removeEventListener(BxEvent.STREAM_MENU_HIDDEN, this.#onStreamMenuHidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
start = () => {
|
start = () => {
|
||||||
@ -9790,13 +9798,13 @@ function injectStreamMenuButtons() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
item.removedNodes.forEach($node => {
|
item.removedNodes.forEach($node => {
|
||||||
if (!$node.className || !$node.className.startsWith) {
|
if (!$node || !$node.className || !$node.className.startsWith) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($node.className.startsWith('StreamMenu')) {
|
if ($node.className.startsWith('StreamMenu')) {
|
||||||
if (!document.querySelector('div[class^=PureInStreamConfirmationModal]')) {
|
if (!document.querySelector('div[class^=PureInStreamConfirmationModal]')) {
|
||||||
window.dispatchEvent(new Event('bx-stream-menu-hidden'));
|
BxEvent.dispatch(window, BxEvent.STREAM_MENU_HIDDEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -9806,6 +9814,12 @@ function injectStreamMenuButtons() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error Page: .PureErrorPage.ErrorScreen
|
||||||
|
if ($node.className.includes('PureErrorPage')) {
|
||||||
|
BxEvent.dispatch(window, BxEvent.STREAM_ERROR_PAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (PREF_DISABLE_FEEDBACK_DIALOG && $node.className.startsWith('PostStreamFeedbackScreen')) {
|
if (PREF_DISABLE_FEEDBACK_DIALOG && $node.className.startsWith('PostStreamFeedbackScreen')) {
|
||||||
const $btnClose = $node.querySelector('button');
|
const $btnClose = $node.querySelector('button');
|
||||||
$btnClose && $btnClose.click();
|
$btnClose && $btnClose.click();
|
||||||
@ -9814,7 +9828,7 @@ function injectStreamMenuButtons() {
|
|||||||
|
|
||||||
// Render badges
|
// Render badges
|
||||||
if ($node.className.startsWith('StreamMenu')) {
|
if ($node.className.startsWith('StreamMenu')) {
|
||||||
window.dispatchEvent(new Event('bx-stream-menu-shown'));
|
BxEvent.dispatch(window, BxEvent.STREAM_MENU_SHOWN);
|
||||||
|
|
||||||
// Hide Quick bar when closing HUD
|
// Hide Quick bar when closing HUD
|
||||||
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]');
|
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]');
|
||||||
@ -10456,14 +10470,10 @@ function patchHistoryMethod(type) {
|
|||||||
|
|
||||||
|
|
||||||
function onHistoryChanged(e) {
|
function onHistoryChanged(e) {
|
||||||
if (e.arguments && e.arguments[0] && e.arguments[0].origin === 'better-xcloud') {
|
if (e && e.arguments && e.arguments[0] && e.arguments[0].origin === 'better-xcloud') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop MKB listeners
|
|
||||||
MkbHandler.INSTANCE.destroy();
|
|
||||||
|
|
||||||
IS_PLAYING = false;
|
|
||||||
setTimeout(RemotePlay.detect, 10);
|
setTimeout(RemotePlay.detect, 10);
|
||||||
|
|
||||||
const $settings = document.querySelector('.better_xcloud_settings');
|
const $settings = document.querySelector('.better_xcloud_settings');
|
||||||
@ -10471,28 +10481,10 @@ function onHistoryChanged(e) {
|
|||||||
$settings.classList.add('bx-gone');
|
$settings.classList.add('bx-gone');
|
||||||
}
|
}
|
||||||
|
|
||||||
const $quickBar = document.querySelector('.bx-quick-settings-bar');
|
|
||||||
if ($quickBar) {
|
|
||||||
$quickBar.classList.add('bx-gone');
|
|
||||||
}
|
|
||||||
|
|
||||||
STREAM_AUDIO_GAIN_NODE = null;
|
|
||||||
$STREAM_VIDEO = null;
|
|
||||||
StreamStats.onStoppedPlaying();
|
|
||||||
|
|
||||||
const $screenshotBtn = document.querySelector('.bx-screenshot-button');
|
|
||||||
if ($screenshotBtn) {
|
|
||||||
$screenshotBtn.style = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseCursorHider.stop();
|
|
||||||
TouchController.reset();
|
|
||||||
|
|
||||||
LoadingScreen.reset();
|
LoadingScreen.reset();
|
||||||
|
|
||||||
GamepadHandler.stopPolling();
|
|
||||||
|
|
||||||
setTimeout(checkHeader, 2000);
|
setTimeout(checkHeader, 2000);
|
||||||
|
|
||||||
|
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -10587,6 +10579,40 @@ window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener(BxEvent.STREAM_ERROR_PAGE, e => {
|
||||||
|
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener(BxEvent.STREAM_STOPPED, e => {
|
||||||
|
if (!IS_PLAYING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IS_PLAYING = false;
|
||||||
|
|
||||||
|
// Stop MKB listeners
|
||||||
|
MkbHandler.INSTANCE.destroy();
|
||||||
|
|
||||||
|
const $quickBar = document.querySelector('.bx-quick-settings-bar');
|
||||||
|
if ($quickBar) {
|
||||||
|
$quickBar.classList.add('bx-gone');
|
||||||
|
}
|
||||||
|
|
||||||
|
STREAM_AUDIO_GAIN_NODE = null;
|
||||||
|
$STREAM_VIDEO = null;
|
||||||
|
StreamStats.onStoppedPlaying();
|
||||||
|
|
||||||
|
const $screenshotBtn = document.querySelector('.bx-screenshot-button');
|
||||||
|
if ($screenshotBtn) {
|
||||||
|
$screenshotBtn.style = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseCursorHider.stop();
|
||||||
|
TouchController.reset();
|
||||||
|
|
||||||
|
GamepadHandler.stopPolling();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
PreloadedState.override();
|
PreloadedState.override();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user