-
Notifications
You must be signed in to change notification settings - Fork 60
Plugin Development
Charles G. edited this page Mar 22, 2014
·
19 revisions
All plugins are stored in the src/js/plugins
directory and are referenced in src/js/plugins/index.js
. Plugins are used by the scroblr content-script in order to answer a few simple questions:
- Should this plugin be active in the current browser window?
- Is a song being played in the current browser window?
- If so, give me as much information about the track as you can.
Plugins inherit from the Plugin
object, and have the following methods and parameters:
- {String} name - The name of the plugin, preferably lowercase letters only (i.e. 'google')
- {String} displayName - The full name of the plugin that will be displayed to the user (i.e. 'Google Play')
- {Function} init - Init method, used when creating an instance of the Plugin object
- {Function} initialize - A method that will be called once when the plugin is activated (optional)
- {Function} scrape - When the plugin is activated, this method is called every 5 seconds, it's purpose is to scrape the page for track information
- {Function} test - This should return true or false whether the plugin should be activated or not, typically by testing the document location
Seeing is believing, below is an example of a simple plugin.
"use strict";
var $ = require("jquery");
var Plugin = require("../modules/Plugin");
var songza = Object.create(Plugin);
songza.init("songza", "Songza"); // name, displayName
songza.test = function () {
var domainTest = this.hostre.test(document.location.hostname);
var playerTest = $("#player").length > 0;
return domainTest && playerTest;
};
songza.scrape = function () {
var info = {
artist: $("#player .szi-artist").text(),
percent: parseFloat($("#player .szi-progress .szi-bar").width() / $("#player .szi-progress").width()),
stopped: $("#player .player-play").css("display") === "none" ? false : true,
title: $("#player .szi-title").text()
};
return info;
};
module.exports = songza;