-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
45 lines (38 loc) · 1.04 KB
/
main.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
const callback = (result, onInsert) => {
const activities = result.activities;
if (!activities.length) {
return;
}
chrome.storage.sync.get(['lastFmUser'], res => {
if (!res.lastFmUser) {
return;
}
lastFm.getScrobbles(res.lastFmUser, {
start: activities[0].startTime,
end: activities[activities.length - 1].endTime
}, (scrobbles) => {
onScrobbles(activities, scrobbles);
onInsert();
});
});
}
const onScrobbles = (activities, scrobbles) => {
console.log(activities, scrobbles);
let a = 0;
let s = 0;
while (a < activities.length && s < scrobbles.length) {
const activity = activities[a];
const scrobbleTime = moment.unix(scrobbles[s].date['uts']);
if (scrobbleTime.isBefore(activity.startTime)) {
++s;
continue;
}
if (scrobbleTime.isAfter(activity.endTime)) {
++a;
continue;
}
activities[a].contentBox.innerHTML += scrobbles[s]['artist']['#text'] + ": " + scrobbles[s]['name'] + '</br>';
++s;
}
};
let t = new Timeline(callback);