Skip to content

Instantly share code, notes, and snippets.

@exp111
Last active June 30, 2023 14:14
Show Gist options
  • Save exp111/1b689de23e998690cf8018678f0088c9 to your computer and use it in GitHub Desktop.
Save exp111/1b689de23e998690cf8018678f0088c9 to your computer and use it in GitHub Desktop.
Wishlist Thingy
<html>
<head>
<title>Wishlist</title>
</head>
<body>
<div>
<!--<input id="steamid" type="text" placeholder="steam64 id" />
<button onclick="getWishlist(getElementById('steamid').value)">GET</button>
-->
<textarea id="wishlist" placeholder="https://store.steampowered.com/wishlist/profiles/<id>/wishlistdata?cc=tl"></textarea>
<button onclick="parseWishlist(JSON.parse(document.getElementById('wishlist').value))">Parse</button>
</div>
<div>
<input type="checkbox" id="hideUnreleased">
<label for="hideUnreleased">Hide Unreleased</label><br/>
<label for="sort">Sort By</label>
<select id="sort" value="price">
<option value="price">Price</option>
<option value="game">Name (doesn't work)</option>
<option value="id">ID</option>
<option value="discount">Discount</option>
</select>
<input type="checkbox" id="reverseSort">
<label for="reverseSort">Reverse</label>
</div>
<div>
<table id="table">
<thead>
<tr>
<th>Game</th>
<th>ID</th>
<th>Price</th>
<th>Discount</th>
<th>Discounted?</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
<script>
const wishlistURL = "https://store.steampowered.com/wishlist/profiles/{id}/wishlistdata?cc=tl"
async function getWishlist(id) {
if (!id) {
alert(`Invalid ID ${id}`);
}
console.log(id);
let url = wishlistURL.replace("{id}", id);
console.log(url);
let res = await fetch(url);
console.log(res);
let json = await res.json();
}
function parseWishlist(json)
{
let hideUnreleased = document.getElementById("hideUnreleased").checked;
let sortVal = document.getElementById("sort").value;
let reverseSort = document.getElementById("reverseSort").checked;
//console.log(json);
clearTable();
let entries = [];
for (let id in json)
{
let app = json[id];
let obj = {
game: app.name,
id: id,
price: -1,
discount: 0,
discounted: false,
}
//console.log(app.name);
if (app.subs.length == 1)
{
obj.price = app.subs[0].price;
if (app.subs[0].discount_pct != null)
{
obj.discount = app.subs[0].discount_pct;
obj.discounted = true;
}
// parse discounted price
if (obj.price)
{
let num = Number.parseInt(obj.price);
obj.price = num / 100;
}
else
{
console.warn("Price null");
}
}
else if (app.subs.length > 1)
{
console.warn(app.subs);
}
else
{
if (hideUnreleased)
continue;
}
entries.push(obj);
}
// sort
if (reverseSort)
entries.sort((a,b) => b[sortVal] - a[sortVal]);
else
entries.sort((a,b) => a[sortVal] - b[sortVal]);
for (let e of entries)
{
addTableRow(e);
}
}
const tableID = "table";
function clearTable()
{
let table = document.getElementById(tableID);
let body = table.tBodies[0];
body.innerHTML = "";
}
function createTH(text)
{
let child = document.createElement("th");
if (typeof text == typeof true)
{
let el = document.createElement("input");
el.type = "checkbox";
el.disabled = true;
el.checked = text;
child.appendChild(el);
}
else
{
child.innerText = text;
}
return child;
}
function addTableRow(obj)
{
let table = document.getElementById(tableID);
let body = table.tBodies[0];
let row = document.createElement("tr");
row.appendChild(createTH(obj.game));
row.appendChild(createTH(obj.id));
row.appendChild(createTH(obj.price));
row.appendChild(createTH(obj.discount));
row.appendChild(createTH(obj.discounted));
body.appendChild(row);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment