From 23bfa05ec45ee41067ffb7b8d65bd7e68730accb Mon Sep 17 00:00:00 2001 From: Fayland Lam Date: Mon, 12 May 2014 14:20:57 +0800 Subject: [PATCH] weipan qiandao --- js/qiandao/weibo.js | 59 ++++++++++++++++++++++++++++++++++++++++++++ manifest.json | 12 ++++++++- src/bg/background.js | 32 +++++++++++++++++++++++- 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 js/qiandao/weibo.js diff --git a/js/qiandao/weibo.js b/js/qiandao/weibo.js new file mode 100644 index 0000000..5e8aa9f --- /dev/null +++ b/js/qiandao/weibo.js @@ -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); \ No newline at end of file diff --git a/manifest.json b/manifest.json index 3506bca..1d744a5 100755 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "自动签到", "short_name": "签到", - "version": "0.0.3", + "version": "0.0.4", "manifest_version": 2, "description": "访问时如果已登陆则自动在淘宝,点评,一号店,苏宁,虾米等网站签到。", "homepage_url": "http://fayland.me/", @@ -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": { diff --git a/src/bg/background.js b/src/bg/background.js index 857f4a3..e1422ec 100755 --- a/src/bg/background.js +++ b/src/bg/background.js @@ -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") { @@ -35,5 +66,4 @@ sendResponse({}); // snub them. } }); - }(window, document, Zepto); \ No newline at end of file