提高识别准确率,加上任务统计
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name 学习通搜题小助手
|
||||
// @description 学习通搜题小助手
|
||||
// @version v1.0.1
|
||||
// @version v1.0.3
|
||||
// @license MIT
|
||||
// @grant GM_addStyle
|
||||
// @grant GM_getResourceText
|
||||
@@ -17,17 +17,19 @@
|
||||
function geneFunction(ocrEnabled, encText) {
|
||||
return 'var ocrEnabled = ' + ocrEnabled + ',' +
|
||||
'encText = ' + encText + ';' +
|
||||
`var imgList=[];setTimeout(function(){for(var t=document.querySelectorAll('img[alt="chaoxing_nmsl"]'),e=0;e<t.length;e++)imgList.push(e);if(0<imgList.length){async function i(){for(var t in imgList){var{data:{text:e}}=await async function(t){return await Tesseract.recognize(t,"chi_sim",{langPath:"https://c.ibcl.us/ocr-lib"})}(document.querySelectorAll('img[alt="chaoxing_nmsl"]')[t].src);encText[t].innerText=e,encText[t].style.color="black",console.log(e)}}i()}},2e3);`;
|
||||
`var imgList=[],_imgList=[];setTimeout(function(){for(var e=document.querySelectorAll('img[alt="chaoxing_nmsl"]'),t=0;t<e.length;t++)imgList.push(t),_imgList.push(t);if(0<imgList.length){async function i(){for(var e in imgList){var{data:{text:t}}=await async function(e){return await Tesseract.recognize(e,"chi_sim",{langPath:"https://c.ibcl.us/ocr-lib"})}(document.querySelectorAll('img[alt="chaoxing_nmsl"]')[e].src);encText[e].innerText=t,encText[e].style.color="black",_imgList.shift(),console.log(t)}}i()}},2e3);var pageHead=document.querySelector('div[class="ZyTop"]');setInterval(function(){var e;0<_imgList.length&&((e=document.querySelector('p[id="ocrProgress"]'))?e.innerHTML="<strong>当前进度:第 "+(_imgList[0]+1)+"/"+imgList.length+" 个</strong>":((e=document.createElement("p")).id="ocrProgress",pageHead.appendChild(e)))},500);`;
|
||||
|
||||
// 未压缩代码
|
||||
/*
|
||||
// 未压缩代码
|
||||
/*
|
||||
// 获取图片 ID 存入数组
|
||||
var imgList = [];
|
||||
var imgList = [],
|
||||
_imgList = [];
|
||||
// 启动 OCR
|
||||
setTimeout(function() {
|
||||
var imgTag = document.querySelectorAll('img[alt="chaoxing_nmsl"]');
|
||||
for (var i = 0; i < imgTag.length; i++) {
|
||||
imgList.push(i);
|
||||
_imgList.push(i);
|
||||
}
|
||||
if (imgList.length > 0) {
|
||||
async function displayText() {
|
||||
@@ -39,6 +41,7 @@ setTimeout(function() {
|
||||
} = await recText(document.querySelectorAll('img[alt="chaoxing_nmsl"]')[img].src);
|
||||
encText[img].innerText = text;
|
||||
encText[img].style.color = 'black';
|
||||
_imgList.shift(); // 用于统计剩下的任务
|
||||
console.log(text);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +55,21 @@ setTimeout(function() {
|
||||
displayText();
|
||||
}
|
||||
}, 2000);
|
||||
*/
|
||||
// 统计 OCR 任务
|
||||
var pageHead = document.querySelector('div[class="ZyTop"]');
|
||||
setInterval(function() {
|
||||
if (_imgList.length > 0) {
|
||||
var currentProgress = document.querySelector('p[id="ocrProgress"]');
|
||||
if (!currentProgress) {
|
||||
var ocrProgress = document.createElement('p');
|
||||
ocrProgress.id = 'ocrProgress';
|
||||
pageHead.appendChild(ocrProgress);
|
||||
} else {
|
||||
currentProgress.innerHTML = '<strong>当前进度:第 ' + (_imgList[0] + 1) + '/' + imgList.length + ' 个</strong>';
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
*/
|
||||
}
|
||||
|
||||
function prettyText() {
|
||||
@@ -87,9 +104,11 @@ if (document.getElementsByClassName('font-cxsecret')[0]) {
|
||||
[].forEach.call(encArray, function(item, index, arr) {
|
||||
// 改大字体、加入空格便于识别
|
||||
if (arr[index].className == 'font-cxsecret fl after') {
|
||||
arr[index].style = 'line-height: 90px; font-size: 50px; color: black; letter-spacing: 5px;';
|
||||
arr[index].style = 'line-height: 80px; font-size: 40px; color: green; letter-spacing: 3px;';
|
||||
} else {
|
||||
arr[index].style = 'line-height: 90px; font-size: 50px; letter-spacing: 5px;';
|
||||
// 为题目括号增大间距,避免识别错误
|
||||
arr[index].innerText = arr[index].innerText.replace(/(\()(\))/g, ' $1 $2');
|
||||
arr[index].style = 'line-height: 80px; font-size: 40px; color: green; letter-spacing: 3px;';
|
||||
}
|
||||
});
|
||||
// 按顺序生成图像
|
||||
@@ -104,7 +123,7 @@ if (document.getElementsByClassName('font-cxsecret')[0]) {
|
||||
img.id = count;
|
||||
document.body.appendChild(img);
|
||||
if (encArray[count].className == 'font-cxsecret fl after') {
|
||||
encArray[count].style = 'padding-left:10px; color: red;';
|
||||
encArray[count].style = 'padding-left: 10px; color: red;';
|
||||
encArray[count].innerText = '正在修复乱码问题,以便后续搜题,这可能需要一些时间...';
|
||||
} else {
|
||||
encArray[count].style = 'line-height: 35px; font-size: 14px; padding-right: 15px; color: red;';
|
||||
@@ -134,4 +153,4 @@ if (document.getElementsByClassName('font-cxsecret')[0]) {
|
||||
}, 1000);
|
||||
} else {
|
||||
console.log('没有检测到加密文本');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user