-
Notifications
You must be signed in to change notification settings - Fork 0
/
steamdb-hide-foreign-currencies.js
80 lines (65 loc) · 2.92 KB
/
steamdb-hide-foreign-currencies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// ==UserScript==
// @name SteamDB Hide Foreign Currencies
// @namespace https://github.com/Drakmyth/steamdb-hide-foreign-currencies
// @version 0.1
// @author Drakmyth
// @description A Tampermonkey userscript to hide foreign currency information on SteamDB
// @homepage https://github.com/Drakmyth/steamdb-hide-foreign-currencies
// @updateURL https://github.com/Drakmyth/steamdb-hide-foreign-currencies/raw/master/steamdb-hide-foreign-currencies.user.js
// @downloadURL https://github.com/Drakmyth/steamdb-hide-foreign-currencies/raw/master/steamdb-hide-foreign-currencies.user.js
// @supportURL https://github.com/Drakmyth/steamdb-hide-foreign-currencies/issues
// @license MIT
// @match https://steamdb.info/app/*
// @run-at document-body
// @grant none
// ==/UserScript==
(function () {
`use strict`;
const toggleButtonId = `tmnky-hide-foreign-currencies`;
let hideForeignCurrencies = true;
function doesToggleButtonExist() {
const controlContainer = getControlContainer();
return controlContainer.querySelector(`button#${toggleButtonId}`);
}
function getCurrentStateButtonText() {
return `${hideForeignCurrencies ? `Show` : `Hide`} Foreign Currencies`;
}
function addToggleButton() {
const toggleButton = createToggleButton(getCurrentStateButtonText(), toggleShowForeignCurrencies)
const controlContainer = getControlContainer();
controlContainer.insertBefore(toggleButton, controlContainer.firstChild);
}
function getControlContainer() {
return document.getElementById('js-currency-selector').parentElement;
}
function createToggleButton(text, onClick) {
const toggleButton = document.createElement(`button`);
toggleButton.className = `btn btn-outline`;
toggleButton.id = toggleButtonId;
toggleButton.onclick = onClick;
toggleButton.textContent = text;
return toggleButton;
}
function toggleShowForeignCurrencies(event) {
hideForeignCurrencies = !hideForeignCurrencies;
event.target.textContent = getCurrentStateButtonText();
onBodyChange();
}
function isCurrentCurrency(row) {
return !hideForeignCurrencies || row.classList.contains(`table-prices-current`);
}
function onBodyChange(mut) {
const priceRows = document.querySelectorAll(`.table-prices>tbody>tr`);
for (let row of priceRows) {
row.style.display = isCurrentCurrency(row) ? null : `none`;
}
}
function onDOMContentLoaded() {
if (!doesToggleButtonExist()) {
addToggleButton();
}
}
document.addEventListener(`DOMContentLoaded`, onDOMContentLoaded, false);
const mo = new MutationObserver(onBodyChange);
mo.observe(document.body, { childList: true, subtree: true });
})();