forked from ylm201/douRadio
/
index.js
83 lines (77 loc) · 2.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var radio = {};
var jp_div = document.createElement('div');
var pref = widget.preferences;
$(document).ready(function () {
jp_div.id = "jquery_jplayer";
jp_div.className = "jp-jplayer";
document.body.appendChild(jp_div);
opera.postError("document ready");
$("#jquery_jplayer").jPlayer({
ready: function (event) {
opera.postError("jplayer ready");
radio = Radio.init($("#jquery_jplayer"));
},
swfPath: "lib/Jplayer.swf",
solution: "flash",
supplied: "mp3",
wmode: "window"
});
});
window.addEventListener("load", function () {
var theButton,
ToolbarUIItemProperties;
ToolbarUIItemProperties = {
title: "douRex",
icon: "img/icon_16.png",
popup: {
href: "popup.html",
width: 340,
height: 340
}
};
theButton = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
opera.contexts.toolbar.addItem(theButton);
if (!pref.version || pref.version !== widget.version) {
opera.extension.tabs.create({ focused: true, url: 'features.html' });
}
pref.version = widget.version;
}, false);
opera.extension.onmessage = function (e) {
var subject_id,
musician_id,
cid;
switch (e.data.action) {
case 'play_album':
subject_id = e.data.subject_id;
if (e.data.subject_id[7] === "\/") {
subject_id = e.data.subject_id.substr(0, 7);
}
localStorage.channel = 0;
radio.channel = 0;
radio.context = "channel:0|subject_id:" + subject_id;
opera.postError(radio.context);
radio.powerOn();
break;
case 'play_musician':
musician_id = e.data.musician_id;
localStorage.channel = 0;
radio.channel = 0;
radio.context = "channel:0|musician_id:" + musician_id;
opera.postError(radio.context);
radio.powerOn();
break;
case 'play_channel':
cid = e.data.channel_id;
localStorage.channel = cid;
radio.channel = cid;
opera.postError(radio.channel);
radio.powerOn();
break;
case 'nolrc':
opera.extension.broadcastMessage({
action: 'show',
song_info: 'Sorry, lyrics not found!'
});
break;
}
};