// ==UserScript== // @name Last.fm play statistics! // @version 1.3.2 // @namespace http://code.google.com/p/lastfm-gm-scripts/ // @description Displays a statistic after the number of played tracks on Last.fm. // @identifier http://lastfm-gm-scripts.googlecode.com/svn/trunk/lastfmplaystatistics.user.js // @include http://www.last.fm/user/* // @include http://beta.last.fm/user/* // @include http://last.fm/user/* // @include http://www.lastfm.*/user/* // ==/UserScript== var SCRIPT = { name: "Last.fm play statistics!", namespace: "http://code.google.com/p/lastfm-gm-scripts/", description: "Displays a statistic after the number of played tracks on Last.fm", identifier: "http://lastfm-gm-scripts.googlecode.com/svn/trunk/lastfmplaystatistics.user.js", source: "http://code.google.com/p/lastfm-fm-scripts/", version: "1.3.2", date: (new Date(2007, 7 - 1, 8)).valueOf() }; // arvid seems to be unavailable, so I fixed the script and published it under a new name. // david@vidmar.net // http://www.vidmar.net/ //This is a complete rewrite of http://www.greasemonkeyed.com/scripts/show/931 in order to make it work with //Last.fm //- arvid.jakobsson@gmail.com /* Changelog: [M Lenzen - LucidCognition] 2007-07-08 1.3.2 Added Include for non-English domains Added option to use reset date 2007-03-31 1.3.1 Use built in toFixed function 2007-03-29 1.3.0 Added automatic updates 2006-12-30 1.2f * Changed to correctly parse tracks played on profiles that are reset. 2006-12-29 1.2f * Updated parsing of tracksplayed to work with the latest last.fm update. [Dennis Burke - theboinkbaron] 2006-09-23 * Changes to work with last.fm's new css layout * I rewrote some of the functions to be more accurate. It used to calculate everything by multiplying each successive statistic by the factor difference between them. It now calculates the difference in time and multiplies out to give the correct stats. Call me crazy but this works better. Oh, and I also added an average per year. [Stephen Paulger] 2005-12-01 1.2e * Rewrite due to HTML change, also I made the registration date match() less specific to allow the script to work on pages of users who are subscribers, staff, moderators etc. [David] 2005-09-28 1.2d * I fixed the script to work with last.fm again. arvid seems unavailable available. [arvid] 2005-08-26 1.2 * Due to a change in the HTML of last.fm which milk pointed out (thanks!), the script stopped working. Changed it to work again. 2005-08-17 1.1 * Some code clean up, removed unnecessary GM_logs etc * Changed the code in accordance to milks suggestions (http://www.userscripts.org/people/327). Thanks for the suggestions! The script works better now when you've got more than zero posts in the forum. 2005-08-14 1.0 * Initial version */ /* BEGIN LICENSE BLOCK Copyright (C) 2005 Arvid Jakobsson arvid.jakobsson@gmail.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You can download a copy of the GNU General Public License at http://www.gnu.org/licenses/gpl.html or get a free printed copy by writing to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. END LICENSE BLOCK */ function xpath(query, context) { return document.evaluate(query, context, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); } function toggleUseResetDate() { var value = GM_getValue("use_reset_date", 0); if(value == 0) { value = 1; } else { value = 0; } GM_setValue("use_reset_date", value); } // check for updates try { window.addEventListener("load", function () { try { (unsafeWindow || window.wrappedJSObject || window) .UserScriptUpdates.requestAutomaticUpdates(SCRIPT); } catch (ex) {} }, false); } catch (ex) {} var panel = document.getElementById("avatarPanel"); var reg_date = panel.innerHTML.match(/Registered:<\/strong>(.*)/)[1]; if(GM_getValue("use_reset_date", 0) == 1 && panel.innerHTML.match(/\(reset on /)) { reg_date = panel.innerHTML.match(/\(reset on ([^<]*)\)/)[1]; } var tracksplayed = document.getElementById("avatarPanel").innerHTML.match(/<\/strong>\W+([0-9,]+)<\/span>/)[1].replace(/,/, ""); var reg_date_ms = Date.parse(reg_date); var now = new Date(); var diff = Math.round(now - reg_date_ms)/1000; //Sounds like this reg_date_ms variable is in milliseconds, so we divide by 1000 to give actual diff. var hours = diff / (60*60); var days = diff / (60*60*24); var weeks = diff / (60*60*24*7); var months = diff / (60*60*24*31); var years = diff / (60*60*24*365); var tph = (tracksplayed / hours).toFixed(3); var tpd = (tracksplayed / days).toFixed(3); var tpw = (tracksplayed / weeks).toFixed(3); var tpm = (tracksplayed / months).toFixed(3); var tpy = (tracksplayed / years).toFixed(3); var paragraphs = xpath(".//DIV[@class='c']/P", panel); for (var i = 0; i < paragraphs.snapshotLength; i++) { var paragraph = paragraphs.snapshotItem(i); if (paragraph.innerHTML.match(/Tracks played:/)) { var p = new Array(); p[0] = document.createElement("span"); p[0].innerHTML = "Tracks per year: " + tpy + "
"; p[1] = document.createElement("span"); p[1].innerHTML = "Tracks per month: " + tpm + "
"; p[2] = document.createElement("span"); p[2].innerHTML = "Tracks per week: " + tpw + "
"; p[3] = document.createElement("span"); p[3].innerHTML = "Tracks per day: " + tpd + "
"; p[4] = document.createElement("span"); p[4].innerHTML = "Tracks per hour: " + tph + "
"; for (var ii = 0; ii < 5; ii++) { paragraph.insertBefore(p[ii], paragraph.childNodes[4]); } } } if(GM_getValue("use_reset_date", 0) == 0) { GM_registerMenuCommand("Play Stats - Use Reset Date", toggleUseResetDate); } else { GM_registerMenuCommand("Play Stats - Do NOT Use Reset Date", toggleUseResetDate); }