Skip to content

Commit

Permalink
缩小base64包
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Apr 5, 2019
1 parent 98bf4cf commit b0ece12
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3",
"image-to-base64": "^2.0.1",
"md5": "^2.2.1",
"mongodb": "^3.1.10",
"redis": "^2.8.0"
Expand Down
15 changes: 7 additions & 8 deletions src/cxmooc-tools/chaoxing/chaoxing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const common = require('../common');
const until = require('./until');
const Video = require('./video');
const Topic = require('./topic');
const image2base64 = require('image-to-base64');

module.exports = function () {
let self = this;
Expand Down Expand Up @@ -174,20 +173,20 @@ module.exports = function () {
}, (config.interval || 0.1) * 60000);
}
//监控验证码
self.monitorVcode();
config.auto && self.monitorVcode();
}

this.monitorVcode = function () {
//验证码监控加载
let hookGetVarCode = window.getVarCode;
window.getVarCode = function () {
let vcodeimg = document.createElement('img');
let img = document.getElementById('imgVerCode');
image2base64('/img/code?' + new Date().getTime()).then(
(response) => {
img.src = 'data:image/jpg;base64,' + response
//TODO:验证码识别
}
)
$(vcodeimg).on('load', function () {
img.src = 'data:' + common.getImageBase64(vcodeimg, 'jpg');
//TODO:验证码识别
});
vcodeimg.src = '/img/code?' + new Date().getTime();
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/cxmooc-tools/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@ Date.prototype.format = function (fmt) {
export function log(msg) {
console.log("cxmooc-tools [" + (new Date()).format("yyyy-MM-dd hh:mm:ss") + "] " + msg)
console.trace()
}
}

export function getImageBase64(img, ext) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var dataURL = canvas.toDataURL("image/" + ext);
canvas = null;
return dataURL;
}
5 changes: 1 addition & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ module.exports = {
},
chunks: ['popup']
})
],
node: {
fs: 'empty'
}
]
}

0 comments on commit b0ece12

Please sign in to comment.