-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
executable file
·54 lines (48 loc) · 1.31 KB
/
node_helper.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
/* Magic Mirror
* Node Helper: MMM-Bilibili-SubCount
*
* By Jimmy Lin (https://github.com/jimmy0017)
* MIT Licensed.
*/
var NodeHelper = require("node_helper");
const fetch = require("node-fetch");
module.exports = NodeHelper.create({
start: function () {
this.finalData = [];
this.channelId = null;
// this.apiKey = null;
},
socketNotificationReceived: function (notification, payload) {
switch (notification) {
case "MMM-Bilibili-SubCount-HERE_IS_CONFIG":
// this.apiKey = payload.apiKey;
this.channelId = payload.channelId;
this.breakDownChannelIds();
break;
case "UPDATE_PLEASE":
this.crypto();
break;
}
},
breakDownChannelIds: function () {
this.url =
"http://api.bilibili.com/x/web-interface/card?mid=" + this.channelId;
console.log(this.url);
this.getData(this.url);
},
getData: function (url) {
// fetch(url + "&key=" + this.apiKey, {
fetch(url, {
method: "GET",
headers: {
Accept: "application/json"
}
})
.then((response) => response.json())
.then((data) => this.handleData(data))
.catch((error) => console.log("Error: ", error));
},
handleData: function (data) {
this.sendSocketNotification("MMM-Bilibili-SubCount-DATA_IS_READY", data);
}
});