Skip to content

Instantly share code, notes, and snippets.

@lamchau
Created June 17, 2020 11:31
Show Gist options
  • Save lamchau/906849f3a70a9947d3bfe25d09bf2c2b to your computer and use it in GitHub Desktop.
Save lamchau/906849f3a70a9947d3bfe25d09bf2c2b to your computer and use it in GitHub Desktop.
(function() {
sessionStorage.clear();
const targetNode = document.querySelector('.unredeemed-keys-table');
if (!targetNode) {
return;
}
const config = { attributes: true, childList: true, subtree: true };
const steamRegex = /\S{5}-\S{5}-\S{5}(-\S{5}-\S{5})?/;
const extract = (mutationsList, observer) => {
const $rows = Array.from(document.querySelectorAll('tr'));
for (const $r of $rows) {
const $game = $r.querySelector('.game-name h4');
const $key = $r.querySelector('.keyfield-value');
const $steam = $r.querySelector('[class~="hb-steam"]');
if ($steam) {
const game = $game.innerText.trim();
const key = $key.innerText.trim();
if (steamRegex.test(key)) {
sessionStorage.setItem(key, game);
}
}
}
console.log(sessionStorage.length);
};
const observer = new MutationObserver(extract);
extract();
observer.observe(targetNode, config);
function remap() {
const games = Object.keys(sessionStorage)
.map(key => [sessionStorage.getItem(key), key]);
games.sort((a, b) => a[0].localeCompare(b[0]));
return games.map(x => `"${x[0]}","${x[1]}"`).join('\n');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment