Last active
April 5, 2016 12:25
-
-
Save Garwih/efb29af37e5cc626422d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 什么值得买自动签到 | |
// @namespace http://smzdm.com/ | |
// @version 0.1 | |
// @icon http://www.smzdm.com/favicon.ico | |
// @description 打开什么值得买任意页面,自动签到 | |
// @author Garwi | |
// @match http://*.smzdm.com/* | |
// @updateURL https://gist.githubusercontent.com/Garwih/efb29af37e5cc626422d/raw/qiandao_smzdm.js | |
// @connect * | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var s = document.querySelector('input[name="s"]'); | |
s.value = '开始签到...'; | |
var qiandao = function() { | |
var user_logined = /user=/.test(document.cookie); | |
var isHome = /www\.smzdm\.com/.test(location.origin); | |
var signScored = document.querySelector('.signScored'); | |
if(isHome && signScored !== null) { | |
s.value = '今日已签到!'; | |
} else if(user_logined) { | |
s.value = '开始签到...'; | |
getResponse(); | |
} else { | |
s.value = '无法签到,请先登录!'; | |
} | |
}; | |
var handle = function(json) { | |
var text = json.replace('(', '').replace(')', ''); | |
var data = JSON.parse(text); | |
if(data.error_code === 0) { | |
var date = data.data.daily_num; | |
if(data.error_msg === '已签到') { | |
s.value = '今日已签到!'; | |
} else { | |
s.value = '签到成功,已连续签到' + date + '天。'; | |
} | |
} | |
}; | |
var getResponse = function(){ | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: 'http://www.smzdm.com/user/qiandao/jsonp_checkin', | |
onload: function(rep){ | |
handle(rep.responseText); | |
}, | |
onerror: function(err){ | |
handle(err.responseText); | |
} | |
}); | |
}; | |
qiandao(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment