Last active
March 18, 2017 12:58
-
-
Save zyguan/41cb3391f575df1f271fb6bc55019031 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 bilibot | |
// @namespace http://live.bilibili.com/ | |
// @version 0.1 | |
// @description get your award automatically | |
// @author zyguan | |
// @include http://live.bilibili.com/* | |
// @exclude http://live.bilibili.com/ | |
// @grant none | |
// @require https://github.com/antimatter15/ocrad.js/raw/master/ocrad.js | |
// ==/UserScript== | |
(function(bot) { | |
'use strict'; | |
$('.box-doms').bind("DOMSubtreeModified", function() { | |
var $boxDoms = $(this); | |
var $timer = $boxDoms.find('.count-down'); | |
if ($timer.text() == "00:00") { | |
bot.tryGetAward(avalon.vmodels.treasureCtrl, $timer, 5); | |
} | |
}); | |
})({ | |
getImgData: function(img) { | |
var canvas = document.createElement('canvas'); | |
var context = canvas.getContext('2d'); | |
canvas.width = 120; | |
canvas.height = 40; | |
context.drawImage(img, 0, 0); | |
return context.getImageData(0, 0, 120, 40); | |
}, | |
ocr: function(imgData) { | |
var valstr = OCRAD(imgData); | |
valstr = valstr.replace(/[zZ]/g, '2'); | |
valstr = valstr.replace(/[sS]/g, '6'); | |
valstr = valstr.replace(/[oO]/g, '0'); | |
valstr = valstr.replace(/[Il]/g, '1'); | |
valstr = valstr.replace(/B/g, '8'); | |
valstr = valstr.replace(/_/g, '4'); | |
valstr = valstr.replace(/g/g, '9'); | |
return valstr; | |
}, | |
tryGetAward: function(ctrl, timer, cnt) { | |
if (cnt > 0 && timer.text() == "00:00" && | |
timer.parents('.treasure-box-ctnr').css('display') != "none") { | |
ctrl.captcha.refresh(); | |
self = this; | |
$('.acquiring-panel .captcha-img').one("load", function() { | |
try { | |
var val = eval(self.ocr(self.getImgData(this))); | |
console.log("tryGetAward #"+cnt, val, this); | |
ctrl.captcha.userInput = val; | |
ctrl.getAward(); | |
} catch (err) { | |
console.error("GetAward:", err); | |
} finally { | |
setTimeout(function () { | |
self.tryGetAward(ctrl, timer, cnt-1); | |
}, 1500); | |
} | |
}); | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment