Update better-xcloud.user.js

This commit is contained in:
redphx 2024-09-04 07:31:40 +07:00
parent 7310700dbb
commit 110106aa97

View File

@ -8057,24 +8057,45 @@ class GameTile {
} }
class ProductDetailsPage { class ProductDetailsPage {
static $btnShortcut = createButton({ static $btnShortcut = AppInterface && createButton({
classes: ["bx-button-shortcut"], classes: ["bx-button-shortcut"],
icon: BxIcon.CREATE_SHORTCUT, icon: BxIcon.CREATE_SHORTCUT,
label: t("create-shortcut"), label: t("create-shortcut"),
style: 32, style: 32,
tabIndex: 0, tabIndex: 0,
onClick: (e) => { onClick: (e) => {
AppInterface && AppInterface.createShortcut(window.location.pathname.substring(6)); AppInterface.createShortcut(window.location.pathname.substring(6));
} }
}); });
static shortcutTimeoutId = null; static $btnWallpaper = AppInterface && createButton({
static injectShortcutButton() { classes: ["bx-button-shortcut"],
if (!AppInterface || BX_FLAGS.DeviceInfo.deviceType !== "android") icon: BxIcon.DOWNLOAD,
label: t("wallpaper"),
style: 32,
tabIndex: 0,
onClick: async (e) => {
try {
const matches = /\/games\/(?<titleSlug>[^\/]+)\/(?<productId>\w+)/.exec(window.location.pathname);
if (!matches?.groups)
return; return;
ProductDetailsPage.shortcutTimeoutId && clearTimeout(ProductDetailsPage.shortcutTimeoutId), ProductDetailsPage.shortcutTimeoutId = window.setTimeout(() => { const titleSlug = matches.groups.titleSlug, productId = matches.groups.productId;
AppInterface.downloadWallpapers(titleSlug, productId);
} catch (e2) {
}
}
});
static injectTimeoutId = null;
static injectButtons() {
if (!AppInterface)
return;
ProductDetailsPage.injectTimeoutId && clearTimeout(ProductDetailsPage.injectTimeoutId), ProductDetailsPage.injectTimeoutId = window.setTimeout(() => {
const $container = document.querySelector("div[class*=ActionButtons-module__container]"); const $container = document.querySelector("div[class*=ActionButtons-module__container]");
if ($container) if ($container && $container.parentElement) {
$container.parentElement?.appendChild(ProductDetailsPage.$btnShortcut); const fragment = document.createDocumentFragment();
if (BX_FLAGS.DeviceInfo.deviceType === "android")
fragment.appendChild(ProductDetailsPage.$btnShortcut);
fragment.appendChild(ProductDetailsPage.$btnWallpaper), $container.parentElement.appendChild(fragment);
}
}, 500); }, 500);
} }
} }
@ -8377,7 +8398,7 @@ window.addEventListener(BxEvent.STREAM_ERROR_PAGE, (e) => {
}); });
window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, (e) => { window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, (e) => {
if (e.component === "product-details") if (e.component === "product-details")
ProductDetailsPage.injectShortcutButton(); ProductDetailsPage.injectButtons();
}); });
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, (e) => { window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, (e) => {
const dataChannel = e.dataChannel; const dataChannel = e.dataChannel;