Skip to content

Commit

Permalink
Merge branch 'wip-4.0' into wip-4.0-mv3
Browse files Browse the repository at this point in the history
  • Loading branch information
tfedor committed Jun 18, 2024
2 parents c75caac + f89c8ae commit 7d9e02f
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 31 deletions.
40 changes: 30 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/js/Background/Modules/Community/SteamCommunityApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default class SteamCommunityApi extends Api implements MessageHandlerInte
return this.fetchJson(url, {credentials: "include"});
}

/**
* @return Promise<number> result size in kB
*/
private async fetchWorkshopFileSize(id: number): Promise<number> {
const url = this.getUrl("/sharedfiles/filedetails/", {id});
const html = await this.fetchText(url, {credentials: "include"});
Expand All @@ -50,7 +53,7 @@ export default class SteamCommunityApi extends Api implements MessageHandlerInte
throw new Error(`Invalid file size for item id "${id}"`);
}

return size*1000;
return size;
}

private async getWorkshopFileSize(id: number, preventFetch: boolean): Promise<number|null> {
Expand Down
16 changes: 13 additions & 3 deletions src/js/Background/Modules/Dom/NativeDomParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,26 @@ export default class NativeDomParser implements DomParserInterface {

parseWorkshopFileSize(html: string): number {
const details = this.dom(html).querySelector(".detailsStatRight")?.textContent;
if (!details || !details.includes("MB")) {
if (!details) {
return -1;
}

const size = parseFloat(details.replace(/,/g, ""));
const m = details.match(/(\d+(?:[.,]\d+)?) (MB|KB|B)/);
if (!m) {
return -2;
}

const size = parseFloat(m[1]!.replace(/,/g, ""));
if (Number.isNaN(size)) {
return -2;
}

return size*1000;
const unit = m[2]! as "MB"|"KB"|"B";
return size*({
"MB": 1000,
"KB": 1,
"B": 0.001
}[unit]);
}

parseReviews(html: string): TReview[] {
Expand Down
5 changes: 3 additions & 2 deletions src/js/Content/Features/Community/FCardExchangeLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ export default class FCardExchangeLinks<T extends CBadges|CGameCard> extends Fea

public override apply(): void | Promise<void> {
document.addEventListener("as_pageUpdated", () => this.onPageUpdated());
this.onPageUpdated();
}

private onPageUpdated() {
const ceImg = ExtensionResources.getURL("img/ico/steamcardexchange.png");

for (const node of document.querySelectorAll<HTMLElement>(".badge_row:not(.es-has-ce-link)")) {
let appid: number|undefined;
let appid: number|null = null;
if (this.context.appid) {
appid = this.context.appid;
} else {
const overlay = node.querySelector<HTMLAnchorElement>("a.badge_row_overlay");
if (overlay) {
AppId.fromGameCardUrl(overlay.href);
appid = AppId.fromGameCardUrl(overlay.href);
}
}
if (!appid) { continue; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ export default class FQuickSellOptions extends Feature<CInventory> {
price: String(sellPrice)
};

const result = await RequestData.post("https://steamcommunity.com/market/sellitem/", data).catch(err => err);
let response: Response|null = null;
try {
response = await RequestData.post("https://steamcommunity.com/market/sellitem/", data);
} catch(err) {
console.error(err);
}

const result = await response?.json();
if (!result?.success) {
loadingEl.textContent = result?.message ?? L(__error);
enableButtons(true);
Expand Down
2 changes: 2 additions & 0 deletions src/js/Content/Features/Community/MarketHome/CMarketHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ export default class CMarketHome extends CCommunityBase {
{"childList": true}
);
}

this.onMarketListings.dispatch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class FPopularRefreshToggle extends Feature<CMarketHome> {
HTML.beforeEnd("#sellListings .market_tab_well_tabs",
`<div id="es_popular_refresh_toggle" class="btn_grey_black btn_small" data-tooltip-text="${L(__marketPopularItemsToggle)}"></div>`);

document.querySelector("#es_popular_refresh_toggle")?.addEventListener("click", () => {
this._toggleRefresh(!LocalStorage.get("popular_refresh"));
document.querySelector("#es_popular_refresh_toggle")?.addEventListener("click", async () => {
this._toggleRefresh(!(await LocalStorage.get("popular_refresh")));
});

this._toggleRefresh(await LocalStorage.get("popular_refresh") ?? false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Localization from "@Core/Localization/Localization";
await Localization;
} catch (err) {
console.group("Augmented Steam initialization");
console.error("Failed to initiliaze Augmented Steam");
console.error("Failed to initialize Augmented Steam");
console.error(err);
console.groupEnd();

Expand Down
2 changes: 1 addition & 1 deletion src/js/Content/Features/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class Page {
await Promise.all([Localization, User, CurrencyManager]);
} catch (err) {
console.group("Augmented Steam initialization");
console.error("Failed to initiliaze Augmented Steam");
console.error("Failed to initialize Augmented Steam");
console.error(err);
console.groupEnd();
return;
Expand Down
11 changes: 5 additions & 6 deletions src/js/Content/Modules/ASEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ export default class ASEventHandler<T = void> {
}

private invoke(listener: ASEventListener<T>) {
if (this.data) {
listener({data: this.data});
}
listener({data: this.data!});
}

public dispatch(data: T): void {
if (data) {
this.data = data;
}
this.data = data;

for (let listener of this.listeners) {
this.invoke(listener);
}

this.wasDispatched = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
contextid: 6
};

const profileUrl = f.global("g_strProfileURL");

$J.get(`${profileUrl}/ajaxgetgoovalue/`, data).done(data => {
$J.get(`${g_strProfileURL}/ajaxgetgoovalue/`, data).done(data => {
data.goo_value_expected = data.goo_value;

$J.post(`${profileUrl}/ajaxgrindintogoo/`, data)
$J.post(`${g_strProfileURL}/ajaxgrindintogoo/`, data)
.done(() => {
ReloadCommunityInventory();
});
Expand Down

0 comments on commit 7d9e02f

Please sign in to comment.