-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.js
191 lines (179 loc) · 8.24 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const buttons = require('sdk/ui/button/action');
const tabs = require('sdk/tabs');
const pageMod = require('sdk/page-mod');
const self = require('sdk/self');
const ss = require('sdk/simple-storage');
const system = require('sdk/system');
const sp = require('sdk/simple-prefs');
const nowPlayingIO = require('./lib/nowPlayingIO');
buttons.ActionButton({
id: 'unp-action',
label: 'Untamed Now Playing',
icon: {
'16': './ico/icon-16.png',
'32': './ico/icon-32.png',
'64': './ico/icon-64.png'
},
onClick: openPreferences
});
sp.on('options_button', function() {
openPreferences();
});
pageMod.PageMod({
include: self.data.url('common/options/index.html') + '*',
contentScriptFile: [
self.data.url('third-party/preact.min.js'),
self.data.url('third-party/preact-router.min.js'),
self.data.url('third-party/preact-markup.min.js'),
self.data.url('third-party/history.min.js'),
self.data.url('third-party/jquery-3.1.0.min.js'),
self.data.url('browserFunc.js'),
self.data.url('common/options/i18n.js'),
self.data.url('common/options/components/infoButton.js'),
self.data.url('common/options/components/header.js'),
self.data.url('common/options/components/settingsForm.js'),
self.data.url('common/options/pages/settings.js'),
self.data.url('common/options/pages/about.js'),
self.data.url('common/options/pages/changelog.js'),
self.data.url('common/options/pages/contact.js'),
self.data.url('common/options/pages/sites.js'),
self.data.url('common/options/app.js')
],
contentScriptWhen: 'ready',
contentScriptOptions: {
platform: system.platform
},
onAttach: function(worker) {
worker.port.on('getPrefs', function() {
worker.port.emit('prefs', ss.storage);
});
worker.port.on('setPref', function(message) {
ss.storage[message.key] = message.value;
});
worker.port.on('writeFile', function(message) {
nowPlayingIO.writeFile(message.filename, message.text).then(function() {
worker.port.emit(message.filename, 'success');
}, function(reason) {
worker.port.emit(message.filename, reason);
});
});
worker.port.on('createDirIfNotExists', function(message) {
const status = nowPlayingIO.createDirIfNotExists(message.directory);
if (status === 'success') {
worker.port.emit(message.directory, 'success');
} else {
worker.port.emit(message.directory, status);
}
});
worker.port.on('removeFile', function(filename) {
nowPlayingIO.removeFile(filename);
});
}
});
function createMusicWebsiteWorker(includes, script, attachTo) {
const param = {
include: includes,
contentScriptFile: [
self.data.url('third-party/jquery-3.1.0.min.js'),
self.data.url('browserFunc.js'),
self.data.url('common/websites-support/website.js'),
self.data.url('common/websites-support/websites/' + script)
],
contentScriptWhen: 'ready',
onAttach: onAttachNowPlaying
};
if (typeof attachTo !== 'undefined')
param.attachTo = attachTo;
pageMod.PageMod(param);
}
createMusicWebsiteWorker('*.music.163.com', 'netease.js', 'top');
createMusicWebsiteWorker('*.8tracks.com', '8tracks.js', 'top');
createMusicWebsiteWorker(/.*ah.fm\/player\/.*/, 'ahfm.js', 'top');
createMusicWebsiteWorker(/.*animenfo.com\/radio\/nowplaying.php/, 'animenfo.js', 'top');
createMusicWebsiteWorker(/.*www.beatport.com\/.*/, 'beatport.js', 'top');
createMusicWebsiteWorker('*.seoul.fm', 'seoulfm.js', 'top');
createMusicWebsiteWorker('*.deezer.com', 'deezer.js', 'top');
createMusicWebsiteWorker('*.di.fm', 'difm.js', 'top');
createMusicWebsiteWorker('*.jazzradio.com', 'jazzradio.js', 'top');
createMusicWebsiteWorker('*.classicalradio.com', 'classicalradio.js', 'top');
createMusicWebsiteWorker('*.rockradio.com', 'rockradio.js', 'top');
createMusicWebsiteWorker('*.distortionradio.com', 'distortionradio.js', 'top');
createMusicWebsiteWorker('*.hypem.com', 'hypem.js', 'top');
createMusicWebsiteWorker(
[
'*.last.fm',
'*.lastfm.de',
'*.lastfm.es',
'*.lastfm.fr',
'*.lastfm.it',
'*.lastfm.jp',
'*.lastfm.pl',
'*.lastfm.com.br',
'*.lastfm.ru',
'*.lastfm.se',
'*.lastfm.com.tr'
], 'lastfm.js', 'top');
createMusicWebsiteWorker('*.jamendo.com', 'jamendo.js', 'top');
createMusicWebsiteWorker('*.jango.com', 'jango.js', 'top');
createMusicWebsiteWorker('*.jombly.com', 'jombly.js', 'top');
createMusicWebsiteWorker('*.loopmasters.com', 'loopmasters.js', 'top');
createMusicWebsiteWorker('*.mixcloud.com', 'mixcloud.js', 'top');
createMusicWebsiteWorker(/.*music.amazon\..*/, 'musicamazon.js', 'top');
createMusicWebsiteWorker(/.*music.yandex\..*/, 'musicyandex.js', 'top');
createMusicWebsiteWorker('*.nightbot.tv', 'nightbottv.js', 'top');
createMusicWebsiteWorker('*.openwhyd.org','openwhyd.js','top');
createMusicWebsiteWorker('*.pandora.com', 'pandora.js', 'top');
createMusicWebsiteWorker('*.planeta.fm', 'planetafm.js', 'top');
createMusicWebsiteWorker(/.*play.google.com\/music.*/, 'playgoogle.js', 'top');
createMusicWebsiteWorker('*.player.epidemicsound.com', 'epidemicsound.js', 'top');
createMusicWebsiteWorker('*.player.siriusxm.com', 'siriusxm.js', 'top');
createMusicWebsiteWorker('*.pleer.com', 'pleer.js', 'top');
createMusicWebsiteWorker('*.plex.tv', 'plex.js', 'top');
createMusicWebsiteWorker(/.*open.spotify.com\/.*/, 'spotify.js', 'top');
createMusicWebsiteWorker('*.playmoss.com', 'playmoss.js', 'top');
createMusicWebsiteWorker('*.radio.yandex.ru', 'radioyandex.js', 'top');
createMusicWebsiteWorker(/.*radiorecord.ru\/player.*/, 'radiorecordplayer.js', 'top');
createMusicWebsiteWorker(/.*radiorecord.ru\/(?!player).*/, 'radiorecord.js', 'top');
createMusicWebsiteWorker('*.radiobells.com', 'radiobells.js', 'top');
createMusicWebsiteWorker(/.*player.radioultra.ru.*/, 'radioultra.js', 'top');
createMusicWebsiteWorker(/.*www\.radiotunes\.com\/.+/, 'radiotunes.js', 'top');
createMusicWebsiteWorker('*.slacker.com', 'slacker.js', 'top');
createMusicWebsiteWorker('*.soundcloud.com', 'soundcloud.js', 'top');
createMusicWebsiteWorker(/.*synchtu.be\/r\/Playhouse.*/, 'synchtube.js', 'top');
createMusicWebsiteWorker('*.themusicninja.com', 'themusicninja.js', 'top');
createMusicWebsiteWorker('*.tunein.com', 'tunein.js', 'top');
createMusicWebsiteWorker('*.vk.com', 'vk.js', 'top');
createMusicWebsiteWorker(/.*yggdrasilradio.net\/nowplaying.php/, 'yggdrasilradio.js', 'frame');
createMusicWebsiteWorker('*.youtube.com', 'youtube.js', 'top');
createMusicWebsiteWorker(/.*youtube.com\/tv.*/, 'youtubetv.js', 'top');
createMusicWebsiteWorker(/.*youtube-playlist-randomizer.valami.info.*/, 'youtubeplaylistrandomizer.js', 'top');
createMusicWebsiteWorker('*.zaycev.fm', 'zaycev.js', 'top');
createMusicWebsiteWorker('*.zvooq.com', 'zvooq.js', 'top');
createMusicWebsiteWorker(/.*listen.tidal.com\/.*/, 'tidal.js', 'top');
createMusicWebsiteWorker("*.monstercat.com", 'monstercat.js', 'top');
// Chinese sites
createMusicWebsiteWorker('*.play.baidu.com', 'playbaidu.js', 'top');
createMusicWebsiteWorker('*.player.kuwo.cn', 'kuwo.js', 'top');
createMusicWebsiteWorker('*.y.qq.com', 'qq.js', 'top');
createMusicWebsiteWorker(/.*xiami.com\/play.*/, 'xiami.js', 'top');
createMusicWebsiteWorker(/.*open.fm.*/, 'openfm.js', 'top');
createMusicWebsiteWorker(/.*www.eskago.pl\/radio.*/, 'eskago.js', 'top');
function onAttachNowPlaying(worker) {
worker.port.on('getPrefs', function() {
worker.port.emit('prefs', ss.storage);
});
worker.port.on('updateNowPlaying', function(data) {
nowPlayingIO.updateNowPlaying(data).then(function() {
worker.port.emit('updateNowPlaying', 'success');
}, function(reason) {
worker.port.emit('updateNowPlaying', 'failure: ' + reason);
});
});
worker.on('detach', function() {
if (ss.storage.unpAutoClear === true)
nowPlayingIO.clearNowPlaying(ss.storage.unpNoMusicMessage);
});
}
function openPreferences() {
tabs.open(self.data.url('common/options/index.html'));
}