Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script to add the most helpful Steam review to the front page
// Initial definitions
var now = new Date().getTime();
var ten_seconds = 10 * 1000;
var one_day = 86400 * 1000;
var one_week = one_day * 7;
// Remove any pre-existing summary elements
jQuery(".summary-element").remove();
// Add the content depending on the result
function considerContent(url, matchingElements, content) {
}
// Define how we add summary elements to deal divs
function addOverview(element, content) {
var div = jQuery("<div class='summary-element' />");
div.css({
position: "absolute",
top: 0,
left: 0,
width: "100%",
"line-height": "1.1em",
"font-size": "12px",
"text-shadow": "1px 1px 1px #000",
"z-index": 399,
background: "rgba(0,0,0,0.7)"
});
if (content.reviews) {
jQuery.each(content.reviews, function(index, review) {
var element = jQuery("<img />");
element.prop("src", review.thumbSrc);
element.css({
float: "right",
background: "rgba(0,0,0,0.7)",
width: "11px",
height: "11px"
});
element.prop("title", review.content);
div.append(element);
});
}
if (content.steamAggregateSummary !== undefined) {
var pSteamAggregate = jQuery("<p />");
pSteamAggregate.css({
"white-space": "nowrap",
"font-weight": "bold"
});
if (content.steamAggregateSummary == "Mixed") pSteamAggregate.css("color", "#A34C25");
else if (content.steamAggregateSummary.indexOf("Positive") !== -1) pSteamAggregate.css("color", "#66C0F4");
pSteamAggregate.text("Steam Reviews: " + (content.steamAggregateSummary || "None"));
pSteamAggregate.prop("title", content.steamAggregateText);
div.append(pSteamAggregate);
}
if (content.metacriticScore) {
var pMetaCritic = jQuery("<p />");
pMetaCritic.text(content.metacriticScore + "% on MetaCritic");
div.append(pMetaCritic);
}
if (content.drmNotices) {
var pDrmNotices = jQuery("<p />");
pDrmNotices.text(content.drmNotices);
if (content.requiresUPlay) pDrmNotices.css({
color: "#f66",
"font-weight": "bold"
});
div.append(pDrmNotices);
}
if (!content.reviews.length) {
div.css({background: "rgba(255, 255, 0, 0.5)", height: "100%"});
} else if (
(content.reviews[0].thumbSrc.indexOf("thumbsDown") !== -1)
|| (content.steamAggregateSummary === undefined)
|| (content.steamAggregateSummary.toLowerCase().indexOf("positive") === -1)
|| (content.requiresUPlay)
) {
div.css({background: "hsla(19, 64%, 30%, 0.8)", height: "100%"});
}
element.append(div);
}
var urls = {};
jQuery("a[href^='http://store.steampowered.com/app/']").css({position: "relative", display: "inline-block"}).each(function() {
var element = jQuery(this);
var domElement = element.get(0);
var url = [domElement.protocol, '//', domElement.host, domElement.pathname].join('');
urls[url] = true;
})
// Stronger colouration on good discounts
jQuery(".discount_pct").filter(function() {
return parseInt(jQuery(this).text()) <= -60;
}).css({
background: "rgb(0, 255, 0)",
"font-weight": "bold"
});
jQuery(".discount_pct").filter(function() {
return parseInt(jQuery(this).text()) > -20;
}).css({
background: "rgb(163, 76, 37)",
});
// Attach our extra content to each block
jQuery.each(urls, function(url) {
var matchingElements = jQuery("a[href^='"+url+"']");
// Try to use the cached value
var timedContent = localStorage[url] ? JSON.parse(localStorage[url]) : null;
if (timedContent && timedContent.expires > now) {
jQuery.each(matchingElements, function(index, element) {
addOverview(jQuery(element), timedContent);
});
}
// Otherwise, getting the linked page's content and parse it out
else {
jQuery.get(url, function(data) {
var remotePage = jQuery(data);
var content = {};
if (jQuery("#agecheck_form", remotePage).length) {
content.expires = now + ten_seconds;
} else {
content.expires = now + one_week;
content.steamAggregateSummary = jQuery("div[itemprop=aggregateRating]", remotePage).find(".game_review_summary").text();
content.steamAggregateText = jQuery("div[itemprop=aggregateRating]", remotePage).data("store-tooltip");
content.metacriticScore = jQuery("#game_area_metascore span", remotePage).first().text();
content.reviews = jQuery("#Reviews_all .review_box", remotePage).map(function() {
var review = jQuery(this);
response = {};
response.thumbSrc = review.find(".thumb img").prop("src");
response.content = review.find(".content").text().trim();
return response;
});
content.drmNotices = jQuery(".DRM_notice", remotePage).text().trim().replace(/\s{2,}/g, '; ');
content.requiresUPlay = (
jQuery(".game_area_sys_req_full", remotePage).text().toLowerCase().indexOf("uplay") !== -1
|| content.drmNotices.toLowerCase().indexOf("uplay") !== -1
|| content.drmNotices.toLowerCase().indexOf("drm") !== -1
);
}
localStorage[url] = JSON.stringify(content);
jQuery.each(matchingElements, function(index, element) {
addOverview(jQuery(element), content);
});
});
}
});
@bradbeattie

This comment has been minimized.

Copy link
Owner Author

commented Jun 26, 2014

Most recent changes brings over review summaries, metacritic scores, helpful reviews, UPlay warnings.

Easily converted into a bookmarklet via https://chriszarate.github.io/bookmarkleter/

To bypass age verification, visit an age verification page which will set your cookie then run the script again.

Not sure what to do about bundle packs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.