Skip to content

Instantly share code, notes, and snippets.

@kpumuk
Last active May 30, 2017 19:15
Show Gist options
  • Save kpumuk/bea77cfcf8303812abc7c06c452b6a1d to your computer and use it in GitHub Desktop.
Save kpumuk/bea77cfcf8303812abc7c06c452b6a1d to your computer and use it in GitHub Desktop.
Script to run from Chrome inspector that will fetch sale details and format them as a table with Reddit markup
$.getJSON('https://store.playstation.com/chihiro-api/viewfinder/US/en/19/' + location.hash.replace(/.*cid=([a-zA-Z0-9\-]+).*/, '$1') + '?size=300', function(d) {
var filteredLinks = $.grep(d.links, function(link) {
return link.playable_platform.find(function(platform) {
return !!platform.match(/^ps4/i);
});
});
var sortedLinks = filteredLinks.sort(function(a, b) {
if (a.name > b.name) return 1;
if (a.name < b.name) return -1;
return 0
});
var hasDiscounts = false;
var hasPSPlusDiscounts = false;
$(sortedLinks).each(function(idx, link) {
$(link.default_sku.rewards).each(function(_, reward) {
if (reward.bonus_discount) {
hasDiscounts = true;
hasPSPlusDiscounts = true;
link.plusReward = reward;
link.normalReward = reward;
} else if (reward.isPlus) {
hasPSPlusDiscounts = true;
link.plusReward = reward;
} else {
hasDiscounts = true;
link.normalReward = reward;
}
})
});
var result = "Game";
if (hasDiscounts) { result += "|Price|% Off"; }
if (hasPSPlusDiscounts) { result += "|PS+|% Off"; }
result += "\n:--";
if (hasDiscounts) { result += "|:--|:--"; }
if (hasPSPlusDiscounts) { result += "|:--|:--"; }
result += "\n";
$(sortedLinks).each(function(idx, link) {
result +=
"[" + link.name.replace("[", "\\[").replace("]", "\\]") + "]" +
"(" + 'https://store.playstation.com/#!cid=' + link.id + ")";
if (hasDiscounts) {
result += "|" +
(link.normalReward ? link.normalReward.display_price : link.default_sku.display_price) + "|" +
(link.normalReward ? link.normalReward.discount + "%" : "–");
}
if (hasPSPlusDiscounts) {
result += "|" +
(link.plusReward ? link.plusReward.bonus_display_price || link.plusReward.display_price || '—' : (hasDiscounts ? '–' : link.default_sku.display_price || '–')) + "|" +
(link.plusReward ? link.plusReward.bonus_discount || link.plusReward.discount || '—' : '–') + (link.plusReward && (link.plusReward.bonus_discount || link.plusReward.discount) ? "%" : '');
}
result += "\n";
});
console.log(result);
});''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment