From b0e23ca335584a9d3ee3a02fff947d4f50340211 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sun, 30 Jul 2023 22:03:25 +0700 Subject: [PATCH] Hold the "Quit game" button for 1s to refresh the stream (#43) * Hold "Quit game" button to refresh the stream * Fix problem with touch screen * Another fix --- better-xcloud.user.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/better-xcloud.user.js b/better-xcloud.user.js index e58f689..c928491 100644 --- a/better-xcloud.user.js +++ b/better-xcloud.user.js @@ -22,6 +22,10 @@ var $STREAM_VIDEO; var $SCREENSHOT_CANVAS; var GAME_TITLE_ID; +// Credit: https://www.iconfinder.com/iconsets/user-interface-outline-27 +const ICON_VIDEO_SETTINGS = ''; +const ICON_STREAM_STATS = ''; + class MouseCursorHider { static #timeout; @@ -1784,8 +1788,6 @@ function injectVideoSettingsButton() { return; } - // Credit: https://www.iconfinder.com/iconsets/user-interface-outline-27 - const ICON_VIDEO_SETTINGS = ''; // Create Video Settings button const $btnVideoSettings = cloneStreamMenuButton($orgButton, 'Video settings', ICON_VIDEO_SETTINGS); $btnVideoSettings.addEventListener('click', e => { @@ -1811,7 +1813,6 @@ function injectVideoSettingsButton() { $quickBar.style.display = 'none'; }); - const ICON_STREAM_STATS = ''; // Create Stream Stats button const $btnStreamStats = cloneStreamMenuButton($orgButton, 'Stream stats', ICON_STREAM_STATS); $btnStreamStats.addEventListener('click', e => { @@ -1827,6 +1828,34 @@ function injectVideoSettingsButton() { // Insert after Video Settings button $orgButton.parentElement.insertBefore($btnStreamStats, $btnVideoSettings); + // Get "Quit game" button + const $btnQuit = $orgButton.parentElement.querySelector('button:last-of-type'); + + let isHolding = false; + let holdTimeout; + const onMouseDown = e => { + isHolding = false; + holdTimeout = setTimeout(() => { + isHolding = true; + }, 750); + }; + const onMouseUp = e => { + holdTimeout && clearTimeout(holdTimeout); + + if (isHolding) { + e.preventDefault(); + e.stopPropagation(); + confirm('Do you want to refresh the stream?') && window.location.reload(); + } + isHolding = false; + }; + + $btnQuit.addEventListener('mousedown', onMouseDown); + $btnQuit.addEventListener('click', onMouseUp); + + $btnQuit.addEventListener('touchstart', onMouseDown); + $btnQuit.addEventListener('touchend', onMouseUp); + // Render stream badges const $menu = document.querySelector('div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module]'); $menu.appendChild(await StreamBadges.render());