Skip to content

Commit

Permalink
init tieba
Browse files Browse the repository at this point in the history
  • Loading branch information
fayland committed May 12, 2014
1 parent 23bfa05 commit 72d6f8f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
1 change: 0 additions & 1 deletion js/qiandao/taobao.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
}
});
});

}(window, document, Zepto);
43 changes: 0 additions & 43 deletions js/qiandao/weibo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,4 @@
});
});

}(window, document, Zepto);


!function(win, doc, $){

$(doc).ready(function() {
// only do it when login
if (1) { // no way to find
chrome.runtime.sendMessage({method: "getLocalStorage", key: "suning_status"}, function(res) {
var status = res.data;
var today = (new Date()).toDateString();
if (! (status && today === status)) {
$.ajax({
type : "POST",
url : 'http://vip.suning.com/ams-web/world/pointSign.htm?r=' + Math.random(),
dataType : 'json',
success : function(data) {
// copied from http://vip.suning.com/
if (data.errorFlag ==" Y"){
return;
}

if (data.pointGetInfo.pointsQuantity) {
chrome.runtime.sendMessage({
method: "setLocalStorage", key: "suning_status", val: today
}, function(res) {});
chrome.runtime.sendMessage({
method: "setLocalStorage", key: "suning_points", val: data.pointValue.totalPoint
}, function(res) {});
console.log('[qiandao][suning] signIn OK.');
// console.log(data);
}
}
});
} else {
console.log('[qiandao][suning] already signIn today.');
}
});
} else {
console.log('[qiandao][suning] not login yet.');
}
});

}(window, document, Zepto);
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
{
"matches": [ "http://tieba.baidu.com/*" ],
"js": [ "js/zepto.min.js", "js/qiandao/baidu_tieba.js" ],
"js": [ "js/zepto.min.js", "js/qiandao/tieba.js" ],
"run_at": "document_end"
}
],
Expand Down
34 changes: 33 additions & 1 deletion src/bg/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
success : function(data) {
console.log(data);
// {"errcode":0,"msg":null,"data":[268,2]}
if (data.errcode == 0) { // 1 is OK, 2 is already done
if (data.errcode == 0) {
var today = (new Date()).toDateString();
localStorage.setItem('weibo_status', today);
localStorage.setItem('weibo_points', data.data[1]);
Expand All @@ -57,6 +57,38 @@
});
}
});
} else if (request.method == 'tieba_qiandao') {
console.log('tieba qiandao');
chrome.cookies.getAll({domain:"tieba.baidu.com"}, function (cookies){
var is_logined = 0;
for (var i in cookies) {
if (cookies[i].name == 'BAIDUID') {
is_logined = 1;
}
}
console.log('is_logined:' + is_logined);
console.log(request);
is_logined = 0;
if (is_logined) {
var url = 'http://tieba.baidu.com/sign/add';
$.ajax({
type : "POST",
url : url,
dataType : 'json',
success : function(data) {
console.log(data);
// {"no":0,"error":"","data":{"errno":0,"errmsg":"success","sign_version":2,"is_block":0,"finfo":{"forum_info":{"forum_id":8021166,"forum_name":"\u767e\u5ea6\u5f71\u68d2"},"current_rank_info":{"sign_count":1101}},"uinfo":{"user_id":889003992,"is_sign_in":1,"user_sign_rank":1101,"sign_time":1399875492,"cont_sign_num":1,"total_sign_num":2,"cout_total_sing_num":2,"hun_sign_num":1,"total_resign_num":0,"is_org_name":0}}}
if (data.data.errno == 0) {
var today = (new Date()).toDateString();
localStorage.setItem('tieba_status', today);
}
},
error: function(err) {
console.log(err);
}
});
}
});
} else if (request.method == "getLocalStorage") {
sendResponse({data: localStorage[request.key]});
} else if (request.method == "setLocalStorage") {
Expand Down

0 comments on commit 72d6f8f

Please sign in to comment.