(function() {
    var options;
    var current = {};

    var trackInfo = function(context) {
        var player = $(context);
        var title;
        if ($(context).parent().hasClass('playlist-player')) {
            title =  $('.tracks li.playing .info a').text().trim();
        }

        if(!title)
            title = $('.soundTitle__title', player).text().trim();

        if(!title)
            title = $('.info-header h3 a, .info-header h1 em', player).text().trim();

        return title.split(" - ");
    };

    var duration = function(context) {
        var node = $('span.duration', context);
        if (node.length)
            return parseInt($(node).attr('title').substring(2), 10);

        node = $('.timeIndicator__total', context);
        if (node.length) {
            // time is given as h.m.s
            var digits = node[0].innerHTML.split(/\D/),
                seconds = 0, length, digit;

            length = digits.length;
            if (length > 3)
                return;

            while (digits.length) {
                d = digits.pop();
                seconds += parseInt(d, 10) * Math.pow(60, length - digits.length - 1);
            }
            return seconds;
        }
    };

    var song = function(context) {
        var track = trackInfo(context);
        return {
                'artist': track[0],
                'track': track[1],
                'duration': duration(context)
        };
    };

    var container = function(context) {
        var parent;
        parent = $(context).closest('li.set')[0] ||  // 'old' soundcloud
                 $(context).closest('div.player')[0] ||
                 $(context).closest('div.sound.playing')[0];  // 'new' ...

        if (!parent) {
            // Couldn't find container element for this song...
        }

        return parent;
    };

    $(document).ready(function() {
        var selectors = 'div.timeIndicator__current, .timecodes .editable';

        $(selectors).live('DOMSubtreeModified', function() {
            var next = $(this).hasClass('timeIndicator__current');

            var parent = $(this).closest('.playing');
            if (!parent.length)
                return;

            if (!current || !current.context || current.context[0] != parent[0]) {
                current = {submitted: false};
                current.context = parent;
            }

            if (!current.player) {
                current.player = container(current.context);
                return;
            }

            if (current.validating)
                return;

            if (next && !parent.hasClass('endOfSound'))
                return;

            var playhead = $('.playhead[style]', parent);
            if (!next && parseFloat(playhead.attr('style').substring(6)) < 70)
                return;

            current.validating = true;

            var s = song(current.player);
            chrome.extension.sendRequest({type: 'validate',
                                        artist: s.artist,
                                         track: s.track},
            function(response) {
                current.validated = response;
                if (response !== false) {
                    chrome.extension.sendRequest({type: 'nowPlaying',
                                                artist: response.artist,
                                                 track: response.track,
                                              duration: s.duration});
                }

                else {
                    chrome.extension.sendRequest({type: 'nowPlaying',
                                              duration: s.duration});
                }
            });
        });
    });

    $(window).unload(function() {
        chrome.extension.sendRequest({type: 'reset'});
        return true;
    });
})();

@@ -139,16 +139,17 @@
  title;%0A
+%0A
         
@@ -200,18 +200,16 @@
 layer'))
- %7B
 %0A       
@@ -268,26 +268,16 @@
 .trim();
-%0A        %7D
 %0A%0A      
@@ -471,22 +471,27 @@
         
-return
+trackInfo =
  title.s
@@ -502,16 +502,386 @@
 (%22 - %22);
+%0A%0A        if(!trackInfo%5B1%5D)%0A            return %5Bartist(context),title%5D;%0A%0A        return trackInfo;%0A    %7D;%0A%0A    var artist = function(context) %7B%0A        var node = $('.info-header .user-name', context);%0A        if (node.length)%0A            return node%5B0%5D.text;%0A%0A        node = $('.soundTitle__username', context);%0A        if (node.length)%0A            return node%5B0%5D.text;
 %0A    %7D;%0A

use username if track title is not in "artist - track" format