Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/background/Api.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import browser from "webextension-polyfill";
import {type GameIdLookupResponse, type GameOverviewResponse} from "../common/_types";
import SteamId from "../common/SteamId";
import {getCountry} from "../common/Utils";
import Config from "../config";

async function gameIdLookup(steamId: SteamId): Promise<null|string> {
const response = await fetch("https://api.isthereanydeal.com/unstable/id-lookup/game/v1", {
method: "POST",
body: JSON.stringify([steamId.toString()])
});
const response = await fetch("https://api.isthereanydeal.com/games/lookup/v1?"+(new URLSearchParams({
key: Config.ITADApiKey,
appid: steamId.id.toString(),
})));

if (response.ok) {
let json = await response.json();
if (json) {
json = json as GameIdLookupResponse;
return json[steamId.toString()] ?? null;
return json?.game?.id ?? null;
}
}
return null;
}

async function gameOverview(id: string): Promise<GameOverviewResponse|null> {
const country = ((await browser.storage.local.get("country"))?.country) ?? "US";

const country = await getCountry();
const response = await fetch("https://api.isthereanydeal.com/games/overview/v2?"+(new URLSearchParams({
key: Config.ITAD.apiKey,
key: Config.ITADApiKey,
country
})), {
method: "POST",
Expand Down
6 changes: 6 additions & 0 deletions src/common/Utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import browser from "webextension-polyfill";

export async function getCountry() {
const country = ((await browser.storage.local.get("country"))?.country) ?? "US";
return country;
}
9 changes: 8 additions & 1 deletion src/common/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,12 @@ export interface GameOverviewResponse {
}

export interface GameIdLookupResponse {
[steamId: string]: string
found: boolean,
game: {
id: string,
title: string,
slug: string,
mature: boolean,
type: string
}
}
3 changes: 2 additions & 1 deletion src/options/Options.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import {onMount} from "svelte";
import {getCountry} from "../common/Utils";
import browser from "webextension-polyfill";

const countries = [
Expand Down Expand Up @@ -256,7 +257,7 @@

let country = "US";
onMount(async () => {
country = ((await browser.storage.local.get("country"))?.country ?? "US") as unknown as string;
country = await getCountry() as unknown as string;
});

function handleSelection(e: Event) {
Expand Down