// ==UserScript== // @name 慕课题目搜搜搜 // @namespace http://tampermonkey.net/ // @version 1.3.2 // @description 题库查询小工具 // @author Onion // @match https://www.icourse163.org/* // @match https://i.chaoxing.com/* // @match https://mooc2-ans.chaoxing.com/* // @match https://mooc1.chaoxing.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=icourse163.org // @grant GM_addStyle // @grant GM_xmlhttpRequest // @grant unsafeWindow // @connect cx.icodef.com // @connect huawei-cdn.lyck6.cn // @connect tk.enncy.cn // @connect web.baimiaoapp.com // @connect lyck6.cn // @connect cx.gocos.cn // @run-at document-start // @license MPL2.0 // @downloadURL none // ==/UserScript== function mainTop() { 'use strict'; var ocrToken = new Object() var webSet = new Array() var GM_abort = new Array() let ocrSumResults = "" const document = unsafeWindow.document; const window = unsafeWindow //////////【配////////置//////////区】////////////// var yzggToken = `ddMyyyPEhfHSzQBy` var enncyToken = `` ocrToken.cookie = `` ocrToken.xauthToken = `` ocrToken.xauthUuid = `` webSet = [ "huawei-cdn.lyck6.cn", "lyck6.cn", "tk.enncy.cn", "cx.icodef.com" ] //////////////////////////////////////////// if (window.location.href.indexOf("www.icourse163.org") > -1) { appendBox(0).then((res) => { initBox() addBoxEvent() addMoveEvent() appendQuesEvent() addSearchEvent() pic2WordsEvent() // keyEvent() }) addBothStyle() } if (window.location.href.indexOf("i.chaoxing.com/base") > -1) { appendBox(0).then((res) => { initBox() addBoxEvent() addMoveEvent() appendQuesEvent() addSearchEvent() pic2WordsEvent() // keyEvent() }) addBothStyle() } if (window.location.href.indexOf("mooc1.chaoxing.com/mycourse/studentstudy") > -1) { appendBox(0).then((res) => { initBox() addBoxEvent() addMoveEvent() appendQuesEvent() addSearchEvent() pic2WordsEvent() // keyEvent() }) addBothStyle() } function creatBox() { return new Promise((resolve) => { var divE = document.createElement('div'); var divId = document.createAttribute("id"); //创建属性 divId.value = 'gptDiv'; //设置属性值 divE.setAttributeNode(divId); //给div添加属性 divE.innerHTML = `
慕课题目搜搜搜v1.2.1已启动
加载中
图片转文字中,请稍等
` resolve(divE) }) } async function pivElemAddEventAndValue(append_case) { var search_content if (append_case === 3) { search_content = document.getElementById('q').value } if (append_case === 2) { search_content = document.getElementById('kw').value } if (append_case === 1) { search_content = document.querySelector("#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input:nth-child(3)").value } if (append_case === 0) { search_content = document.getElementsByClassName('b_searchbox')[0].value } document.getElementById("gptInput").value = search_content document.getElementById('button_GPT').addEventListener('click', () => { your_qus = document.getElementById("gptInput").value do_it() }) } async function appendBox(append_case) { return new Promise((resolve, reject) => { creatBox().then((divE) => { switch (append_case) { case 0: //bing if (divE) { document.body.prepend(divE) } break; case 1://google if (document.getElementsByClassName('TQc1id ')[0]) { document.getElementsByClassName('TQc1id ')[0].prepend(divE); } else { document.getElementById("rcnt").appendChild(divE); } break; case 2: if (document.getElementById('content_right')) { document.getElementById('content_right').prepend(divE) } break; case 3: if (document.getElementsByClassName("layout-web__sidebar")[0]) { document.getElementsByClassName("layout-web__sidebar")[0].prepend(divE) } default: if (divE) { console.log(`啥情况${divE}`) } } }).catch((err) => { throw new Error(err) }) resolve("finished") }) } function addBothStyle() { GM_addStyle(` #moveIt{ justify-content: right; display: flex; cursor: move; } .icon{ width: 100%; height: 100%; } #gptSettingBox{ display: flex; flex-direction: row; width: 8%; } #spreadOrShrink{ justify-content: space-evenly; display: flex; align-items: center; border: solid; border-top: none; border-bottom: none; caret-color: transparent; } #gptAnswer{ margin: 4px; border-top: solid; border-bottom: solid; height: fit-content; overflow-y: auto; align-items: center; text-align: center; } #gptInput{ width: 81%; border-radius: 4px; border: solid; } #gptInputBox{ display: flex; justify-content: space-around; } #button_GPT:hover{ background:#ffffffcc; } #gptDiv{ border-radius: 8px; padding: 10px; margin-bottom: 9px; width:452px; translate:-20px; background:#ffffffcc; display: flex; flex-direction: row; position: fixed; top: 80px; border: solid; right: 51px; z-index: 9999; background: white; color: black; transition: all 0.5s ease 0s; } #button_GPT{ } #button_GPT{ background: transparent; border-radius: 3px; } #gptCueBox{ width: 68%; } #gptAnswer_inner{ } /*dots*/ .dot{ height: 4px; width: 4px; display: inline-block; border-radius: 2px; animation: dotting 2.4s infinite step-start; } @keyframes dotting { 25%{ box-shadow: 4px 0 0 #71777D; } 50%{ box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D; } 75%{ box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D, 24px 0 0 #71777D; } } `) } function addBoxEvent() { if (getCookie("isShrink") == "") { setCookie("isShrink", 0, 30) } else { document.getElementById('spreadOrShrink').addEventListener("click", () => { if (getCookie("isShrink") == 0) { document.getElementById('gptInputBox').style.display = "none" document.getElementById('gptCueBox').style.display = "none" document.getElementById('gptDiv').style.width = "1.5vh" document.getElementById('spreadOrShrink').innerHTML = "\u21e4" setCookie("isShrink", 1, 30) } else { document.getElementById('gptInputBox').style.display = "flex" document.getElementById('gptCueBox').style.display = "block" document.getElementById('gptDiv').style.width = "452px" document.getElementById('spreadOrShrink').innerHTML = "\u21e5" setCookie("isShrink", 0, 30) } }) } } function controlBoxDisplay(id, way) { document.getElementById(`${id}`).style.display = `${way}` } function initBox() { if (getCookie("isShrink") == 0) { document.getElementById('gptInputBox').style.display = "flex" document.getElementById('gptCueBox').style.display = "block" document.getElementById('gptDiv').style.width = "452px" document.getElementById('spreadOrShrink').innerHTML = "\u21e5" } else { document.getElementById('gptInputBox').style.display = "none" document.getElementById('gptCueBox').style.display = "none" document.getElementById('gptDiv').style.width = "1.5vh" document.getElementById('spreadOrShrink').innerHTML = "\u21e4" } controlBoxDisplay("loadingBox", "none")//默认不展示 controlBoxDisplay("loadingBoxImg", "none")//默认不展示 } function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toGMTString(); document.cookie = cname + "=" + cvalue + "; " + expires; } //原生cookie函数 function getCookieObject() { let cookieString = document.cookie; cookieString = cookieString.substring(0, cookieString.length - 1); let tempCookieArray = cookieString.split('; '); let cookieObject = {}; // 存放 cookie 键值对 tempCookieArray.forEach(item => { let name = item.substring(0, item.indexOf('=')); let value = item.substring(item.indexOf('=') + 1); value = decodeURIComponent(value); // 还原字符串 cookieObject[name] = value; // 将键值插入中这个对象中 }); return cookieObject // 返回包含 cookie 键值对的对象 } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name) == 0) return c.substring(name.length, c.length); } return ""; } function moveIt(controlEle, movedEle) { //var demo = document.getElementById(`${settings}`) var canitmove = false var x = 0, y = 0 controlEle.onmousedown = function (e) { e.preventDefault() x = e.pageX - movedEle.offsetLeft y = e.pageY - movedEle.offsetTop canitmove = true document.getElementById("gptDiv").style.transition = "none" // console.log(e.pageX) } controlEle.onmouseup = function (e) { e.preventDefault() x = e.pageX - movedEle.offsetLeft y = e.pageY - movedEle.offsetTop canitmove = false document.getElementById("gptDiv").style.transition = "all 0.5s ease 0s" // console.log(movedEle.offsetLeft) console.log(e.pageX) } window.onmouseup = function () { canitmove = false } window.onmousemove = function (e) { if (canitmove) { movedEle.style.left = e.pageX - x + 'px' movedEle.style.top = e.pageY - y + 'px' } } } function addMoveEvent() { moveIt(document.getElementById('moveIt'), document.getElementById('gptDiv')) } //搜题部分 function getQues() { return document.getElementById('gptInput').value.trim() } function appendQuesEvent() { document.addEventListener("mouseup", () => { if (unsafeWindow.getSelection().toString().replace(/(\s)|(\\n)/g, "") !== "") { document.getElementById('gptInput').value = unsafeWindow.getSelection().toString().replace(/(\s)|(\\n)/g, "") } }); } function getAllAnswer() { if (document.getElementById('gptInput').value !== "") { controlBoxDisplay("loadingBox", "block") document.getElementById('gptAnswer_inner').innerHTML = `` getAnswer(1) .then(() => { return getAnswer(0) }) .then(() => { return getAnswer(3) }) .then(() => { if (enncyToken !== "") { return getAnswer(2) } }) .then(() => { controlBoxDisplay("loadingBox", "none") console.log("finished"); }) .catch((err) => { log(err) }) } else { document.getElementById('gptAnswer_inner').innerHTML = `
搜索内容不能为空
` } } function getAnswer(chooseCase) { return new Promise((resolve) => { if (document.getElementById('gptInput').value !== "") { switch (chooseCase) { case 0: GM_abort[0] = GM_xmlhttpRequest({ method: "POST", url: "https://cx.icodef.com/wyn-nb", headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: `${yzggToken}`, }, data: `question=${getQues()}`, onloadend: function (data) { try { let parsedAnswer = JSON.parse(data.response).data resolve(data.response) if (parsedAnswer.match(/http.+/g)) { logAdd(`
一之哥哥`) } else { logAdd(`
一之哥哥:${parsedAnswer}
`) } } catch (err) { logAdd(`
一之哥哥err:${err}`) } }, onerror: function (err) { throw new Error('Error while executing the code'); }, ontimeout: function (err) { throw new Error('Error while executing the code'); } }) break; case 1: GM_abort[1] = GM_xmlhttpRequest({ method: "POST", url: `http://${webSet[1]}/api/autoFreeAnswer`, headers: { "Content-Type": "application/json", }, data: `{"question": "${getQues()}"}`, onloadend: function (data) { try { console.log(data.response) if (JSON.parse(data.response).code !== 200) { logAdd(`【万能】全平台:${JSON.parse(data.response).msg}
`) } else { let allAns = "" for (let i = 0; i <= 2; i++) { allAns += `${i}:${JSON.parse(data.response).data.list[i]}\n\n` } logAdd(`【万能】全平台:${allAns}
`) } } catch (err) { logAdd(`【万能】全平台:点的太快了gg,再试一次;
错误信息:"${err}"
`) } resolve(data.response) }, onerror: function (err) { throw new Error('Error while executing the code'); }, ontimeout: function (err) { throw new Error('Error while executing the code'); } }) break; case 2: GM_abort[2] = GM_xmlhttpRequest({ method: "GET", url: `https://tk.enncy.cn/query?title=${getQues()}&token=${enncyToken}`, headers: { "Content-Type": "application/json", }, onloadend: function (data) { try { logAdd(`
enncy题库:${JSON.parse(data.response).data.answer}`) } catch (err) { logAdd(`
enncyERR:${err}`); } resolve(data.response) }, onerror: function (err) { throw new Error('Error while executing the code'); }, ontimeout: function (err) { throw new Error('Error while executing the code'); } }) break; case 3: GM_abort[3] = GM_xmlhttpRequest({ method: "POST", url: `https://cx.gocos.cn/api/v1/cx?v=1.7.8`, headers: { "Content-Type": "application/x-www-form-urlencoded", }, data: `question=${getQues()}`, onloadend: function (data) { try { if (JSON.parse(data.response).data.answer == "") { logAdd(`
Ne-21题库:${JSON.parse(data.response).msg}`) } else { logAdd(`
Ne-21题库:${JSON.parse(data.response).data.answer}`) } } catch (err) { logAdd(`
Ne-21题库ERR:${err}`); } resolve(data.response) }, onerror: function (err) { throw new Error('Error while executing the code'); }, ontimeout: function (err) { throw new Error('Error while executing the code'); } }) break; default: GM_abort[4] = GM_xmlhttpRequest({ method: "POST", url: "https://cx.icodef.com/wyn-nb", headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: `${yzggToken}`, }, data: `question=${getQues()}`, onloadend: function (data) { document.getElementById('gptAnswer').innerHTML = JSON.parse(data.response).data }, onerror: function (err) { throw new Error('Error while executing the code'); }, ontimeout: function (err) { throw new Error('Error while executing the code'); } }) } } else { document.getElementById('gptAnswer_inner').innerHTML = `
搜索内容不能为空
` } }) } function pic2WordsEvent() { document.getElementById('gptInput').addEventListener('paste', (e) => { pic2base64(e).then((base64data) => { if (base64data) { if (!ocrToken.xauthToken || !ocrToken.xauthUuid || !ocrToken.cookie) { log(`你妹有白描cookie(悲
点我去白描官网买`) } else { console.log(base64data); log(`尊贵的白描黄金VIP,欢迎`) controlBoxDisplay("loadingBoxImg", "block") sendOcrMode() .then((sendOcrModeRes) => { console.log(sendOcrModeRes); return sendOcrData(JSON.parse(sendOcrModeRes).data.token, base64data) }) .then((sendOcrDataRes) => { // console.log(JSON.parse(sendOcrDataRes).data.jobStatusId); return JSON.parse(sendOcrDataRes).data.jobStatusId }) .then((jobStatusId) => { console.log(jobStatusId); sleep(2000).then(() => { getOcrResults(jobStatusId) .then((finalRes) => { if (JSON.parse(finalRes).code) { for (let i = 0; i <= JSON.parse(finalRes).data.ydResp.data.lines.length - 1; i++) { ocrSumResults += JSON.parse(finalRes).data.ydResp.data.lines[i].text } } else { log(`emmm,网络有点卡,再试一次吧!`) } }).then(() => { if (ocrSumResults == "") { log(`奇怪的情况出现了(惊`) } else { document.getElementById('gptInput').value = `${ocrSumResults.trim()}` } }).then(() => { ocrSumResults = "" }).then(() => { controlBoxDisplay("loadingBoxImg", "none") }) }) }) } } else { console.log("原来只是正常的复制而已(*~*)"); } }) }) } function pic2base64(e) { return new Promise((resolve) => { e.stopPropagation(); // e.preventDefault(); // 阻止粘贴 // 获取剪贴板信息 var clipboardData = e.clipboardData || window.clipboardData; var items = clipboardData.items; for (var i = 0; i < items.length; i++) { var item = items[i]; if (item.kind == 'file') { var pasteFile = item.getAsFile(); var reader = new FileReader(); reader.onload = function (event) { // 将结果显示在