forked from IsThereAnyDeal/AugmentedSteam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add link to download demo on wishlists
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/js/Content/Features/Store/Wishlist/FWishlistDemoLink.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters