一个并没有什么卵用的 tampermonkey 脚本。
小微识别文字的逻辑好迷啊~
// ==UserScript==
// @name hacpai写字
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @grant none
// @include https://hacpai.com/activity/character
// ==/UserScript==
(function () {
'use strict';
function reload() {
setTimeout(() => {
location.reload();
}, 1000);
}
function exe() {
function getBase(font) {
const canvas = document.createElement("canvas");
const w = 200;
const h = 200;
canvas.width = w;
canvas.height = h;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fff";
ctx.fillRect(0, 0, 200, 200);
ctx.font = "8em bold 微软雅黑";
ctx.fillStyle = "#000";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(font, w / 2, h / 2);
return canvas.toDataURL("image/png");
}
const text = document.querySelector("#activityCharacterChar > h2 > a").innerText;
const image = getBase(text);
console.log(text, image);
fetch("https://hacpai.com/activity/character/submit", {
"headers": {
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
},
"referrer": "https://hacpai.com/activity/character",
"referrerPolicy": "no-referrer-when-downgrade",
"body": JSON.stringify({
dataURL: image,
character: text
}),
"method": "POST",
"mode": "cors",
"credentials": "include"
}).then(function (response) {
response.json().then(function (data) {
console.log(data);
reload();
})
}).catch(function (e) {
console.log('error: ' + e.toString());
reload();
});
}; exe();
})();
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于