Last active
March 10, 2025 16:08
-
-
Save seujorgenochurras/6df740e9d98f4628cf11407650ccf1e3 to your computer and use it in GitHub Desktop.
csgocases price checker
This file contains hidden or 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
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | |
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | |
return new (P || (P = Promise))(function (resolve, reject) { | |
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | |
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | |
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | |
step((generator = generator.apply(thisArg, _arguments || [])).next()); | |
}); | |
}; | |
var __generator = (this && this.__generator) || function (thisArg, body) { | |
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); | |
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | |
function verb(n) { return function (v) { return step([n, v]); }; } | |
function step(op) { | |
if (f) throw new TypeError("Generator is already executing."); | |
while (g && (g = 0, op[0] && (_ = 0)), _) try { | |
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | |
if (y = 0, t) op = [op[0] & 2, t.value]; | |
switch (op[0]) { | |
case 0: case 1: t = op; break; | |
case 4: _.label++; return { value: op[1], done: false }; | |
case 5: _.label++; y = op[1]; op = [0]; continue; | |
case 7: op = _.ops.pop(); _.trys.pop(); continue; | |
default: | |
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | |
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | |
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | |
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | |
if (t[2]) _.ops.pop(); | |
_.trys.pop(); continue; | |
} | |
op = body.call(thisArg, _); | |
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | |
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | |
} | |
}; | |
var __rest = (this && this.__rest) || function (s, e) { | |
var t = {}; | |
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | |
t[p] = s[p]; | |
if (s != null && typeof Object.getOwnPropertySymbols === "function") | |
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | |
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | |
t[p[i]] = s[p[i]]; | |
} | |
return t; | |
}; | |
var STEAM_API_URL = "https://steamcommunity.com/"; | |
var STEAM_MARKET_PRICE_ENDPOINT = STEAM_API_URL + "market/priceoverview"; | |
function printSkinsPrices() { | |
return __awaiter(this, void 0, void 0, function () { | |
var skinBoxQuery, skinBoxElement, skinsPrices, _i, _a, skinDiv, skin, steamPrice, flattenSkinPrices, reducedSkinPrices; | |
return __generator(this, function (_b) { | |
switch (_b.label) { | |
case 0: | |
skinBoxQuery = "#itemsContent"; | |
skinBoxElement = document.querySelector(skinBoxQuery); | |
skinsPrices = []; | |
_i = 0, _a = skinBoxElement === null || skinBoxElement === void 0 ? void 0 : skinBoxElement.querySelectorAll("div.gradient-item"); | |
_b.label = 1; | |
case 1: | |
if (!(_i < _a.length)) return [3 /*break*/, 4]; | |
skinDiv = _a[_i]; | |
skin = getSkinContents(skinDiv); | |
return [4 /*yield*/, getSkinMarketPrice(skin)]; | |
case 2: | |
steamPrice = _b.sent(); | |
skinsPrices.push({ | |
initialSkin: skin, | |
steamPrice: steamPrice | |
}); | |
_b.label = 3; | |
case 3: | |
_i++; | |
return [3 /*break*/, 1]; | |
case 4: | |
flattenSkinPrices = skinsPrices.map(function (skinPrice) { | |
var initialSkin = skinPrice.initialSkin; | |
var steamPrice = skinPrice.steamPrice; | |
var initialSkinPrice = initialSkin.price; | |
var lowestPrice = steamPrice.lowestPrice; | |
var medianPrice = steamPrice.medianPrice; | |
var lowestPriceDif = "$" + (initialSkinPrice - lowestPrice).toFixed(2); | |
var lowestPriceDifROI = (lowestPrice / initialSkinPrice * 100).toFixed(2) + "%"; | |
var mediaPriceDif = "$" + (initialSkinPrice - medianPrice).toFixed(2); | |
var mediaPriceDifROI = (medianPrice / initialSkinPrice * 100).toFixed(2) + "%"; | |
return { | |
skinName: initialSkin.name, | |
"steam.lowestPrice": "$" + lowestPrice, | |
"steam.medianPrice": "$" + medianPrice, | |
"Lowest Price Dif": lowestPriceDif, | |
"Lowest Price ROI": lowestPriceDifROI, | |
"Median Price Dif": mediaPriceDif, | |
"Median Price ROI": mediaPriceDifROI | |
}; | |
}); | |
reducedSkinPrices = flattenSkinPrices.reduce(function (teste, _a) { | |
var skinName = _a.skinName, x = __rest(_a, ["skinName"]); | |
teste[skinName] = x; | |
return teste; | |
}, {}); | |
console.table(reducedSkinPrices); | |
return [2 /*return*/]; | |
} | |
}); | |
}); | |
} | |
function getSkinMarketPrice(skin) { | |
return __awaiter(this, void 0, void 0, function () { | |
var url, apiResponse, body, lowestPrice, medianPrice; | |
return __generator(this, function (_a) { | |
switch (_a.label) { | |
case 0: | |
url = STEAM_MARKET_PRICE_ENDPOINT + | |
"?appid=730¤cy=1&market_hash_name=".concat(skin.statTrack ? "StatTrak™ " : "").concat(skin.name); | |
return [4 /*yield*/, fetch(url, { | |
method: "GET", | |
})]; | |
case 1: | |
apiResponse = _a.sent(); | |
return [4 /*yield*/, apiResponse.json()]; | |
case 2: | |
body = _a.sent(); | |
lowestPrice = body["lowest_price"]; | |
medianPrice = body["median_price"]; | |
if (!lowestPrice) { | |
lowestPrice = "0"; | |
} | |
if (!medianPrice) { | |
medianPrice = "0"; | |
} | |
return [2 /*return*/, { | |
lowestPrice: medianPrice.replace("$", ""), | |
medianPrice: medianPrice.replace("$", ""), | |
}]; | |
} | |
}); | |
}); | |
} | |
function getSkinContents(skinDiv) { | |
var contentElement = skinDiv === null || skinDiv === void 0 ? void 0 : skinDiv.querySelector("div.item-content"); | |
var statTrack = isStatTrack(contentElement); | |
var name = getContentName(contentElement); | |
var price = getContentPrice(contentElement); | |
return { name: name, statTrack: statTrack, price: price }; | |
} | |
function isStatTrack(contentsElement) { | |
var imageTextElement = contentsElement.querySelector("span.ng-scope"); | |
return imageTextElement != undefined; | |
} | |
function getContentName(contentElement) { | |
var bottomElement = contentElement.querySelector("div.item-bottom"); | |
var nameElement = bottomElement.firstElementChild; | |
var rarityElement = bottomElement.lastElementChild; | |
var name = nameElement.textContent; | |
if (rarityElement.textContent != "") { | |
name += "(".concat(rarityElement.textContent, ")"); | |
} | |
return name.trim().replaceAll("\n", "").replace(/\s+/g, " "); | |
} | |
function getContentPrice(contentElement) { | |
var topElement = contentElement.querySelector("div.item-top"); | |
var priceElement = topElement.querySelector("span.resell-price-span"); | |
var priceString = priceElement.textContent; | |
priceString = priceString.replace("$", ""); | |
return +priceString; | |
} | |
printSkinsPrices(); |
This file contains hidden or 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
const STEAM_API_URL = "https://steamcommunity.com/"; | |
const STEAM_MARKET_PRICE_ENDPOINT = STEAM_API_URL + "market/priceoverview"; | |
async function printSkinsPrices() { | |
const skinBoxQuery = `#itemsContent`; | |
const skinBoxElement = document.querySelector(skinBoxQuery); | |
const skinsPrices: SkinPrice[] = [] | |
for (let skinDiv of skinBoxElement?.querySelectorAll("div.gradient-item")!) { | |
const skin = getSkinContents(skinDiv); | |
const steamPrice = await getSkinMarketPrice(skin); | |
skinsPrices.push({ | |
initialSkin: skin, | |
steamPrice: steamPrice | |
} | |
) | |
} | |
const flattenSkinPrices = skinsPrices.map(skinPrice => { | |
const initialSkin = skinPrice.initialSkin | |
const steamPrice = skinPrice.steamPrice | |
const initialSkinPrice = initialSkin.price; | |
const lowestPrice = steamPrice.lowestPrice; | |
const medianPrice = steamPrice.medianPrice; | |
const lowestPriceDif = "$" + (initialSkinPrice - lowestPrice).toFixed(2) | |
const lowestPriceDifROI = (lowestPrice / initialSkinPrice * 100).toFixed(2) + "%" | |
const mediaPriceDif = "$" + (initialSkinPrice - medianPrice).toFixed(2) | |
const mediaPriceDifROI = (medianPrice / initialSkinPrice * 100).toFixed(2) + "%" | |
return { | |
skinName: initialSkin.name, | |
"steam.lowestPrice": "$" + lowestPrice, | |
"steam.medianPrice": "$" + medianPrice, | |
"Lowest Price Dif": lowestPriceDif, | |
"Lowest Price ROI": lowestPriceDifROI, | |
"Median Price Dif": mediaPriceDif, | |
"Median Price ROI": mediaPriceDifROI | |
} | |
}) | |
const reducedSkinPrices = flattenSkinPrices.reduce((teste, { skinName, ...x }) => { | |
teste[skinName] = x; | |
return teste | |
}, {}) | |
console.table(reducedSkinPrices) | |
} | |
async function getSkinMarketPrice(skin: Skin): Promise<SteamPrice> { | |
const url = | |
STEAM_MARKET_PRICE_ENDPOINT + | |
`?appid=730¤cy=1&market_hash_name=${skin.statTrack ? "StatTrak™ " : ""}${skin.name}`; | |
const apiResponse = await fetch(url, { | |
method: "GET", | |
}); | |
const body = await apiResponse.json(); | |
let lowestPrice = body["lowest_price"] | |
let medianPrice = body["median_price"] | |
if (!lowestPrice) { | |
lowestPrice = "0" | |
} | |
if (!medianPrice) { | |
medianPrice = "0" | |
} | |
return { | |
lowestPrice:medianPrice.replace("$", ""), | |
medianPrice: medianPrice.replace("$", ""), | |
}; | |
} | |
function getSkinContents(skinDiv: Element): Skin { | |
const contentElement = skinDiv?.querySelector("div.item-content")!; | |
const statTrack = isStatTrack(contentElement); | |
const name = getContentName(contentElement); | |
const price = getContentPrice(contentElement); | |
return { name, statTrack, price }; | |
} | |
function isStatTrack(contentsElement: Element) { | |
const imageTextElement = contentsElement.querySelector("span.ng-scope"); | |
return imageTextElement != undefined; | |
} | |
function getContentName(contentElement: Element) { | |
const bottomElement = contentElement.querySelector("div.item-bottom")!; | |
const nameElement = bottomElement.firstElementChild!; | |
const rarityElement = bottomElement.lastElementChild!; | |
let name = nameElement.textContent!; | |
if (rarityElement.textContent != "") { | |
name += `(${rarityElement.textContent})`; | |
} | |
return name.trim().replaceAll("\n", "").replace(/\s+/g, " "); | |
} | |
function getContentPrice(contentElement: Element) { | |
const topElement = contentElement.querySelector("div.item-top")!; | |
const priceElement = topElement.querySelector("span.resell-price-span")!; | |
let priceString = priceElement.textContent!; | |
priceString = priceString.replace("$", ""); | |
return +priceString; | |
} | |
printSkinsPrices(); | |
interface Skin { | |
name: string; | |
statTrack: boolean; | |
price: number; | |
} | |
interface SteamPrice{ | |
lowestPrice: number, | |
medianPrice: number, | |
} | |
interface SkinPrice { | |
initialSkin: Skin, | |
steamPrice: SteamPrice | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have to install the extension "CORS Unblock" and it also only works on the shop page