-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdf_stock_display.user.js
More file actions
24 lines (18 loc) · 945 Bytes
/
df_stock_display.user.js
File metadata and controls
24 lines (18 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ==UserScript==
// @name Dwarven Forge Stock Display
// @version 2
// @match https://dwarvenforge.com/*
// @updateURL https://github.com/drossy/df_stock_display/raw/main/df_stock_display.user.js
// ==/UserScript==
// Get the product title
var prodtitle = document.querySelector('.product-single__title');
// If there isnt a product title dont do anything else
if (prodtitle != null) {
// Extract the JSON product string and remove leading and trailing white space
var jsonstr = document.querySelector('[aria-label="Product JSON"]').innerText.trim();
// The JSON product string is JSON wrapped in square brackets so extract a substring that is
// all but the first and last characters of that string and parse the JSON
var json = JSON.parse(jsonstr.substring(1, jsonstr.length - 1));
// Update the product title with the inventory quantity
prodtitle.innerHTML += "(" + json.inventory_quantity + " in stock)";
}