Skip to content

Instantly share code, notes, and snippets.

@k0nserv
Last active December 7, 2015 11:24
Show Gist options
  • Save k0nserv/b3a593ab449f94bc0ac9 to your computer and use it in GitHub Desktop.
Save k0nserv/b3a593ab449f94bc0ac9 to your computer and use it in GitHub Desktop.
Figure out how much money you have contributed to the music industry by paying for Spotify. Run the following at https://www.spotify.com/se/account/subscription/receipt/.
(function (window) {
"use strict";
var isAtTheCorrectURL = location.href.indexOf("account/subscription/receipt/") !== -1;
if (!isAtTheCorrectURL) {
console.log("Please run this script at https://www.spotify.com/us/account/subscription/receipt/ after logging in");
return;
}
var payments = document.querySelectorAll("#table-receipts > tbody > tr > td.receipt-price");
if (payments.length === 0) {
console.log("It seems like you haven't made any payments, you should start by doing that");
return;
}
var currency = null,
firstItem = payments[0].innerText;
if (firstItem.indexOf("kr") !== -1) {
currency = 'SEK';
} else if (firstItem.indexOf("$") !== -1) {
currency = 'USD';
} else {
alert("Unknown currency :/");
return;
}
var amount = [].reduce.call(payments, function (previousValue, element) {
var price = null;
if (currency === 'SEK') {
price = element.innerText.replace(',', '.');
price = price.replace(/[^\d\.]/gi, '');
return previousValue + parseFloat(price);
} else if (currency === 'USD') {
price = element.innerText.replace(/[^\d\.]/gi, '');
return previousValue + parseFloat(price);
}
return null;
}, 0);
var message = "I have contributed " + Math.round(amount) + " " + currency + " to the music industry by using @spotify #spotifypays";
console.log(message)
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment