Skip to content

Commit

Permalink
Add link to download demo on wishlists
Browse files Browse the repository at this point in the history
  • Loading branch information
candela97 committed Sep 17, 2023
1 parent c5f4cd5 commit 0d51409
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/js/Content/Features/Store/Wishlist/CWishlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import FExportWishlist from "./FExportWishlist";
import FKeepEditableRanking from "./FKeepEditableRanking";
import FOneClickRemoveFromWishlist from "./FOneClickRemoveFromWishlist";
import FWishlistProfileLink from "./FWishlistProfileLink";
import FWishlistDemoLink from "./FWishlistDemoLink";

export class CWishlist extends CStoreBase {

Expand All @@ -37,6 +38,7 @@ export class CWishlist extends CStoreBase {
FKeepEditableRanking,
FOneClickRemoveFromWishlist,
FWishlistProfileLink,
FWishlistDemoLink,
]);

this.wishlistData = wishlistData;
Expand Down
42 changes: 42 additions & 0 deletions src/js/Content/Features/Store/Wishlist/FWishlistDemoLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {Localization} from "../../../../modulesCore";
import {CallbackFeature, RequestData} from "../../../modulesContent";

export default class FWishlistDemoLink extends CallbackFeature {

async checkPrerequisites() {

this._info = [];

const appids = this.context.wishlistData.map(({appid}) => `appids[]=${appid}`);

// https://stackoverflow.com/questions/8495687/split-array-into-chunks
const chunkSize = 400; // Split params into chunks as Steam may throw `HTTP 414 Request-URI Too Large`

for (let i = 0; i < appids.length; i += chunkSize) {
const params = appids.slice(i, i + chunkSize).join("&");

const data = await RequestData.getJson(`https://store.steampowered.com/saleaction/ajaxgetdemoevents?${params}`).catch(err => console.error(err));
if (!data || !data.success || !data.info) { continue; }

this._info = this._info.concat(data.info.filter(val => Boolean(val.demo_appid)));
}

return this._info.length > 0;
}

callback(nodes) {

for (const node of nodes) {

const rowAppid = Number(node.dataset.appId);
const demoAppid = this._info.find(({appid}) => appid === rowAppid)?.demo_appid;
if (typeof demoAppid === "undefined") { continue; }

const link = document.createElement("a");
link.href = `steam://install/${demoAppid}`;
link.textContent = Localization.str.download_demo;
link.classList.add("earlyaccess");
node.querySelector(".platform_icons").prepend(link);
}
}
}
1 change: 1 addition & 0 deletions src/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"continue": "Yes, continue shopping"
},
"download_demo_header": "Download __gamename__ Demo",
"download_demo": "Download Demo",
"deck_compat": {
"header": "Steam Deck Compatibility",
"unknown": "Unknown",
Expand Down

0 comments on commit 0d51409

Please sign in to comment.