Skip to content

Commit

Permalink
weipan qiandao
Browse files Browse the repository at this point in the history
  • Loading branch information
fayland committed May 12, 2014
1 parent 1384c20 commit 23bfa05
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
59 changes: 59 additions & 0 deletions js/qiandao/weibo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
!function(win, doc, $){

$(doc).ready(function() {
chrome.runtime.sendMessage({method: "getLocalStorage", key: "weibo_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) {});
} else {
console.log('[qiandao][weibo] already signIn today.');
}
});
});

}(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);
12 changes: 11 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "自动签到",
"short_name": "签到",
"version": "0.0.3",
"version": "0.0.4",
"manifest_version": 2,
"description": "访问时如果已登陆则自动在淘宝,点评,一号店,苏宁,虾米等网站签到。",
"homepage_url": "http://fayland.me/",
Expand Down Expand Up @@ -35,6 +35,16 @@
"matches": [ "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/baidu_tieba.js" ],
"run_at": "document_end"
}
],
"background": {
Expand Down
32 changes: 31 additions & 1 deletion src/bg/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@
});
}
});
} else if (request.method == 'weibo_qiandao') {
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;
}
}
console.log('is_logined:' + is_logined);
if (is_logined) {
var url = 'http://vdisk.weibo.com/task/checkIn';
$.ajax({
type : "POST",
url : url,
async : !1,
dataType : 'json',
success : function(data) {
console.log(data);
// {"errcode":0,"msg":null,"data":[268,2]}
if (data.errcode == 0) { // 1 is OK, 2 is already done
var today = (new Date()).toDateString();
localStorage.setItem('weibo_status', today);
localStorage.setItem('weibo_points', data.data[1]);
}
},
error: function(err) {
console.log(err);
}
});
}
});
} else if (request.method == "getLocalStorage") {
sendResponse({data: localStorage[request.key]});
} else if (request.method == "setLocalStorage") {
Expand All @@ -35,5 +66,4 @@
sendResponse({}); // snub them.
}
});

}(window, document, Zepto);

0 comments on commit 23bfa05

Please sign in to comment.