Skip to content

Instantly share code, notes, and snippets.

@AviDuda
Last active June 29, 2018 15:09
Show Gist options
  • Save AviDuda/4083c9634445347fd6bef0243baa23a9 to your computer and use it in GitHub Desktop.
Save AviDuda/4083c9634445347fd6bef0243baa23a9 to your computer and use it in GitHub Desktop.
Steam Store DLC review stats
// ==UserScript==
// @name Steam Store DLC review stats
// @namespace https://timmy.im/
// @version 1.1
// @description Click on the "Get DLC reviews" link above DLC list
// @author Tomáš Duda
// @match https://store.steampowered.com/app/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
jQuery('.game_area_dlc_section h2').append('<span class="note"><a href="#" data-get-dlc-reviews>Get DLC reviews</a></span>');
jQuery('[data-get-dlc-reviews]').click((e) => {
e.preventDefault();
let results = [];
let promises = [];
document.querySelectorAll('[data-ds-appid].game_area_dlc_row').forEach(elem => {
const appid = elem.dataset.dsAppid;
promises.push(fetch(`https://store.steampowered.com/apphover/${appid}`).then(response => response.text()).then(data => {
const hover = jQuery(data);
let result = {};
result.gameName = hover.find('h4').text();
const summary = hover.find('.game_review_summary');
if (summary.hasClass('not_enough_reviews')) {
result.summary = 'Not enough reviews';
result.reviews = summary.text().replace(/ .*/, '').replace(',', '');
}
else {
result.summary = summary.text();
result.reviews = -1;
if (summary.length > 0) {
result.reviews = jQuery.trim(summary[0].nextSibling.nodeValue).replace('(', '').replace(/ .*/, '').replace(',', '');
result.reviews = parseInt(result.reviews);
}
}
results.push(result);
}));
});
let table = "| DLC | Summary | Reviews |";
table += "\n| --- | ------- | ------- |";
setTimeout(() => Promise.all(promises).then(() => {
results = results.sort((a, b) => {
if (b.reviews > a.reviews) return 1;
else if (b.reviews === a.reviews) return 0;
else return -1;
});
results.forEach(result => table += `\n| ${result.gameName} | ${result.summary} | ${result.reviews} |`);
ShowDialog('Steam DLC reviews', `<textarea rows="40" style="width: 1000px;">${table}</textarea>`);
}), 1);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment