Created
November 17, 2014 13:45
Revisions
-
17 created this gist
Nov 17, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ var miner = function() { var postData, timeoutID, startLoop, stopLoop, printList var list = [] startLoop = function(delay) { console.log('开始了辛勤的挖掘.') timeoutID = setInterval(postData, delay || 1000 * 10) } stopLoop = function() { clearTimeout(timeoutID) console.log('工作结束了 ( ゜- ゜)つロ 乾杯~ ') } printList = function() { console.table(list) console.log('挖了那么多, 酬劳一下? (●°u°●)つ') } postData = function () { $.ajax({ url: "http://www.bilibili.com/widget/ajaxGetGift", dataType: "json", type: "post", data: { gift_id: 22, act: "get_code" }, success: function(data) { if (data.code == 0) { list.push({ item: data.item, card: data.card }) console.info('发现了' + data.item) } else if (data.code == -7) { console.warn('可恶的验证马挡住了前面的去路!') stopLoop() } else { console.error('好像出现了点什么错误: ' + data.msg) stopLoop() } }, error: function() { console.info('网络不给力啊..') } }) } return { play: startLoop, stop: stopLoop, list: printList } }