Skip to content

Instantly share code, notes, and snippets.

@tdhsmith
Created October 18, 2017 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdhsmith/ab95474eab5b474c5d42397d1efacef6 to your computer and use it in GitHub Desktop.
Save tdhsmith/ab95474eab5b474c5d42397d1efacef6 to your computer and use it in GitHub Desktop.
Very rough userscript to expose exact inventory data on Canadian games retailers BGB and 401G
// ==UserScript==
// @match https://store.401games.ca/*
// @match https://www.boardgamebliss.com/*
// ==/UserScript==
const is401 = document.location.host.indexOf("401") > -1;
function getProduct() {
try {
if (is401) {
const wrapper = document.getElementById("ProductJson-product-template");
if (wrapper)
{
return JSON.parse(wrapper.textContent);
}
} else {
const decl = document.getElementById("content");
if (decl)
{
const scr = decl.firstElementChild;
if (scr instanceof HTMLScriptElement)
{
eval(scr.textContent);
return SPOParams.product;
}
}
}
} catch (e) {
console.error("Hit error while trying to find product info: ", e);
}
}
function getTarget () {
if (is401) {
return document.getElementById("variant-inventory");
} else {
const q = document.getElementById("quantity");
if (q) {
return q.parentElement.children[0];
}
}
}
const product = getProduct();
if (product && product.variants) {
if (product.variants.length === 1) {
const site = getTarget();
if (site) {
site.style.color = "blue";
site.innerHTML = "Inventory: " + product.variants[0].inventory_quantity;
} else {
console.error("No inventory label found");
}
} else {
console.error("Product had " + product.variants.length + " variants. Unable to consolidate.");
}
} else {
console.error("No product data JSON found");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment