From bc5f18dee8827906a80883905780a31607bf6b19 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Wed, 1 Oct 2025 12:05:10 -0700 Subject: [PATCH] Hide skins & account login if in iframe (#2126) ## Description: CrazyGames doesn't allow purchase (must be integrated into their sdk), so disable it on iframe for now. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan --- src/client/AccountModal.ts | 6 +++++- src/client/Main.ts | 5 +++++ src/client/Utils.ts | 10 ++++++++++ src/client/graphics/layers/WinModal.ts | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/client/AccountModal.ts b/src/client/AccountModal.ts index b55929222..93bf0ff96 100644 --- a/src/client/AccountModal.ts +++ b/src/client/AccountModal.ts @@ -4,7 +4,7 @@ import { UserMeResponse } from "../core/ApiSchemas"; import "./components/Difficulties"; import "./components/PatternButton"; import { discordLogin, getApiBase, getUserMe, logOut } from "./jwt"; -import { translateText } from "./Utils"; +import { isInIframe, translateText } from "./Utils"; @customElement("account-modal") export class AccountModal extends LitElement { @@ -268,6 +268,10 @@ export class AccountButton extends LitElement { } render() { + if (isInIframe()) { + return html``; + } + if (!this.isVisible) { return html``; } diff --git a/src/client/Main.ts b/src/client/Main.ts index 9d4f1eba8..8b48f79cc 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -34,6 +34,7 @@ import { UsernameInput } from "./UsernameInput"; import { generateCryptoRandomUUID, incrementGamesPlayed, + isInIframe, translateText, } from "./Utils"; import "./components/NewsButton"; @@ -207,6 +208,10 @@ class Client { const patternButton = document.getElementById( "territory-patterns-input-preview-button", ); + if (isInIframe() && patternButton) { + patternButton.style.display = "none"; + } + this.patternsModal instanceof TerritoryPatternsModal; if (patternButton === null) throw new Error("territory-patterns-input-preview-button"); diff --git a/src/client/Utils.ts b/src/client/Utils.ts index 51dff4258..289d730d0 100644 --- a/src/client/Utils.ts +++ b/src/client/Utils.ts @@ -189,3 +189,13 @@ export function incrementGamesPlayed(): void { console.warn("Failed to increment games played in localStorage:", error); } } + +export function isInIframe(): boolean { + try { + return window.self !== window.top; + } catch (e) { + // If we can't access window.top due to cross-origin restrictions, + // we're definitely in an iframe + return true; + } +} diff --git a/src/client/graphics/layers/WinModal.ts b/src/client/graphics/layers/WinModal.ts index 1b030ea3d..850766bac 100644 --- a/src/client/graphics/layers/WinModal.ts +++ b/src/client/graphics/layers/WinModal.ts @@ -1,6 +1,6 @@ import { LitElement, TemplateResult, html } from "lit"; import { customElement, state } from "lit/decorators.js"; -import { translateText } from "../../../client/Utils"; +import { isInIframe, translateText } from "../../../client/Utils"; import { ColorPalette, Pattern } from "../../../core/CosmeticSchemas"; import { EventBus } from "../../../core/EventBus"; import { GameUpdateType } from "../../../core/game/GameUpdates"; @@ -95,7 +95,7 @@ export class WinModal extends LitElement implements Layer { } innerHtml() { - if (this.rand < 0.25) { + if (isInIframe() || this.rand < 0.25) { return this.steamWishlist(); } return this.renderPatternButton();