cgravolet / scroblr

A lightweight browser extension that scrobbles the music you listen to on the web.
http://scroblr.fm
Other
230 stars 62 forks source link

Rockradio.com support #92

Open snakecase opened 9 years ago

snakecase commented 9 years ago

I'm not a developer myself so I don't know how to export src's to Chrome as extension ("Load unpacked extension" gives an error) to debug my code but if someone can I will be very grateful. So instead of commit I'll write it down:

manifest.json

"*://*.rockradio.com/*",

index.js

exports.rockradio    = require("./rockradio");

rockradio.js

"use strict";

var $      = require("jquery");
var Plugin = require("../modules/Plugin");
var Utils    = require("../modules/Utilities");
var rockradio = Object.create(Plugin);

rockradio.init("rockradio", "Rockradio"); // name, displayName

rockradio.test = function () {
    var domainTest = /rockradio\.com/i.test(document.location.hostname);
    var playerTest = $(".status") === "now playing" : "stopped";

    return domainTest && playerTest;
};

rockradio.scrape = function () {
    var artistsong = $(".title").text().split("-");
    var info = {
        artist:  artistsong.length > 1 ? $.trim(artistsong[1]) : "",
        title:  artistsong.length > 1 ? $.trim(artistsong[2]) : "",
        elapsed:  Utils.calculateDuration($(".elapsed").text()),
        stopped: $(".status") === "stopped",
    };

    return info;
};

module.exports = rockradio;

Other AudioAddict Network sites (http://www.radiotunes.com/ http://www.jazzradio.com/ http://www.di.fm/) use the same player so if someone want he can easily add them too.

Thanks.