forked from justan/gmscrobber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqqmusicscrobber.user.js
68 lines (62 loc) · 2.49 KB
/
qqmusicscrobber.user.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
// ==UserScript==
// @name QQ音乐 online scrobbler
// @namespace http://gmscrobber.whosemind.net
// @description 记录qq在线音乐到 last.fm
// @match http://y.qq.com/
// @match http://y.qq.com/?*
// @match http://y.qq.com/#*
// @exclude http://y.qq.com/y/*
// @require https://raw.github.com/justan/gmscrobber/master/simple_scrobbler_user.js
// @version 0.0.4
// @changelog firefox 17 支持
// @uso:script 136050
// ==/UserScript==
var meta = uso.metaParse(GM_info.scriptMetaStr);
var init = function(){
log('init');
scrobber.setSongInfoFN(getSongInfo, {checktime: 4000});
document.getElementsByClassName('player_bar')[0].addEventListener('click', function(e){
var oldTime = getSongInfo().playTime;
setTimeout(function(){
var newTime = getSongInfo().playTime;
offset = oldTime - newTime;
scrobber.seek(offset);
}, 0);
}, true);
scrobber.on('nowplaying', function(){
var loveEle = document.getElementsByClassName('music_op')[0].firstChild;
loveEle.addEventListener('click', function(e){
if(loveEle.title == '喜欢'){
scrobber.love();
}else if(loveEle.title == '取消喜欢'){
scrobber.unlove();
}
}, false);
scrobber.getInfo(scrobber.song, function(info){
document.getElementById('divplayer').title = '在 last.fm 中记录: ' + info.len + ' 次';
//同步 last.fm 红星歌曲到 qq music
if(info.islove == '1' && loveEle.title == '喜欢' || info.islove == '0' && loveEle.title == '取消喜欢'){
//unsafeWindow.g_topPlayer.like(null, loveEle, unsafeWindow.g_topPlayer.getCurSongInfo());
document.getElementsByClassName('music_op')[0].children[0].click();
}
});
});
};
var scrobber = new Scrobbler({
name: 'QQ 音乐',
ready: init
});
var getSongInfo = function(){
var song = {};
var songinfo = document.getElementById('divsonginfo');
song.title = songinfo.getElementsByClassName('music_name')[0].title.replace(/\([^\)]*\)/, '');
song.artist = songinfo.getElementsByClassName('singer_name')[0].title;
song.duration = timeParse(document.getElementById('ptime').innerHTML);
song.playTime = song.duration * document.getElementById('spanplaybar').style.width.replace(/%/, '') / 100;
song.album = songinfo.getElementsByClassName('album_pic')[0].title;
return song;
};
var timeParse = function(timeStr){
var ts = timeStr.split(':');
return ts[0] * 60 + ts[1] * 1;
};