Skip to content

Commit

Permalink
add weibo, fix xiami
Browse files Browse the repository at this point in the history
  • Loading branch information
fayland committed May 24, 2014
1 parent 6d983d6 commit 83ba0f0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 71 deletions.
35 changes: 31 additions & 4 deletions js/qiandao/weibo.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
!function(win, doc, $){

$(doc).ready(function() {
chrome.runtime.sendMessage({method: "getLocalStorage", key: "weibo_status"}, function(res) {
chrome.runtime.sendMessage({method: "getLocalStorage", key: "weipan_status"}, function(res) {
var status = res.data;
var today = (new Date()).toDateString();
if (! (status && today === status)) {
// need cookie
chrome.runtime.sendMessage({method: "weibo_qiandao"}, function(res) {});
// check if logined
if (doc.cookie.match(/login_sid_t=/)) {
$.ajax({
type : "POST",
url : 'http://vdisk.weibo.com/task/checkIn',
async : !1,
dataType : 'json',
beforeSend : function (xhr) {
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
},
success : function(data) {
// {"errcode":0,"msg":null,"data":[268,2]}
// {"errcode":1,"msg":"已经签到过了","data":{"app_uid":2583117564,"time":1400896165,"size":376,"star":3,"sent_weibo_size":0,"date":"20140524","quota":4497}}
if (data.errcode == 0 || data.errcode == 1) {
chrome.runtime.sendMessage({
method: "setLocalStorage", key: "weipan_status", val: today
}, function(res) {});
}
if (data.errcode == 0) {
chrome.runtime.sendMessage({
method: "setLocalStorage", key: "weipan_points", val: data.data[0]
}, function(res) {});
}
},
error: function(err) {
console.log(err);
}
});
}
} else {
console.log('[qiandao][weibo] already signIn today.');
console.log('[qiandao][weipan] already signIn today.');
}
});
});
Expand Down
18 changes: 16 additions & 2 deletions js/qiandao/xiami.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
!function(win, doc, $){
$(doc).ready(function() {

chrome.runtime.sendMessage({method: "getLocalStorage", key: "xiami_status"}, function(res) {
var status = res.data;
var today = (new Date()).toDateString();
if (! (status && today === status)) {
// need cookie
chrome.runtime.sendMessage({method: "xiami_qiandao"}, function(res) {});
// check if logined
if (doc.cookie.match(/user=\d+/)) {
$.ajax({
type : "POST",
url : 'http://www.xiami.com/task/signin',
dataType : 'html',
success : function(data) {
if (parseInt(data) === 1 || parseInt(data) === 2) {
chrome.runtime.sendMessage({
method: "setLocalStorage", key: "xiami_status", val: today
}, function(res) {});
}
}
});
}
} else {
console.log('[qiandao][xiami] already signIn today.');
}
Expand Down
7 changes: 6 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@
"run_at": "document_end"
},
{
"matches": [ "http://*.xiami.com/*" ],
"matches": [ "http://*.xiami.com/*", "http://xiami.com/*" ],
"js": [ "js/zepto.min.js", "js/qiandao/xiami.js" ],
"run_at": "document_end"
},
{
"matches": [ "http://*.weibo.com/*", "http://weibo.com/*" ],
"js": [ "js/zepto.min.js", "js/qiandao/weibo.js" ],
"run_at": "document_end"
},
{
"matches": [ "http://tieba.baidu.com/*" ],
"js": [ "js/zepto.min.js", "js/qiandao/tieba.js" ],
Expand Down
63 changes: 0 additions & 63 deletions src/bg/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,44 +62,6 @@
return;
}

if (request.method === 'weibo_qiandao') {
return;
chrome.cookies.getAll({domain:"weibo.com"}, function (cookies){
var is_logined = 0;
for (var i in cookies) {
if (cookies[i].name === 'login_sid_t') {
is_logined = 1;
break;
}
}
console.log('is_logined:' + is_logined);
if (is_logined) {
$.ajax({
type : "POST",
url : 'http://vdisk.weibo.com/task/checkIn',
async : !1,
dataType : 'json',
beforeSend : function (xhr) {
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
},
success : function(data) {
console.log(data);
// {"errcode":0,"msg":null,"data":[268,2]}
if (data.errcode == 0) {
var today = (new Date()).toDateString();
localStorage.setItem('weibo_status', today);
localStorage.setItem('weibo_points', data.data[0]);
}
},
error: function(err) {
console.log(err);
}
});
}
});
return;
}

if (request.method === 'tieba_qiandao') {
chrome.cookies.getAll({domain:"tieba.baidu.com"}, function (cookies){
var is_logined = 0;
Expand Down Expand Up @@ -139,31 +101,6 @@
return;
}

if (request.method === 'xiami_qiandao') {
chrome.cookies.getAll({domain:"xiami.com"}, function (cookies){
var is_logined = 0;
for (var i in cookies) {
if (cookies[i].name === 'user') {
is_logined = 1;
break;
}
}
if (is_logined) {
$.ajax({
type : "POST",
url : 'http://www.xiami.com/task/signin',
dataType : 'html',
success : function(data) {
if (parseInt(data) === 1 || parseInt(data) === 2) {
localStorage.setItem('xiami_status', today);
}
}
});
}
});
return;
}

// utils
if (request.method === "getLocalStorage") {
sendResponse({data: localStorage[request.key]});
Expand Down
4 changes: 4 additions & 0 deletions src/browser_action/browser_action.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
<td>虾米</td><td id='xiami_status'></td><td id='suning_points'>-</td>
<td><a href='http://www.xiami.com/' target='_blank'>访问</a></td>
</tr>
<tr>
<td>微盘</td><td id='weipan_status'></td><td id='weipan_points'>-</td>
<td><a href='http://vdisk.weibo.com/' target='_blank'>访问</a></td>
</tr>
</table>
</div>
3 changes: 2 additions & 1 deletion src/browser_action/browser_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
'dianping_status',
'suning_status', 'suning_points',
'xiami_status',
'tieba_status'
'tieba_status',
'weipan_status', 'weipan_points'
];
$.each(ele, function(i, v) {
$('#' + v).text(localStorage.getItem(v));
Expand Down

0 comments on commit 83ba0f0

Please sign in to comment.