Greasy Fork is available in English.

慕课题目搜搜搜

超星慕课题库聚合查询小工具,【快捷查询】【高级搜索模式】【OCR识别】

  1. // ==UserScript==
  2. // @name 慕课题目搜搜搜
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.5.4
  5. // @description 超星慕课题库聚合查询小工具,【快捷查询】【高级搜索模式】【OCR识别】
  6. // @author Onion
  7. // @match https://www.icourse163.org/*
  8. // @match https://i.chaoxing.com/*
  9. // @match https://mooc2-ans.chaoxing.com/*
  10. // @match https://mooc1.chaoxing.com/*
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=icourse163.org
  12. // @grant GM_addStyle
  13. // @grant GM_xmlhttpRequest
  14. // @grant unsafeWindow
  15. // @connect cx.icodef.com
  16. // @connect huawei-cdn.lyck6.cn
  17. // @connect tk.enncy.cn
  18. // @connect web.baimiaoapp.com
  19. // @connect lyck6.cn
  20. // @connect cx.gocos.cn
  21. // @connect api.muketool.com
  22. // @connect 43.143.249.139
  23. // @run-at document-start
  24. // @license MPL2.0
  25. // ==/UserScript==
  26. function mainTop() {
  27.  
  28. 'use strict';
  29. /////////全/////////局/////////变/////////量
  30. var ocrToken = new Object()
  31. var requestDst = new Array()
  32. var GM_abort = new Array()
  33. let ocrSumResults = ""
  34. let isCtrl=false
  35. let isAdvanced=false
  36. const document = unsafeWindow.document;
  37. const window = unsafeWindow
  38.  
  39. //////////【配////////置////////区】//////////////
  40. var yzggToken = `ddMyyyPEhfHSzQBy`
  41. var enncyToken = ``
  42. ocrToken.cookie = ``
  43. ocrToken.xauthToken = ``
  44. ocrToken.xauthUuid = ``
  45. requestDst = [
  46. "cx.icodef.com",//yzgg
  47. "huawei-cdn.lyck6.cn",//万能1
  48. "lyck6.cn",//万能2
  49. "tk.enncy.cn",//enncy
  50. "cx.gocos.cn",//Ne-21
  51. "api.muketool.com",//山楂树1
  52. "api2.muketool.com",//山楂树2
  53. "43.143.249.139",//蛋炒饭
  54. ]
  55. //////【题/////////目/////////配////////置/////////区】//////
  56. let formedQues = ""
  57. let quesType = 0 //0:单选题 (必填) 1:多选题 2:判断题 (int)
  58. let quesWorkType = "zj" //zj:章节测验 zy:作业 ks:考试
  59. let quesOptions = new Array()
  60. let quesSrc = "https://mooc1.chaoxing.com/mycourse/studentstudy?chapterId=636516658&courseId=227751756&clazzid=61817745&cpi=169857532&enc=6431fbd689555ba100515caefc783235&mooc2=1&openc=0737a9a35dcb1f96af6ce927f5cdd739"
  61. quesOptions = [
  62. "发展生产力",
  63. "以经济建设为中心",
  64. "走向共同富裕",
  65. "全面建成小康社会"
  66. ]
  67.  
  68. ///////////开///////////源///////////区////////////
  69. let namespaceURL = [
  70. "https://greasyfork.org/zh-CN/scripts/451356-%E4%B8%87%E8%83%BD-%E5%85%A8%E5%B9%B3%E5%8F%B0%E8%87%AA%E5%8A%A8%E7%AD%94%E9%A2%98%E8%84%9A%E6%9C%AC",
  71. "https://afdian.net/a/enncy",
  72. "https://scriptcat.org/",
  73. "https://scriptcat.org/script-show-page/10",
  74. "https://scriptcat.org/script-show-page/639",
  75. "https://greasyfork.org/zh-CN/scripts/450614-%E5%85%A8%E5%B9%B3%E5%8F%B0%E8%87%AA%E5%8A%A8%E7%AD%94%E9%A2%98%E8%84%9A%E6%9C%AC-%E8%B6%85%E6%98%9F%E5%AD%A6%E4%B9%A0%E9%80%9A-%E6%99%BA%E6%85%A7%E6%A0%91-%E6%89%A7%E6%95%99%E4%BA%91-%E6%9B%B4%E6%96%B02022-11-09",
  76. "https://greasyfork.org/zh-CN/scripts/455607-%E8%B6%85%E6%98%9F%E5%AD%A6%E4%B9%A0%E9%80%9A%E5%B0%8F%E5%8A%A9%E6%89%8B-%E7%AD%94%E9%A2%98%E4%B8%93%E7%89%88/code",
  77.  
  78. ]
  79. ////////////外//////////部//////////资///////源//////区////////////
  80. /*
  81. // @require https://cdn.bootcdn.net/ajax/libs/react/18.2.0/umd/react.production.min.js
  82. // @require https://cdn.bootcdn.net/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js
  83. // @require https://unpkg.com/babel-standalone@6.26.0/babel.min.js
  84. @react
  85. */
  86. function importReact() {
  87. return new Promise((resolve) => {
  88. let scriptReact = document.createElement('script');
  89. scriptReact.setAttribute('type', 'text/javascript');
  90. scriptReact.src = "https://cdn.bootcdn.net/ajax/libs/react/18.2.0/umd/react.production.min.js";
  91. document.documentElement.appendChild(scriptReact);
  92. let scriptReactDom = document.createElement('script');
  93. scriptReactDom.setAttribute('type', 'text/javascript');
  94. scriptReactDom.src = "https://cdn.bootcdn.net/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js";
  95. document.documentElement.appendChild(scriptReactDom);
  96. resolve("import end")
  97. })
  98. }
  99. /*
  100. @react
  101. */
  102. /*
  103. babel
  104.  
  105. let babelScript = document.createElement('script');
  106. babelScript.setAttribute('type', 'text/javascript');
  107. babelScript.src = "https://unpkg.com/babel-standalone@6.26.0/babel.min.js";
  108. document.documentElement.appendChild(babelScript);
  109. /*
  110. babel
  111. */
  112.  
  113. ////////////////////////////////////////////////////////////////////////////
  114.  
  115.  
  116. if (window.location.href.indexOf(".") > -1) {
  117. addBothStyle()
  118. }
  119. if (window.location.href.indexOf("www.icourse163.org") > -1) {
  120. createBox()
  121. .then((divE) => {
  122. return appendBox(0, divE)
  123. }).then(() => {
  124. //do Sth
  125. }).then(() => {
  126. //babelJsxAndRun()
  127. // createBoxReact() 页面重写了React和Babel原型,先暂时使用原生添加,后续再来解决React冲突
  128. initBox()
  129. addBoxEvent()
  130. addMoveEvent()
  131. appendQuesEvent()
  132. addSearchEvent()
  133. pic2WordsEvent()
  134. keyEvent()
  135. })
  136. }
  137. if (window.location.href.indexOf("i.chaoxing.com/base") > -1) {
  138. doItBoth()
  139. }
  140. if (window.location.href.indexOf("mooc1.chaoxing.com/mycourse/studentstudy") > -1) {
  141. doItBoth()
  142. }
  143. function doItBoth() {
  144. importReact().then(() => {
  145. sleep(30).then(() => {
  146. createBox()
  147. .then((divE) => {
  148. return appendBox(0, divE)
  149. }).then(() => {
  150. //
  151. }).then(() => {
  152. //babelJsxAndRun()
  153. createBoxReact()
  154. initBox()
  155. addBoxEvent()
  156. addMoveEvent()
  157. appendQuesEvent()
  158. addSearchEvent()
  159. pic2WordsEvent()
  160. keyEvent()
  161. })
  162. })
  163. })
  164. }
  165. function createBoxJsx() {
  166. return `
  167. ReactDOM.render(<div>
  168. <div id="gptInputBox">
  169. <textarea id="gptInput" type="text" defaultValue={""} />
  170. <button id="button_GPT">搜一下</button>
  171. </div>
  172. <div id="gptCueBox">
  173. <div id="gptAnswer" className="markdown-body">
  174. <div id="gptAnswer_inner">慕课题目搜搜搜v1.5.4已启动</div>
  175. <div id="loadingBox">
  176. 加载中
  177. <span className="dot" />
  178. </div>
  179. <div id="loadingBoxImg">
  180. 图片转文字中,请稍等
  181. <span className="dot" />
  182. </div>
  183. </div>
  184. </div>
  185. <div id="gptSettingBox">
  186. <div id="moveIt">
  187. <svg
  188. t={1671455942102}
  189. className="icon"
  190. viewBox="0 0 1024 1024"
  191. version="1.1"
  192. xmlns="http://www.w3.org/2000/svg"
  193. p-id={2728}
  194. width={200}
  195. height={200}
  196. >
  197. <path
  198. d="M486.4 776.533333v-213.333333H247.466667v106.666667L85.333333 512l162.133334-162.133333V512h238.933333V247.466667H349.866667L512 85.333333l162.133333 162.133334h-132.266666V512h238.933333V349.866667L938.666667 512l-162.133334 162.133333v-106.666666h-238.933333v213.333333h132.266667L512 938.666667l-162.133333-162.133334h136.533333z"
  199. p-id={2729}
  200. />
  201. </svg>
  202. </div>
  203. <div id="spreadOrShrink">⇥</div>
  204. </div>
  205. </div>, document.getElementById('gptDiv'))
  206. `
  207. }
  208. function babelJsxAndRun() {
  209. let { code } = window.Babel.transform(createBoxJsx(), { presets: ['es2015', 'react'] });
  210. let functionReactJsx = new Function(code)
  211. functionReactJsx()
  212. }
  213. function createBoxReact() {
  214. return new Promise((resolve) => {
  215. ReactDOM.render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
  216. id: "gptInputBox"
  217. }, /*#__PURE__*/React.createElement("textarea", {
  218. id: "gptInput",
  219. type: "text",
  220. defaultValue: ""
  221. }), /*#__PURE__*/React.createElement("button", {
  222. id: "button_GPT"
  223. }, "\u641C\u4E00\u4E0B")), /*#__PURE__*/React.createElement("div", {
  224. id: "gptCueBox"
  225. }, /*#__PURE__*/React.createElement("div", {
  226. id: "gptAnswer",
  227. className: "markdown-body"
  228. }, /*#__PURE__*/React.createElement("div", {
  229. id: "gptAnswer_inner"
  230. }, "\u6155\u8BFE\u9898\u76EE\u641C\u641C\u641Cv1.2.1\u5DF2\u542F\u52A8"), /*#__PURE__*/React.createElement("div", {
  231. id: "loadingBox"
  232. }, "\u52A0\u8F7D\u4E2D", /*#__PURE__*/React.createElement("span", {
  233. className: "dot"
  234. })), /*#__PURE__*/React.createElement("div", {
  235. id: "loadingBoxImg"
  236. }, "\u56FE\u7247\u8F6C\u6587\u5B57\u4E2D,\u8BF7\u7A0D\u7B49", /*#__PURE__*/React.createElement("span", {
  237. className: "dot"
  238. })))), /*#__PURE__*/React.createElement("div", {
  239. id: "gptSettingBox"
  240. }, /*#__PURE__*/React.createElement("div", {
  241. id: "moveIt"
  242. }, /*#__PURE__*/React.createElement("svg", {
  243. t: 1671455942102,
  244. className: "icon",
  245. viewBox: "0 0 1024 1024",
  246. version: "1.1",
  247. xmlns: "http://www.w3.org/2000/svg",
  248. "p-id": 2728,
  249. width: 200,
  250. height: 200
  251. }, /*#__PURE__*/React.createElement("path", {
  252. d: "M486.4 776.533333v-213.333333H247.466667v106.666667L85.333333 512l162.133334-162.133333V512h238.933333V247.466667H349.866667L512 85.333333l162.133333 162.133334h-132.266666V512h238.933333V349.866667L938.666667 512l-162.133334 162.133333v-106.666666h-238.933333v213.333333h132.266667L512 938.666667l-162.133333-162.133334h136.533333z",
  253. "p-id": 2729
  254. }))), /*#__PURE__*/React.createElement("div", {
  255. id: "spreadOrShrink"
  256. }, "\u21E5"))), document.getElementById('gptDiv'));
  257. //ReactDOM.render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h2", null, "Hello World")), document.getElementById('gptDiv'));
  258. resolve("createEnded")
  259. })
  260. }
  261. /*
  262. <div id="gptInputBox">
  263. <textarea id="gptInput" type=text></textarea>
  264. <button id="button_GPT">搜一下</button>
  265. </div>
  266. <div id=gptCueBox>
  267. <div id="gptAnswer" class="markdown-body">
  268. <div id="gptAnswer_inner">慕课题目搜搜搜v1.2.1已启动</div>
  269. <div id="loadingBox">加载中<span class="dot"></span></div>
  270. <div id="loadingBoxImg">图片转文字中,请稍等<span class="dot"></span></div>
  271. </div>
  272. </div>
  273. <div id="gptSettingBox">
  274. <div id="moveIt"><svg t="1671455942102" class="icon" viewBox="0 0 1024 1024" version="1.1"
  275. xmlns="http://www.w3.org/2000/svg" p-id="2728" width="200" height="200">
  276. <path
  277. d="M486.4 776.533333v-213.333333H247.466667v106.666667L85.333333 512l162.133334-162.133333V512h238.933333V247.466667H349.866667L512 85.333333l162.133333 162.133334h-132.266666V512h238.933333V349.866667L938.666667 512l-162.133334 162.133333v-106.666666h-238.933333v213.333333h132.266667L512 938.666667l-162.133333-162.133334h136.533333z"
  278. p-id="2729"></path>
  279. </svg></div>
  280. <div id="spreadOrShrink">⇥</div>
  281. </div>
  282. */
  283.  
  284. function createBox() {
  285. return new Promise((resolve) => {
  286. var divE = document.createElement('div');
  287. var divId = document.createAttribute("id"); //创建属性
  288. divId.value = 'gptDiv'; //设置属性值
  289. divE.setAttributeNode(divId); //给div添加属性
  290. divE.innerHTML = `
  291. <div id="gptInputBox">
  292. <textarea id="gptInput" type=text></textarea>
  293. <button id="button_GPT">搜一下</button>
  294. </div>
  295. <div id=gptCueBox>
  296. <div id="gptAnswer" class="markdown-body">
  297. <div id="gptAnswer_inner">慕课题目搜搜搜v1.2.1已启动</div>
  298. <div id="loadingBox">加载中<span class="dot"></span></div>
  299. <div id="loadingBoxImg">图片转文字中,请稍等<span class="dot"></span></div>
  300. </div>
  301. </div>
  302. <div id="gptSettingBox">
  303. <div id="moveIt"><svg t="1671455942102" class="icon" viewBox="0 0 1024 1024" version="1.1"
  304. xmlns="http://www.w3.org/2000/svg" p-id="2728" width="200" height="200">
  305. <path
  306. d="M486.4 776.533333v-213.333333H247.466667v106.666667L85.333333 512l162.133334-162.133333V512h238.933333V247.466667H349.866667L512 85.333333l162.133333 162.133334h-132.266666V512h238.933333V349.866667L938.666667 512l-162.133334 162.133333v-106.666666h-238.933333v213.333333h132.266667L512 938.666667l-162.133333-162.133334h136.533333z"
  307. p-id="2729"></path>
  308. </svg></div>
  309. <div id="spreadOrShrink">⇥</div>
  310. </div>`
  311. resolve(divE)
  312. })
  313. }
  314. async function pivElemAddEventAndValue(append_case) {
  315. var search_content
  316. if (append_case === 3) {
  317. search_content = document.getElementById('q').value
  318. }
  319. if (append_case === 2) {
  320. search_content = document.getElementById('kw').value
  321. }
  322. if (append_case === 1) {
  323. search_content = document.querySelector("#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input:nth-child(3)").value
  324. }
  325. if (append_case === 0) {
  326. search_content = document.getElementsByClassName('b_searchbox')[0].value
  327. }
  328. document.getElementById("gptInput").value = search_content
  329. document.getElementById('button_GPT').addEventListener('click', () => {
  330. your_qus = document.getElementById("gptInput").value
  331. do_it()
  332.  
  333. })
  334. }
  335. async function appendBox(append_case, divE) {
  336. return new Promise((resolve, reject) => {
  337. switch (append_case) {
  338. case 0: //bing
  339. if (divE) {
  340. document.body.prepend(divE)
  341. }
  342. break;
  343. case 1://google
  344. if (document.getElementsByClassName('TQc1id ')[0]) {
  345. document.getElementsByClassName('TQc1id ')[0].prepend(divE);
  346. }
  347. else {
  348. document.getElementById("rcnt").appendChild(divE);
  349. }
  350. break;
  351. default:
  352. if (divE) {
  353. console.log(`啥情况${divE}`)
  354. }
  355. }
  356. resolve("finished")
  357. })
  358. }
  359. function addBothStyle() {
  360. GM_addStyle(`
  361. b{
  362. font-weight: bold;
  363. }
  364. #moveIt{
  365. justify-content: right;
  366. display: flex;
  367. cursor: move;
  368. }
  369. .icon{
  370. width: 100%;
  371. height: 100%;
  372. }
  373. #gptSettingBox{
  374. display: flex;
  375. flex-direction: row;
  376. width: 8%;
  377. }
  378. #spreadOrShrink{
  379. justify-content: space-evenly;
  380. display: flex;
  381. align-items: center;
  382. border: solid;
  383. border-top: none;
  384. border-bottom: none;
  385. caret-color: transparent;
  386. }
  387. #gptAnswer{
  388. margin: 4px;
  389. border-top: solid;
  390. border-bottom: solid;
  391. height: fit-content;
  392. overflow-y: auto;
  393. align-items: center;
  394. text-align: center;
  395. }
  396. #gptInput{
  397. width: 81%;
  398. border-radius: 4px;
  399. border: solid;
  400. resize: vertical;
  401. }
  402. #gptInputBox{
  403. display: flex;
  404. justify-content: space-around;
  405. }
  406. #button_GPT:hover{
  407. background:#ffffffcc;
  408. }
  409. #gptDiv{
  410. border-radius: 8px;
  411. padding: 10px;
  412. margin-bottom: 9px;
  413. width:452px;
  414. translate:-20px;
  415. background:#ffffffcc;
  416. display: flex;
  417. flex-direction: row;
  418. position: fixed;
  419. top: 80px;
  420. border: solid;
  421. right: 51px;
  422. z-index: 9999;
  423. background: white;
  424. color: black;
  425. transition: all 0.5s ease 0s;
  426. }
  427. #button_GPT{
  428. }
  429. #button_GPT{
  430. background: transparent;
  431. border-radius: 3px;
  432. }
  433. #gptCueBox{
  434. width: 68%;
  435. }
  436. #gptAnswer_inner{
  437.  
  438. }
  439. /*dots*/
  440. .dot{
  441. height: 4px;
  442. width: 4px;
  443. display: inline-block;
  444. border-radius: 2px;
  445. animation: dotting 2.4s infinite step-start;
  446. }
  447. @keyframes dotting {
  448. 25%{
  449. box-shadow: 4px 0 0 #71777D;
  450. }
  451. 50%{
  452. box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D;
  453. }
  454. 75%{
  455. box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D, 24px 0 0 #71777D;
  456. }
  457. }
  458. `)
  459. }
  460. function addBoxEvent() {
  461. if (getCookie("isShrink") == "") {
  462. setCookie("isShrink", 0, 30)
  463. }
  464. else {
  465. document.getElementById('spreadOrShrink').addEventListener("click", () => {
  466. if (getCookie("isShrink") == 0) {
  467. document.getElementById('gptInputBox').style.display = "none"
  468. document.getElementById('gptCueBox').style.display = "none"
  469. document.getElementById('gptDiv').style.width = "1.5vh"
  470. document.getElementById('spreadOrShrink').innerHTML = "\u21e4"
  471. setCookie("isShrink", 1, 30)
  472. }
  473. else {
  474. document.getElementById('gptInputBox').style.display = "flex"
  475. document.getElementById('gptCueBox').style.display = "block"
  476. document.getElementById('gptDiv').style.width = "452px"
  477. document.getElementById('spreadOrShrink').innerHTML = "\u21e5"
  478. setCookie("isShrink", 0, 30)
  479. }
  480. })
  481. }
  482. }
  483. function controlBoxDisplay(id, way) {
  484. document.getElementById(`${id}`).style.display = `${way}`
  485. }
  486. function initBox() {
  487. if (getCookie("isShrink") == 0) {
  488. document.getElementById('gptInputBox').style.display = "flex"
  489. document.getElementById('gptCueBox').style.display = "block"
  490. document.getElementById('gptDiv').style.width = "452px"
  491. document.getElementById('spreadOrShrink').innerHTML = "\u21e5"
  492. }
  493. else {
  494. document.getElementById('gptInputBox').style.display = "none"
  495. document.getElementById('gptCueBox').style.display = "none"
  496. document.getElementById('gptDiv').style.width = "1.5vh"
  497. document.getElementById('spreadOrShrink').innerHTML = "\u21e4"
  498. }
  499. controlBoxDisplay("loadingBox", "none")//默认不展示
  500. controlBoxDisplay("loadingBoxImg", "none")//默认不展示
  501. }
  502. function setCookie(cname, cvalue, exdays) {
  503. var d = new Date();
  504. d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  505. var expires = "expires=" + d.toGMTString();
  506. document.cookie = cname + "=" + cvalue + "; " + expires;
  507. }
  508. //原生cookie函数
  509. function getCookieObject() {
  510. let cookieString = document.cookie;
  511. cookieString = cookieString.substring(0, cookieString.length - 1);
  512. let tempCookieArray = cookieString.split('; ');
  513.  
  514. let cookieObject = {}; // 存放 cookie 键值对
  515.  
  516. tempCookieArray.forEach(item => {
  517. let name = item.substring(0, item.indexOf('='));
  518. let value = item.substring(item.indexOf('=') + 1);
  519. value = decodeURIComponent(value); // 还原字符串
  520. cookieObject[name] = value; // 将键值插入中这个对象中
  521. });
  522.  
  523. return cookieObject // 返回包含 cookie 键值对的对象
  524. }
  525. function getCookie(cname) {
  526. var name = cname + "=";
  527. var ca = document.cookie.split(';');
  528. for (var i = 0; i < ca.length; i++) {
  529. var c = ca[i].trim();
  530. if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
  531. }
  532. return "";
  533. }
  534. function moveIt(controlEle, movedEle) {
  535. //var demo = document.getElementById(`${settings}`)
  536. var canitmove = false
  537. var x = 0,
  538. y = 0
  539. controlEle.onmousedown = function (e) {
  540. e.preventDefault()
  541. x = e.pageX - movedEle.offsetLeft
  542. y = e.pageY - movedEle.offsetTop
  543. canitmove = true
  544. document.getElementById("gptDiv").style.transition = "none"
  545. // console.log(e.pageX)
  546. }
  547. controlEle.onmouseup = function (e) {
  548. e.preventDefault()
  549. x = e.pageX - movedEle.offsetLeft
  550. y = e.pageY - movedEle.offsetTop
  551. canitmove = false
  552. document.getElementById("gptDiv").style.transition = "all 0.5s ease 0s"
  553. // console.log(movedEle.offsetLeft)
  554. console.log(e.pageX)
  555. }
  556. window.onmouseup = function () {
  557. canitmove = false
  558. }
  559. window.onmousemove = function (e) {
  560.  
  561. if (canitmove) {
  562. movedEle.style.left = e.pageX - x + 'px'
  563. movedEle.style.top = e.pageY - y + 'px'
  564. }
  565. }
  566. }
  567. function addMoveEvent() {
  568. moveIt(document.getElementById('moveIt'), document.getElementById('gptDiv'))
  569. }
  570.  
  571. //搜题部分
  572. function getRawQues(){
  573. return document.getElementById('gptInput').value.trim().replace(/(\s)|(\\n)/g, "")
  574. }
  575. function getQues() {
  576. if (getRawQues().match(/\[.+\]/g)) {
  577. return getRawQues().match(/(?<=\[).*?(?=\])/g)[0]
  578. }else{
  579. return getRawQues()
  580. }
  581. }
  582. function getFullQues() {
  583. if (getRawQues().match(/\[.+\]/g)) {
  584. formedQues = getRawQues().match(/(?<=\[).*?(?=\])/g)[0]
  585. quesOptions[0] = getRawQues().match(/(?<=\[).*?(?=\])/g)[1]
  586. quesOptions[1] = getRawQues().match(/(?<=\[).*?(?=\])/g)[2]
  587. quesOptions[2] = getRawQues().match(/(?<=\[).*?(?=\])/g)[3]
  588. quesOptions[3] = getRawQues().match(/(?<=\[).*?(?=\])/g)[4]
  589. return true
  590. }
  591. }
  592. function appendQuesEvent() {
  593. document.addEventListener("mouseup", () => {
  594. if (unsafeWindow.getSelection().toString().replace(/(\s)|(\\n)/g, "") !== "" && !isActive("gptInput")&&isCtrl) {
  595. document.getElementById('gptInput').value = unsafeWindow.getSelection().toString().replace(/(\s)|(\\n)/g, "")
  596. }
  597. else if(isAdvanced){
  598. document.getElementById('gptInput').value +=`[${unsafeWindow.getSelection().toString().replace(/(\s)|(\\n)/g, "")}]\n`
  599. }
  600. });
  601. }
  602. function getAllAnswer() {
  603. if (getQues() !== "") {
  604. controlBoxDisplay("loadingBox", "block")
  605. log(``)
  606. getAnswer(1)
  607. .then(() => {
  608. return getAnswer(0)
  609. })
  610. .then(() => {
  611. return getAnswer(3)
  612. })
  613. .then(() => {
  614. return getAnswer(4)
  615. })
  616. .then(() => {
  617. if (enncyToken !== "") {
  618. return getAnswer(2)
  619. }
  620. })
  621. .then(() => {
  622. if (getFullQues()) {
  623. getFullQues()
  624. return getAnswer(5)
  625. }
  626. })
  627. .then(() => {
  628. controlBoxDisplay("loadingBox", "none")
  629. console.log("finished");
  630. })
  631. .catch((err) => {
  632. log(err)
  633. })
  634. }
  635. else {
  636. document.getElementById('gptAnswer_inner').innerHTML = `<div>搜索内容不能为空</div>`
  637. }
  638. }
  639. function getAnswer(chooseCase) {
  640. return new Promise((resolve) => {
  641. if (document.getElementById('gptInput').value !== "") {
  642. switch (chooseCase) {
  643. case 0:
  644. GM_abort[0] = GM_xmlhttpRequest({
  645. method: "POST",
  646. url: `https://${requestDst[0]}/wyn-nb`,
  647. headers: {
  648. "Content-Type": "application/x-www-form-urlencoded",
  649. Authorization: `${yzggToken}`,
  650. },
  651. data: `question=${getQues()}`,
  652. onloadend: function (data) {
  653. try {
  654. let parsedAnswer = JSON.parse(data.response).data
  655. resolve(data.response)
  656. if (parsedAnswer.match(/http.+/g)) {
  657. logAdd(`<br><b>一之哥哥</b>:<img src="${parsedAnswer}" alt="">`)
  658. }
  659. else if(parsedAnswer.match(/#+/g)){
  660. logAdd(`<br><b>一之哥哥(多选)</b>:<br>`)
  661. parsedAnswer.split("#").forEach((ele,index)=>{logAdd(`<b>${index+1}</b>:${ele}<br>`)})
  662. }
  663. else {
  664. logAdd(`<br><b>一之哥哥</b>:${parsedAnswer}<br>`)
  665. }
  666. } catch (err) {
  667. logAdd(`<br><b>一之哥哥err</b>:${err}`)
  668. }
  669. },
  670. onerror: function (err) {
  671. throw new Error('Error while executing the code');
  672. },
  673. ontimeout: function (err) {
  674. throw new Error('Error while executing the code');
  675. }
  676. })
  677. break;
  678. case 1:
  679. GM_abort[1] = GM_xmlhttpRequest({
  680. method: "POST",
  681. url: `http://${requestDst[1]}/api/autoFreeAnswer`,
  682. headers: {
  683. "Content-Type": "application/json",
  684. },
  685. data: `{"question": "${getQues()}"}`,
  686. onloadend: function (data) {
  687. try {
  688. console.log(data.response)
  689. if (JSON.parse(data.response).code !== 200) {
  690. logAdd(`<b>【万能】全平台</b>:${JSON.parse(data.response).msg}<br>`)
  691. }
  692. else {
  693. let allAns = ""
  694. for (let i = 0; i <= 2; i++) {
  695. allAns += `<b>${i}</b>:${JSON.parse(data.response).data.list[i]}\n\n`
  696. }
  697. logAdd(`<b>【万能】全平台</b>:${allAns}<br>`)
  698. }
  699. } catch (err) {
  700. logAdd(`<b>【万能】全平台</b>:点的太快了gg,再试一次;<br><b>错误信息</b>:"${err}"<br>`)
  701. }
  702. resolve(data.response)
  703. },
  704. onerror: function (err) {
  705. throw new Error('Error while executing the code');
  706. },
  707. ontimeout: function (err) {
  708. throw new Error('Error while executing the code');
  709. }
  710. })
  711. break;
  712. case 2:
  713. GM_abort[2] = GM_xmlhttpRequest({
  714. method: "GET",
  715. url: `https://${requestDst[3]}/query?title=${getQues()}&token=${enncyToken}`,
  716. headers: {
  717. "Content-Type": "application/json",
  718. },
  719. onloadend: function (data) {
  720. try {
  721. logAdd(`<br><b>enncy题库</b>:${JSON.parse(data.response).data.answer}<br>`)
  722. } catch (err) {
  723. logAdd(`<br><b>enncyERR</b>:${err}<br>`);
  724. }
  725. resolve(data.response)
  726. },
  727. onerror: function (err) {
  728. throw new Error('Error while executing the code');
  729. },
  730. ontimeout: function (err) {
  731. throw new Error('Error while executing the code');
  732. }
  733. })
  734. break;
  735. case 3:
  736. GM_abort[3] = GM_xmlhttpRequest({
  737. method: "POST",
  738. url: `https://${requestDst[4]}/api/v1/cx?v=1.7.8`,
  739. headers: {
  740. "Content-Type": "application/x-www-form-urlencoded",
  741. },
  742. data: `question=${getQues()}`,
  743. onloadend: function (data) {
  744. try {
  745. if (JSON.parse(data.response).data.answer == "") {
  746. logAdd(`<br><b>Ne-21题库</b>:${JSON.parse(data.response).msg}<br>`)
  747. }
  748. else {
  749. logAdd(`<br><b>Ne-21题库</b>:${JSON.parse(data.response).data.answer}<br>`)
  750. }
  751. } catch (err) {
  752. logAdd(`<br><b>Ne-21题库ERR</b>:${err}<br>`);
  753. }
  754. resolve(data.response)
  755. },
  756. onerror: function (err) {
  757. throw new Error('Error while executing the code');
  758. },
  759. ontimeout: function (err) {
  760. throw new Error('Error while executing the code');
  761. }
  762. })
  763. break;
  764. case 4:
  765. GM_abort[4] = GM_xmlhttpRequest({
  766. method: "POST",
  767. url: `http://${requestDst[5]}/v1/cx`,
  768. headers: {
  769. "Content-Type": "application/x-www-form-urlencoded",
  770. },
  771. data: 'question=' + encodeURIComponent(getQues()) + '&script=v1cx',
  772. onloadend: function (res) {
  773. try {
  774. if (JSON.parse(res.response).code) {
  775. logAdd(`<br><b>山楂树题库</b>:${JSON.parse(res.response).data}<br>`)
  776. }
  777. else {
  778. logAdd(`<br><b>山楂树题库(failed)</b>:${JSON.parse(res.response).data}<br>`)
  779. }
  780. } catch (err) {
  781. logAdd(`<br><b>山楂树题库ERR</b>:${err}<br>`);
  782. }
  783. resolve(res.response)
  784. },
  785. onerror: function (err) {
  786. throw new Error('Error while executing the code');
  787. },
  788. ontimeout: function (err) {
  789. throw new Error('Error while executing the code');
  790. }
  791. })
  792. break;
  793. case 5:
  794. GM_abort[5] = GM_xmlhttpRequest({
  795. method: "POST",
  796. url: `http://${requestDst[7]}/answer?z=${quesWorkType}&t=${quesType}`,
  797. headers: {
  798. "Content-Type": "application/json",
  799. "v": "1.4.3",
  800. "referer": `${quesSrc}`
  801. },
  802. data: `
  803. {
  804. "question":"${formedQues}",
  805. "options":[
  806. "${quesOptions[0]}",
  807. "${quesOptions[1]}",
  808. "${quesOptions[2]}",
  809. "${quesOptions[3]}"
  810. ],
  811. "type":"${quesType}",
  812. "questionData":"",
  813. "workType":"${quesWorkType}"
  814. }
  815. `,
  816. onloadend: function (res) {
  817. try {
  818. console.log(res.response)
  819. if (JSON.parse(res.response).code == 200) {
  820. logAdd(`<br><b>蛋炒饭</b>:${JSON.parse(res.response).data.answer[0]}<br>`)
  821. }
  822. else if (JSON.parse(res.response).code == -1) {
  823. logAdd(`<br><b>蛋炒饭</b>:${JSON.parse(res.response).msg}<br>`)
  824. }
  825. } catch (err) {
  826. logAdd(`<br><b>蛋炒饭题库ERR</b>:${err}<br>`);
  827. }
  828. resolve(res.response)
  829. },
  830. onerror: function (err) {
  831. throw new Error('Error while executing the code');
  832. },
  833. ontimeout: function (err) {
  834. throw new Error('Error while executing the code');
  835. }
  836. })
  837. break;
  838. default:
  839. GM_abort[5] = GM_xmlhttpRequest({
  840. method: "POST",
  841. url: "https://cx.icodef.com/wyn-nb",
  842. headers: {
  843. "Content-Type": "application/x-www-form-urlencoded",
  844. Authorization: `${yzggToken}`,
  845. },
  846. data: `question=${getQues()}`,
  847. onloadend: function (data) {
  848. document.getElementById('gptAnswer').innerHTML = JSON.parse(data.response).data
  849. },
  850. onerror: function (err) {
  851. throw new Error('Error while executing the code');
  852. },
  853. ontimeout: function (err) {
  854. throw new Error('Error while executing the code');
  855. }
  856. })
  857.  
  858. }
  859. }
  860. else {
  861. document.getElementById('gptAnswer_inner').innerHTML = `<div>搜索内容不能为空</div>`
  862. }
  863. })
  864.  
  865.  
  866.  
  867.  
  868. }
  869. function pic2WordsEvent() {
  870. document.getElementById('gptInput').addEventListener('paste', (e) => {
  871. pic2base64(e).then((base64data) => {
  872. if (base64data) {
  873. if (!ocrToken.xauthToken || !ocrToken.xauthUuid || !ocrToken.cookie) {
  874. log(`你妹有白描cookie(悲<br><a href="https://web.baimiaoapp.com/">点我去白描官网买</a>`)
  875. }
  876. else {
  877. console.log(base64data.toString());
  878. log(`尊贵的白描黄金VIP,欢迎`)
  879. controlBoxDisplay("loadingBoxImg", "block")
  880. sendOcrMode()
  881. .then((sendOcrModeRes) => {
  882. console.log(sendOcrModeRes);
  883. return sendOcrData(JSON.parse(sendOcrModeRes).data.token, base64data)
  884. })
  885. .then((sendOcrDataRes) => {
  886. // console.log(JSON.parse(sendOcrDataRes).data.jobStatusId);
  887. return JSON.parse(sendOcrDataRes).data.jobStatusId
  888. })
  889. .then((jobStatusId) => {
  890. console.log(jobStatusId);
  891. sleep(2500).then(() => {
  892. getOcrResults(jobStatusId)
  893. .then((finalRes) => {
  894. console.log(finalRes)
  895. if (JSON.parse(finalRes).code === 1) {
  896. for (let i = 0; i <= JSON.parse(finalRes).data.ydResp.data.lines.length - 1; i++) {
  897. ocrSumResults += JSON.parse(finalRes).data.ydResp.data.lines[i].text
  898. }
  899. }
  900. else {
  901. logAdd(`<br>emmm,网络有点卡,再试一次吧!`)
  902. return JSON.parse(finalRes).code
  903. }
  904. }).then((statusCode) => {
  905. if (ocrSumResults == "" && statusCode !== 0) {
  906. logAdd(`<br>识别的内容居然是空的(惊`)
  907. }
  908. else { document.getElementById('gptInput').value = `${ocrSumResults.trim()}` }
  909. }).then(() => {
  910. ocrSumResults = ""
  911. }).then(() => {
  912. controlBoxDisplay("loadingBoxImg", "none")
  913. })
  914. })
  915.  
  916.  
  917. })
  918. }
  919.  
  920. }
  921. else {
  922. console.log("原来只是正常的复制而已(*~*)");
  923. }
  924.  
  925. })
  926. })
  927. }
  928. function pic2base64(e) {
  929. return new Promise((resolve) => {
  930. e.stopPropagation();
  931. // e.preventDefault();
  932. // 阻止粘贴
  933. // 获取剪贴板信息
  934. var clipboardData = e.clipboardData || window.clipboardData;
  935. var items = clipboardData.items;
  936. for (var i = 0; i < items.length; i++) {
  937. var item = items[i];
  938. if (item.kind == 'file') {
  939. var pasteFile = item.getAsFile();
  940. var reader = new FileReader();
  941. reader.onload = function (event) {
  942. // 将结果显示在<textarea>中
  943. resolve(event.target.result)
  944. // console.log(event.target.result);
  945. }
  946. // 将文件读取为BASE64格式字符串
  947. reader.readAsDataURL(pasteFile);
  948. break;
  949. }
  950. else {
  951. resolve(0)
  952. }
  953. }
  954. })
  955. }
  956. const sleep = (time) => {
  957. return new Promise(resolve => setTimeout(resolve, time))
  958. }
  959. function getOcrResults(jobStatusId) {
  960. return new Promise((resolve) => {
  961. GM_xmlhttpRequest({
  962. method: "GET",
  963. url: `https://web.baimiaoapp.com/api/ocr/image/xunfei/status?jobStatusId=${jobStatusId}`,
  964. headers: {
  965. "Content-Type": "application/json;charset=UTF-8",
  966. "x-auth-token": ocrToken.xauthToken,
  967. "x-auth-uuid": ocrToken.xauthUuid,
  968. "Cookie": ocrToken.cookie,
  969. "Connection": "keep-alive",
  970. "Accept": "*/*"
  971. },
  972. onloadend: function (data) {
  973. try {
  974. resolve(data.response)
  975. } catch (err) {
  976. logAdd(`err:${err}`)
  977. }
  978. },
  979. onerror: function (err) {
  980. logAdd(`err:${err}`)
  981. },
  982. ontimeout: function (err) {
  983. logAdd(`err:${err}`)
  984. }
  985. })
  986. })
  987.  
  988. }
  989. function sendOcrData(nextToken, base64data) {
  990. return new Promise((resolve) => {
  991. GM_xmlhttpRequest({
  992. method: "POST",
  993. url: "https://web.baimiaoapp.com/api/ocr/image/xunfei",
  994. headers: {
  995. "Content-Type": "application/json;charset=UTF-8",
  996. "x-auth-token": ocrToken.xauthToken,
  997. "x-auth-uuid": ocrToken.xauthUuid,
  998. "Cookie": ocrToken.cookie,
  999. "Connection": "keep-alive",
  1000. "Accept": "*/*"
  1001. },
  1002. data: `{"token":"${nextToken}","hash":"3f9c056379f0457c564290f6e15a9c232f1e5557","name":"image.png","size":13764,"dataUrl":"${base64data}","result":{},"status":"processing","isSuccess":false}`,
  1003. onloadend: function (data) {
  1004. try {
  1005. resolve(data.response)
  1006. } catch (err) {
  1007. logAdd(`err:${err}`)
  1008. }
  1009. },
  1010. onerror: function (err) {
  1011. logAdd(`err:${err}`)
  1012. },
  1013. ontimeout: function (err) {
  1014. logAdd(`err:${err}`)
  1015. }
  1016. })
  1017. })
  1018.  
  1019. }
  1020. function sendOcrMode() {
  1021. return new Promise((resolve) => {
  1022. GM_xmlhttpRequest({
  1023. method: "POST",
  1024. url: "https://web.baimiaoapp.com/api/perm/single",
  1025. headers: {
  1026. "Content-Type": "application/json;charset=UTF-8",
  1027. "x-auth-token": ocrToken.xauthToken,
  1028. "x-auth-uuid": ocrToken.xauthUuid,
  1029. cookie: ocrToken.cookie
  1030. },
  1031. data: `{"mode": "single"}`,
  1032. onloadend: function (data) {
  1033. try {
  1034. resolve(data.response)
  1035. } catch (err) {
  1036. logAdd(`err:${err}`)
  1037. }
  1038. },
  1039. onerror: function (err) {
  1040. logAdd(`err:${err}`)
  1041. },
  1042. ontimeout: function (err) {
  1043. logAdd(`err:${err}`)
  1044. }
  1045. })
  1046. })
  1047.  
  1048. }
  1049. function addSearchEvent() {
  1050. document.getElementById('button_GPT').addEventListener("click", () => {
  1051. getAllAnswer()
  1052. })
  1053. }
  1054. function keyEvent() {
  1055. document.onkeydown = function (e) {
  1056. // console.log(e)
  1057. var keyNum = window.event ? e.keyCode : e.which;
  1058. if (13 == keyNum && e.ctrlKey) {
  1059. console.log(isAdvanced)
  1060. if (isActive("gptInput")) {
  1061. document.getElementById('button_GPT').click()
  1062. }
  1063. else {
  1064. console.log("失焦不执行")
  1065. }
  1066. }
  1067. else if(e.ctrlKey){
  1068. isCtrl=true
  1069. }
  1070. else{
  1071. isCtrl=false
  1072. }
  1073. }
  1074. document.addEventListener("keydown", (e)=>{
  1075. var keyNum = window.event ? e.keyCode : e.which;
  1076. if(65 == keyNum && e.altKey){
  1077. isAdvanced=true
  1078. console.log(isAdvanced)
  1079. }
  1080. });
  1081. document.onkeyup= function (e) {
  1082. isCtrl=false
  1083. isAdvanced=false
  1084. }
  1085.  
  1086. }
  1087. function isActive(id) {
  1088. var myInput = document.getElementById(id);
  1089. if (myInput == document.activeElement) {
  1090. return 1
  1091. } else {
  1092. return 0
  1093. }
  1094. }
  1095. function getBase64Size(base64) {//获取base64字符串的大小
  1096. /*
  1097. 参考:https://www.jb51.net/article/172316.htm
  1098. 并优化后代码
  1099. */
  1100. if (base64) { // 获取base64图片byte大小
  1101. base64 = base64.split(",")[1].split("=")[0];
  1102. var strLength = base64.length;
  1103. var fileLength = strLength - (strLength / 8) * 2;
  1104. return Math.floor(fileLength); // 向下取整
  1105. } else {
  1106. return null
  1107. }
  1108. };
  1109. function log(temp_1) {
  1110. document.getElementById('gptAnswer_inner').innerHTML = temp_1
  1111. }
  1112. function logAdd(temp_1) {
  1113. document.getElementById('gptAnswer_inner').innerHTML += temp_1
  1114. }
  1115.  
  1116. }
  1117. (function () { window.onload = mainTop })()