Skip to content

Commit

Permalink
import xiami
Browse files Browse the repository at this point in the history
  • Loading branch information
fayland committed May 15, 2014
1 parent b89a245 commit 5c95581
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 39 deletions.
1 change: 0 additions & 1 deletion js/qiandao/taobao.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
!function(win, doc, $){

$(doc).ready(function() {
chrome.runtime.sendMessage({method: "getLocalStorage", key: "taobao_status"}, function(res) {
var status = res.data;
Expand Down
40 changes: 10 additions & 30 deletions js/qiandao/xiami.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
!function(win, doc, $){

$(doc).ready(function() {
// only do it when login
if (1) {
chrome.runtime.sendMessage({method: "getLocalStorage", key: "xiami_status"}, function(res) {
var status = res.data;
var today = (new Date()).toDateString();
if (! (status && today === status)) {
$.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) {});
console.log('[qiandao][xiami] signIn OK.');
} else {
console.log(data);
}
}
});
} else {
console.log('[qiandao][xiami] already signIn today.');
}
});
} else {
console.log('[qiandao][xiami] not login yet.');
}
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) {});
} else {
console.log('[qiandao][xiami] already signIn today.');
}
});
});

}(window, document, Zepto);
7 changes: 6 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.5",
"version": "0.0.6",
"manifest_version": 2,
"description": "访问时如果已登陆则在淘宝,百度贴吧,点评,一号店,苏宁,虾米等网站自动签到。",
"homepage_url": "http://fayland.me/",
Expand All @@ -16,6 +16,11 @@
"js": [ "js/zepto.min.js", "js/qiandao/taobao.js" ],
"run_at": "document_end"
},
{
"matches": [ "http://*.tmall.com/*" ],
"js": [ "js/zepto.min.js", "js/qiandao/tmall.js" ],
"run_at": "document_end"
},
{
"matches": [ "http://*.yhd.com/*" ],
"js": [ "js/zepto.min.js", "js/qiandao/yhd.js" ],
Expand Down
83 changes: 76 additions & 7 deletions src/bg/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!function(win, doc, $){
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.method == 'taobao_qiandao') {
if (request.method === 'taobao_qiandao') {
chrome.cookies.getAll({domain:"taobao.com"}, function (cookies){
var token;
for (var i in cookies) {
Expand All @@ -26,11 +26,48 @@
});
}
});
} else if (request.method == 'weibo_qiandao') {
return;
}

if (request.method === 'tmall_qiandao') {
return;
chrome.cookies.getAll({domain:"tmall.com"}, function (cookies){
var token;
for (var i in cookies) {
if (cookies[i].name == '_tb_token_') {
token = cookies[i].value;
}
}
if (token) {
var timestamp = (new Date()).getTime();
$.ajax({
type : "GET",
url : 'http://www.tmall.com/go/rgn/ka/sign.php?modal=ka&_ksTS=' + timestamp + '_172',
dataType : 'jsonp',
success : function(data) {
alert(JSON.stringify(data));
// {"login":"true","currentLevel":"v5","nextLevel":"v6","nextMaxCoin":40,"code":1,"coinOld":9145,"coinNew":9155,"daysTomorrow":2,"coinTomorrow":"15","auth":true,"isTake":"false","takeAmount":"","friendNum":"0","switcher":"true"}
if (data.code == 1 || data.code == 2) { // 1 is OK, 2 is already done
var today = (new Date()).toDateString();
localStorage.setItem('tmall_status', today);
localStorage.setItem('tmall_points', data.coinNew);
}
},
error: function(err) {
console.log(err);
}
});
}
});
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') {
if (cookies[i].name === 'login_sid_t') {
is_logined = 1;
break;
}
Expand All @@ -57,11 +94,14 @@
});
}
});
} else if (request.method == 'tieba_qiandao') {
return;
}

if (request.method === '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' || cookies[i].name == 'TIEBAUID') {
if (cookies[i].name === 'BAIDUID' || cookies[i].name === 'TIEBAUID') {
is_logined = 1;
break;
}
Expand Down Expand Up @@ -93,9 +133,38 @@
});
}
});
} else if (request.method == "getLocalStorage") {
return;
}

if (request.method === 'xiami_qiandao') {
chrome.cookies.getAll({domain:"weibo.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]});
} else if (request.method == "setLocalStorage") {
} else if (request.method === "setLocalStorage") {
localStorage.setItem(request.key, request.val);
sendResponse({});
} else {
Expand Down

0 comments on commit 5c95581

Please sign in to comment.