Skip to content

Instantly share code, notes, and snippets.

@inverse
Last active February 10, 2016 06:02
Show Gist options
  • Save inverse/4aed673c0b0d51dc2d3d to your computer and use it in GitHub Desktop.
Save inverse/4aed673c0b0d51dc2d3d to your computer and use it in GitHub Desktop.

Revisions

  1. inverse revised this gist Feb 6, 2016. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions lastfmextra.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name Last.fm Extra
    // @namespace https://malachisoord.com/
    // @version 0.1.2
    // @version 0.1.3
    // @description Provide missing extra functionality to Last.fm
    // @author Malachi Soord
    // @match http://www.last.fm/*
    @@ -11,6 +11,7 @@

    'use strict';


    $(document).on('ready', function() {

    var url = window.location.href;
    @@ -35,18 +36,22 @@ $(document).on('ready', function() {
    var template = '<div id="listening" class="kerve widget widget_listeningnow"><div class="nowwrap noselect"></div></div>';

    $(template).insertAfter('#mobile_pos_4');

    var found = false;

    $.each(users, function(index, user) {
    var requestUrl = libraryUrl.replace('{user}', user);
    $.ajax(requestUrl, {
    success: function(data) {
    var $data = $(data);
    var scrobbles = $data.find('#mantle_skin > div.container.page-content > div > div.col-main > ul > li:nth-child(1) > p').html() || 0;

    if (scrobbles !== 0) {
    found = true;
    var pictureUrl = $data.find('div.header-avatar > div > a > img').prop('src');
    var userTemplate = $('<div style="padding-bottom:5px;"><a href="' + requestUrl + '"><img src="' + pictureUrl + '" class="avatar" style="width:40px;margin-right:10px;" title ="' + user +'"/>' + scrobbles + ' scrobbles</a></div>');
    $('#listening').append(userTemplate);
    } else if (index === (users.length-1) && !found) {
    $('#listening').append('None of your friends listen to this artist :(');
    }
    }
    });
    @@ -87,5 +92,4 @@ $(document).on('ready', function() {
    loadUsers(followingUrl, users, page);
    }
    }

    });
    });
  2. inverse revised this gist Jan 17, 2016. 1 changed file with 15 additions and 7 deletions.
    22 changes: 15 additions & 7 deletions lastfmextra.user.js
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,33 @@
    // ==UserScript==
    // @name Last.fm Extra
    // @namespace https://malachisoord.com/
    // @version 0.1
    // @version 0.1.2
    // @description Provide missing extra functionality to Last.fm
    // @author Malachi Soord
    // @match http://www.last.fm/music/*
    // @match http://www.last.fm/*/music/*
    // @match http://www.last.fm/*
    // @require https://code.jquery.com/jquery-2.2.0.min.js
    // @run-at document-idle
    // ==/UserScript==

    'use strict';

    $(document).ready(function() {
    $(document).on('ready', function() {

    var url = window.location.href;

    console.log('xx: ' + url);

    if (!url.match(/^http:\/\/www\.last.fm\/([a-z]{2}\/)?music\/[^\/]+$/)) {
    return;
    }

    console.log('xx: running');

    var user = $('#mantle_skin > div.container.page-content > div > div.col-sidebar > div.kerve.widget.widget_trends').attr('data-user');

    var users = getUsers();

    var libraryUrl = 'http://www.last.fm/user/{user}/library/music/{artist}';

    var url = window.location.href;

    var artist = url.substring(url.lastIndexOf('/') + 1);

    libraryUrl = libraryUrl.replace('{artist}', artist);
    @@ -47,9 +53,11 @@ $(document).ready(function() {
    });



    function getUsers() {
    var users = GM_getValue('users', []);
    if (users.length === 0) {
    var user = $('#mantle_skin > div.container.page-content > div > div.col-sidebar > div.kerve.widget.widget_trends').attr('data-user');
    var followingUrl = 'http://www.last.fm/user/{user}/following?page='.replace('{user}', user);
    loadUsers(followingUrl, users, 1);
    GM_setValue('users', users);
  3. inverse revised this gist Jan 17, 2016. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions lastfmextra.user.js
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@
    // @description Provide missing extra functionality to Last.fm
    // @author Malachi Soord
    // @match http://www.last.fm/music/*
    // @match http://www.last.fm/*/music/*
    // @require https://code.jquery.com/jquery-2.2.0.min.js
    // @run-at document-idle
    // ==/UserScript==
    @@ -79,8 +80,4 @@ $(document).ready(function() {
    }
    }

    });




    });
  4. inverse created this gist Jan 17, 2016.
    86 changes: 86 additions & 0 deletions lastfmextra.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    // ==UserScript==
    // @name Last.fm Extra
    // @namespace https://malachisoord.com/
    // @version 0.1
    // @description Provide missing extra functionality to Last.fm
    // @author Malachi Soord
    // @match http://www.last.fm/music/*
    // @require https://code.jquery.com/jquery-2.2.0.min.js
    // @run-at document-idle
    // ==/UserScript==

    'use strict';

    $(document).ready(function() {

    var user = $('#mantle_skin > div.container.page-content > div > div.col-sidebar > div.kerve.widget.widget_trends').attr('data-user');

    var users = getUsers();

    var libraryUrl = 'http://www.last.fm/user/{user}/library/music/{artist}';

    var url = window.location.href;

    var artist = url.substring(url.lastIndexOf('/') + 1);

    libraryUrl = libraryUrl.replace('{artist}', artist);

    var template = '<div id="listening" class="kerve widget widget_listeningnow"><div class="nowwrap noselect"></div></div>';

    $(template).insertAfter('#mobile_pos_4');

    $.each(users, function(index, user) {
    var requestUrl = libraryUrl.replace('{user}', user);
    $.ajax(requestUrl, {
    success: function(data) {
    var $data = $(data);
    var scrobbles = $data.find('#mantle_skin > div.container.page-content > div > div.col-main > ul > li:nth-child(1) > p').html() || 0;

    if (scrobbles !== 0) {
    var pictureUrl = $data.find('div.header-avatar > div > a > img').prop('src');
    var userTemplate = $('<div style="padding-bottom:5px;"><a href="' + requestUrl + '"><img src="' + pictureUrl + '" class="avatar" style="width:40px;margin-right:10px;" title ="' + user +'"/>' + scrobbles + ' scrobbles</a></div>');
    $('#listening').append(userTemplate);
    }
    }
    });
    });


    function getUsers() {
    var users = GM_getValue('users', []);
    if (users.length === 0) {
    var followingUrl = 'http://www.last.fm/user/{user}/following?page='.replace('{user}', user);
    loadUsers(followingUrl, users, 1);
    GM_setValue('users', users);
    }

    return users;
    }

    function loadUsers(followingUrl, users, page) {

    var response = $.ajax({
    type: 'GET',
    url: followingUrl + page++,
    async: false
    }).responseText;

    var $response = $(response);

    var $users = $(response).find('div.username > a');

    $.each($users, function() {
    users.push($.trim($(this).text()));
    });

    var $next = $response.find('li.next > a');
    if ($next.length === 1) {
    loadUsers(followingUrl, users, page);
    }
    }

    });