diff --git a/src/index.ts b/src/index.ts index bd77bfb..fe6dce3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -245,7 +245,7 @@ window.addEventListener(BxEvent.STREAM_ERROR_PAGE, e => { window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, e => { const component = (e as any).component; if (component === 'product-details') { - ProductDetailsPage.injectShortcutButton(); + ProductDetailsPage.injectButtons(); } }); diff --git a/src/modules/ui/product-details.ts b/src/modules/ui/product-details.ts index b9d1bfd..91f467c 100644 --- a/src/modules/ui/product-details.ts +++ b/src/modules/ui/product-details.ts @@ -5,30 +5,60 @@ import { ButtonStyle, createButton } from "@/utils/html"; import { t } from "@/utils/translation"; export class ProductDetailsPage { - private static $btnShortcut = createButton({ + private static $btnShortcut = AppInterface && createButton({ classes: ['bx-button-shortcut'], icon: BxIcon.CREATE_SHORTCUT, label: t('create-shortcut'), style: ButtonStyle.FOCUSABLE, tabIndex: 0, onClick: e => { - AppInterface && AppInterface.createShortcut(window.location.pathname.substring(6)); + AppInterface.createShortcut(window.location.pathname.substring(6)); }, }); - private static shortcutTimeoutId: number | null = null; + private static $btnWallpaper = AppInterface && createButton({ + classes: ['bx-button-shortcut'], + icon: BxIcon.DOWNLOAD, + label: t('wallpaper'), + style: ButtonStyle.FOCUSABLE, + tabIndex: 0, + onClick: async e => { + try { + const matches = /\/games\/(?[^\/]+)\/(?\w+)/.exec(window.location.pathname); + if (!matches?.groups) { + return; + } - static injectShortcutButton() { - if (!AppInterface || BX_FLAGS.DeviceInfo.deviceType !== 'android') { + const titleSlug = matches.groups.titleSlug; + const productId = matches.groups.productId; + AppInterface.downloadWallpapers(titleSlug, productId); + } catch (e) {} + }, + }); + + private static injectTimeoutId: number | null = null; + + static injectButtons() { + if (!AppInterface) { return; } - ProductDetailsPage.shortcutTimeoutId && clearTimeout(ProductDetailsPage.shortcutTimeoutId); - ProductDetailsPage.shortcutTimeoutId = window.setTimeout(() => { + ProductDetailsPage.injectTimeoutId && clearTimeout(ProductDetailsPage.injectTimeoutId); + ProductDetailsPage.injectTimeoutId = window.setTimeout(() => { // Find action buttons container const $container = document.querySelector('div[class*=ActionButtons-module__container]'); - if ($container) { - $container.parentElement?.appendChild(ProductDetailsPage.$btnShortcut); + if ($container && $container.parentElement) { + const fragment = document.createDocumentFragment(); + + // Shortcut button + if (BX_FLAGS.DeviceInfo.deviceType === 'android') { + fragment.appendChild(ProductDetailsPage.$btnShortcut); + } + + // Wallpaper button + fragment.appendChild(ProductDetailsPage.$btnWallpaper); + + $container.parentElement.appendChild(fragment); } }, 500); } diff --git a/src/utils/true-achievements.ts b/src/utils/true-achievements.ts index 289dcb3..bc4e476 100644 --- a/src/utils/true-achievements.ts +++ b/src/utils/true-achievements.ts @@ -1,4 +1,3 @@ -import { BX_FLAGS } from "./bx-flags"; import { AppInterface, STATES } from "./global"; import { ButtonStyle, CE, createButton, getReactProps } from "./html"; import { t } from "./translation";