/
extension.js
47 lines (42 loc) · 1.26 KB
/
extension.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
const vscode = require('vscode');
const request = require('request');
let GuP;
let timer;
exports.activate = function activate(context) {
init();
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(handleConfigChange));
};
exports.deactivate = function deactivate() {
clearInterval(timer);
};
function init() {
setView();
const hour = (new Date).getHours();
const interval = parseInt(vscode.workspace.getConfiguration().get('gup.interval'));
if ([9, 10, 11, 13, 14].indexOf(hour) > -1) {
timer = setInterval(setView, interval < 10000 ? 10000 : interval);
}
}
function setView() {
request.get("http://hq.sinajs.cn/list=" + vscode.workspace.getConfiguration().get('gup.code'), function (err, res, body) {
const GuPList = body.split(';').slice(0, -1).map(item => item.split('"')[1].split(',')[3].slice(0, -1))
const message = GuPList.join(' ') || 'Check Your Setting';
if (GuP) {
GuP.text = message;
} else {
const barItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 999999);
barItem.text = message;
barItem.show();
GuP = barItem;
}
});
}
function handleConfigChange() {
clearInterval(timer);
if (GuP) {
GuP.hide();
GuP.dispose();
GuP = null;
}
init();
}