Last active
December 21, 2018 02:48
-
-
Save lingsamuel/fbd7efd321750610c421e3d5b74a9bb3 to your computer and use it in GitHub Desktop.
Calculate Steam wish list
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
// Usage: | |
// Copy and paste [base] part into F12-Console at your Steam wishlist page(https://store.steampowered.com/wishlist/id/username) | |
// Copy and paste [price] part into F12-Console to show your wishlist total price | |
// Copy and paste [names] part into F12-Console to show your wishlist game names | |
// ======================= [BASE] ============================ | |
let items = this.top.g_Wishlist.rgElements; | |
let appIds = Object.keys(items); | |
function getItemTitle(item){ | |
return item.children[2].children[0].innerText.replace(/[^\x20-\x7E]/g, ''); // has many invisible char | |
} | |
function getPurchaseContainer(item){ | |
return item.children[2].children[1].children[1]; | |
} | |
let titles = appIds.map(x => getItemTitle(items[x][0])); | |
// Normal Item | |
// content - mid_container - purchase_container - purchase_area - discount_block - discount_prices - discount_final_price | |
// 2 - 1 - 1 - 0 - 0 - 0 - 0 | |
// Discount Item | |
// content - mid_container - purchase_container - purchase_area - discount_block - discount_prices - discount_final_price | |
// 2 - 1 - 1 - 0 - 0 - 1 - 1 | |
// Coming Soom Item | |
// content - mid_container - purchase_container - coming_soon_link | |
// 2 - 1 - 1 - 0 | |
// Free/Banned Item | |
// content - mid_container - purchase_container - purchase_area - <a> | |
// 2 - 1 - 1 - 0 - 0 | |
// content - mid_container - purchase_container - purchase_area - discount_block empty | |
// 2 - 1 - 1 - 0 - 0 | |
// No Price Item: 340, HL: Lost Coast | |
function isNormal(x) { | |
x = getPurchaseContainer(items[x][0]); | |
// Div check because no price item like 340/HL: Lost Coast has 2 children too | |
return x.children[0].hasClassName("purchase_area") && x.children[0].children[0].tagName == "DIV" && x.children[0].children[0].children.length == 1; | |
} | |
function isDiscount(x) { | |
x = getPurchaseContainer(items[x][0]); | |
return x.children[0].hasClassName("purchase_area") && x.children[0].children[0].children.length == 2; | |
} | |
function isComing(x) { | |
x = getPurchaseContainer(items[x][0]); | |
return x.children[0].hasClassName("coming_soon_link"); | |
} | |
function isFree(x) { | |
x = getPurchaseContainer(items[x][0]); | |
return (x.children[0].hasClassName("purchase_area") && x.children[0].children[0].tagName == "A") || | |
(x.children[0].hasClassName("purchase_area") && x.children[0].children[0].tagName == "DIV" && x.children[0].children[0].children.length == 0); | |
} | |
const neitherThem = (x) => !isNormal(x) && !isDiscount(x) && !isComing(x) && !isFree(x); | |
let normalItems = appIds.filter(isNormal); | |
let discountItems = appIds.filter(isDiscount); | |
let comingItems = appIds.filter(isComing); | |
let freeItems = appIds.filter(isFree); | |
let neitherItems = appIds.filter(neitherThem); | |
let comingItemTitles = comingItems.map(x => getItemTitle(items[x][0])); | |
let freeItemTitles = freeItems.map(x => getItemTitle(items[x][0])); | |
let neitherItemTitles = neitherItems.map(x => getItemTitle(items[x][0])); | |
let normalItemTitles = normalItems.map(x => getItemTitle(items[x][0])); | |
let discountItemTitles = discountItems.map(x => getItemTitle(items[x][0])); | |
let normalPurchaseContainers = normalItems.map(x => getPurchaseContainer(items[x][0])); | |
let discountPurchaseContainers = discountItems.map(x => getPurchaseContainer(items[x][0])); | |
// ======================= [BASE END] ============================ | |
// ======================= [PRICE] ============================ | |
function getDiscountItemPrice(item) { | |
return item.children[0].children[0].children[1]. // Here, children[0] is discount percentage div | |
children[1]. // Here, children[0] is discount value div | |
innerText; | |
} | |
function getFullPriceItemPrice(item) { | |
return item.children[0].children[0].children[0].children[0].innerText; | |
} | |
const adder = (accumulator, currentValue) => accumulator + currentValue; | |
// WTF Some *normal* game price shows "Free" with a "Play Now" button | |
// But other free games won't shows that just a "Play Now" button... | |
let normalPrice = normalPurchaseContainers.map(getFullPriceItemPrice).map(x => { | |
let price = parseInt(x.split(' ')[1]); | |
if(Number.isNaN(price)) price = 0; | |
return price; | |
}).reduce(adder); | |
let discountPrice = discountPurchaseContainers.map(getDiscountItemPrice).map(x => parseInt(x.split(' ')[1])).reduce(adder); | |
console.log(`Discount Item Price: ${discountPrice}, Full Price Item Price: ${normalPrice}, Total Price: ${discountPrice + normalPrice}`); | |
// ======================= [PRICE END] ============================ | |
// ======================= [NAMES] ============================ | |
let normalNames = normalItemTitles.join(", "); | |
let discountNames = discountItemTitles.join(", "); | |
let comingNames = comingItemTitles.join(", "); | |
let freeNames = freeItemTitles.join(", "); | |
console.log(`Normal Games: ${normalNames}`); | |
console.log(`Discount Games: ${discountNames}`); | |
console.log(`Coming Games: ${comingNames}`); | |
console.log(`Free Games: ${freeNames}`); | |
if(neitherItemTitles.length > 0){ | |
let neitherNames = neitherItemTitles.join(", "); | |
console.log(`Unrecognized Games: ${neitherNames}`); | |
} | |
// ======================= [NAMES END] ============================ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment