From a2db2a0fe1b8e31c8993ef9575d2a106afffcdf1 Mon Sep 17 00:00:00 2001 From: Step7750 Date: Thu, 4 Apr 2024 08:59:47 -0600 Subject: [PATCH] Allows Remotely Disabling Auto Tracker Banner --- src/lib/bridge/handlers/handlers.ts | 2 ++ src/lib/bridge/handlers/meta_settings.ts | 18 ++++++++++++++++++ src/lib/bridge/handlers/types.ts | 1 + src/lib/components/trade_offers/auto_track.ts | 8 +++++++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/lib/bridge/handlers/meta_settings.ts diff --git a/src/lib/bridge/handlers/handlers.ts b/src/lib/bridge/handlers/handlers.ts index 4f9f84ee..6a694c71 100644 --- a/src/lib/bridge/handlers/handlers.ts +++ b/src/lib/bridge/handlers/handlers.ts @@ -14,6 +14,7 @@ import {AnnotateOffer} from './annotate_offer'; import {ExtensionVersion} from './extension_version'; import {SendCookies} from './send_cookies'; import {HasPermissions} from './has_permissions'; +import {MetaSettings} from './meta_settings'; export const HANDLERS_MAP: {[key in RequestType]: RequestHandler} = { [RequestType.EXECUTE_SCRIPT_ON_PAGE]: ExecuteScriptOnPage, @@ -30,4 +31,5 @@ export const HANDLERS_MAP: {[key in RequestType]: RequestHandler} = { [RequestType.EXTENSION_VERSION]: ExtensionVersion, [RequestType.SEND_COOKIES]: SendCookies, [RequestType.HAS_PERMISSIONS]: HasPermissions, + [RequestType.META_SETTINGS]: MetaSettings, }; diff --git a/src/lib/bridge/handlers/meta_settings.ts b/src/lib/bridge/handlers/meta_settings.ts new file mode 100644 index 00000000..b3c5d477 --- /dev/null +++ b/src/lib/bridge/handlers/meta_settings.ts @@ -0,0 +1,18 @@ +import {EmptyRequestHandler} from './main'; +import {RequestType} from './types'; + +export interface MetaSettingsResponse { + enable_auto_trade: boolean; +} + +export const MetaSettings = new EmptyRequestHandler(RequestType.META_SETTINGS, async (req) => { + const resp = await fetch(`https://csfloat.com/api/v1/meta/extension`, { + credentials: 'include', + }); + + if (resp.status !== 200) { + throw new Error('invalid status'); + } + + return resp.json() as Promise; +}); diff --git a/src/lib/bridge/handlers/types.ts b/src/lib/bridge/handlers/types.ts index e9a5d3cd..d4d275f4 100644 --- a/src/lib/bridge/handlers/types.ts +++ b/src/lib/bridge/handlers/types.ts @@ -13,4 +13,5 @@ export enum RequestType { EXTENSION_VERSION, SEND_COOKIES, HAS_PERMISSIONS, + META_SETTINGS, } diff --git a/src/lib/components/trade_offers/auto_track.ts b/src/lib/components/trade_offers/auto_track.ts index 5859edb5..ab1971f6 100644 --- a/src/lib/components/trade_offers/auto_track.ts +++ b/src/lib/components/trade_offers/auto_track.ts @@ -7,6 +7,7 @@ import {ClientSend} from '../../bridge/client'; import {state} from 'lit/decorators.js'; import {FetchPendingTrades} from '../../bridge/handlers/fetch_pending_trades'; import {HasPermissions} from '../../bridge/handlers/has_permissions'; +import {MetaSettings} from '../../bridge/handlers/meta_settings'; @CustomElement() @InjectAfter( @@ -56,6 +57,11 @@ export class AutoTrackWidget extends FloatElement { super.connectedCallback(); try { + const meta = await ClientSend(MetaSettings, {}); + if (!meta.enable_auto_trade) { + return; + } + await ClientSend(FetchPendingTrades, {}); const hasPermissions = await ClientSend(HasPermissions, {permissions: ['cookies', 'alarms']}); @@ -63,7 +69,7 @@ export class AutoTrackWidget extends FloatElement { this.show = true; } } catch (e) { - console.info('user is not logged into CSFloat'); + console.info('user is not logged into CSFloat or something went wrong'); } }