Skip to content

Instantly share code, notes, and snippets.

@Luckz
Last active November 18, 2021 10:27
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 Luckz/f71f5bd63eedfe5c3cfabee04d04a5af to your computer and use it in GitHub Desktop.
Save Luckz/f71f5bd63eedfe5c3cfabee04d04a5af to your computer and use it in GitHub Desktop.
SteamDBPriceChangesMemory.user.js
// ==UserScript==
// @name SteamDB Price Changes Memory
// @namespace luckz
// @author luckz
// @version 0.2
// @description mark price changes up to a certain timestamp as seen (by fading them out)
// @match https://steamdb.info/pricechanges/*
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @downloadURL https://gist.github.com/Luckz/f71f5bd63eedfe5c3cfabee04d04a5af/raw/SteamDBPriceChangesMemory.user.js
// @updateURL https://gist.github.com/Luckz/f71f5bd63eedfe5c3cfabee04d04a5af/raw/SteamDBPriceChangesMemory.user.js
// ==/UserScript==
const onAppsPage = new URLSearchParams(location.search).get('subs') === '1'; // that "subs=1" means apps instead of subs is braindead but not my fault
const timestamp = !onAppsPage ? 'timestamp' : 'timestampApps'; // GM storage entry
const qs = '.table-responsive .timeago[data-sort]'; // query selector
const ttFade = 'PCM: Fade out visible items older than saved timestamp';
const ttSet = 'PCM: Save latest visible timestamp';
const getTimestamp = () => GM_getValue(timestamp, 0);
const fadeOut = () => {
const ts = getTimestamp();
document.querySelectorAll(qs).forEach(x => {if (x.dataset.sort <= ts) x.parentElement.style.opacity = 0.15});
}
const setTimestamp = () => GM_setValue(timestamp, [...document.querySelectorAll(qs)].reduce((highest, curr) => highest = curr.dataset.sort > highest ? curr.dataset.sort : highest, 0));
GM_registerMenuCommand(ttFade, fadeOut);
GM_registerMenuCommand(ttSet, setTimestamp);
const entry = document.querySelector('thead > tr > th:nth-child(2)');
entry.innerHTML = `<span class="pcm_fade" title="${ttFade}">👁‍🗨</span><span class="pcm_set" title="${ttSet}">💾</span>`;
entry.querySelector('.pcm_fade').addEventListener('click', fadeOut); //eyes to darken
entry.querySelector('.pcm_set').addEventListener('click', setTimestamp); //floppy to save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment