Skip to content

Instantly share code, notes, and snippets.

@bih
Last active January 3, 2016 17:00
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 bih/152b44024fec3304ab5c to your computer and use it in GitHub Desktop.
Save bih/152b44024fec3304ab5c to your computer and use it in GitHub Desktop.
Calculate how much you've paid to Spotify
// Go to https://www.spotify.com/account/subscription/receipt/
var Receipt = function(jquery){
this.id = $(jquery).find(".receipt-orderid").text();
this.id = $.trim(this.id);
this.id = parseInt(this.id);
this.date = $(jquery).find(".receipt-date").text();
this.date = new Date(Date.parse(this.date));
this.price = $(jquery).find(".receipt-price").text();
this.price = this.price.substring(1,10);
this.price = parseFloat(this.price);
};
var receipts = new Array();
$(".receipt").each(function(index, receipt){
receipts.push(new Receipt(receipt));
});
if(
receipts.count === 0 ||
window.location.hostname !== "www.spotify.com" ||
window.location.pathname.substring(3,33) !== "/account/subscription/receipt/"
) {
console.log("%c You need to visit https://www.spotify.com/account/subscription/receipt/ logged in to view how much you've paid to Spotify. ", "background: #2ebd59; color: #fff;");
} else {
var total_amount_paid_to_spotify = receipts.map(function(receipt){
return receipt.price;
}).reduce(function(total, receipt_price){
return total + receipt_price;
}).toFixed(2);
console.log("%c ", "background: #2ebd59; color: #fff;");
console.log("%c Total amount you have spent on Spotify: £" + total_amount_paid_to_spotify + " ", "background: #2ebd59; color: #fff;");
console.log("%c ", "background: #2ebd59; color: #fff;");
}
// Go to https://www.spotify.com/account/subscription/receipt/
var Receipt=function(t){this.id=$(t).find(".receipt-orderid").text(),this.id=$.trim(this.id),this.id=parseInt(this.id),this.date=$(t).find(".receipt-date").text(),this.date=new Date(Date.parse(this.date)),this.price=$(t).find(".receipt-price").text(),this.price=this.price.substring(1,10),this.price=parseFloat(this.price)},receipts=new Array;if($(".receipt").each(function(t,e){receipts.push(new Receipt(e))}),0===receipts.count||"www.spotify.com"!==window.location.hostname||"/account/subscription/receipt/"!==window.location.pathname.substring(3,33))console.log("%c You need to visit https://www.spotify.com/account/subscription/receipt/ logged in to view how much you've paid to Spotify. ","background: #2ebd59; color: #fff;");else{var total_amount_paid_to_spotify=receipts.map(function(t){return t.price}).reduce(function(t,e){return t+e}).toFixed(2);console.log("%c ","background: #2ebd59; color: #fff;"),console.log("%c Total amount you have spent on Spotify: £"+total_amount_paid_to_spotify+" ","background: #2ebd59; color: #fff;"),console.log("%c ","background: #2ebd59; color: #fff;")}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment