-
Notifications
You must be signed in to change notification settings - Fork 2
/
user.js
82 lines (75 loc) · 2.7 KB
/
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Created by zzzz on 3/17/17.
*/
function UserBBS(bbsUrlPrefix, updateCallback) {
this.uid = null;
// {
// avatar: 'http://xxxxxx&size=medium',
// username: 'gamerteam',
// grouptitle: 'Lv.9 xxx',
// credits: '6666',
// creditslower: '10000'
// }
this.userInfo = null;
this.pm = 0;
this.notice = 0;
var self = this;
var headUrlPrefix = bbsUrlPrefix + "/uc_server/avatar.php?uid=";//头像API
var userProfileUrl = bbsUrlPrefix + "/api/mobile/index.php?module=profile";//用户信息API
function saveToStorage(callback) {
callback = callback || function () {};
var storage = chrome.storage.local;
if (self.uid) {
storage.set({'uid': self.uid, 'info': self.userInfo,'cookies': self.cookies}, callback.bind(undefined));
} else {
storage.remove(['uid', 'info', 'cookies'], callback.bind(undefined));
}
}
function loadFromStorage(callback) {
callback = callback || function () {};
var storage = chrome.storage.local;
storage.get(['uid', 'info','cookies'], function (data) {
if (data.uid) {
self.uid = data.uid;
self.userInfo = data.info;
self.cookies = data.cookies;
} else {
self.uid = null;
self.userInfo = null;
self.cookies = null;
}
callback();
});
}
this.syncUserInfo = function (callback) {
callback = callback || function () {};
$.ajax({
url: bbsUrlPrefix + '/api/mobile/index.php?module=profile',
contentType: 'MCBBSHelper Plugin/1.0(zhaisoul.650@gmail.com)'
}).done(function (data) {
var json = data['Variables'];
self.uid = json['member_uid'];
self.userInfo = {
avatar: json['member_avatar']
.replace('size=small', 'size=middle')
.replace(/http:\/\/[^\/]+/, bbsUrlPrefix),
username: json['member_username'],
grouptitle: json['space'].group.grouptitle,
credits: json['space'].credits,
creditslower: json['space'].creditslower || json['space'].credits
};
self.cookies ={
auth : json["auth"],
saltkey : json["saltkey"],
cookiepre : json["cookiepre"]
};
self.pm = json['space'].newpm || 0;
self.notice = json['space'].newprompt || 0;
saveToStorage(function () {
updateCallback();
callback();
});
});
};
loadFromStorage(updateCallback);
}