💡智慧树复读机-优化版

半自动回答习惯分问题,基于原作者@ch3cknull修改

  1. // ==UserScript==
  2. // @name 💡智慧树复读机-优化版
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.2
  5. // @description 半自动回答习惯分问题,基于原作者@ch3cknull修改
  6. // @author Erick
  7. // @require https://unpkg.com/axios/dist/axios.min.js
  8. // @match https://qah5.zhihuishu.com/qa.html
  9. // @license MIT
  10. // ==/UserScript==
  11. (function() {
  12. const e = document.createEvent("MouseEvents");
  13. e.initEvent("click", true, true);
  14. const input = document.createEvent("HTMLEvents");
  15. input.initEvent("input", true, false);
  16. const state = (document.URL.includes('home'))?'home':'detail'
  17. const MY_ANSWER_API = "https://creditqa.zhihuishu.com/creditqa/web/qa/myAnswerList"
  18. const HOT_QUESTION = "https://creditqa.zhihuishu.com/creditqa/web/qa/getHotQuestionList"
  19. const NEW_QUESTION = "https://creditqa.zhihuishu.com/creditqa/web/qa/getRecommendList"
  20. const config = {
  21. offset: 0,
  22. currURL: HOT_QUESTION
  23. }
  24. const CASLOGC = document.cookie.split(';')
  25. .filter(item => item.includes('CASLOGC'))
  26. .toString().trim()
  27. .replace(/\"/g, "'").split('=')[1]
  28. const uuid = JSON.parse(decodeURIComponent(CASLOGC)).uuid
  29. let reqCount = 0
  30. let params = {
  31. uuid: uuid, dateFormate: new Date() * 1,
  32. pageIndex: 0, pageSize: 50
  33. }
  34. params.recruitId = document.URL.split('?')[1].split('&')
  35. .filter( item => item.includes('recruitId'))[0].split('=')[1]
  36. params.courseId = document.URL.split('/')[6].split('?')[0]
  37.  
  38. function Grama(mode) {
  39. const question = document.querySelector('.question-content').children[0].innerText
  40. const ans = document.querySelector('.answer-content').children[0].innerText
  41. if(ans!=""){
  42. console.log(ans)
  43. return ans
  44. }
  45. else{
  46. console.log(ans+"111")
  47. setTimeout(Grama(mode),1000)
  48. }
  49.  
  50. }
  51.  
  52. function binding() {
  53. const panel = document.querySelector('.wheel-pannel')
  54. if (!panel) console.log('not panel')
  55. document.querySelector('.wheel-pannel').addEventListener('click', (e) => {
  56. const text = document.querySelector('textarea')
  57. const mode = e.target.classList[1].split('wheel-')[1]
  58. text.innerText = Grama(mode)
  59. text.dispatchEvent(input)
  60. })
  61. document.querySelector('.up-btn').addEventListener('click', () => {
  62. const questionId = location.hash.split('/')[4].split('?')[0]
  63. let answered = getMyAnswer()
  64. answered.push(questionId)
  65. localStorage.setItem('answered', JSON.stringify(answered))
  66. })
  67. }
  68. function Render() {
  69. return `<p style="color:red;font-size: 16px;">关注公众号"泛流查题FUNLOOK",超全的查题公众号(已收录1亿+题目)</p>
  70. <img style="position:fixed;right:200px;top:120px;z-index:1000;height="200" width="200"" src="https://mmkjsucai.oss-cn-hangzhou.aliyuncs.com/qrcode_for_gh_1f713e066caa_258-2.jpg">
  71. <p style="background-color:rgb(255,255,0);color:red;font-size: 16px;position:fixed;right:200px;top:320px;z-index:1000;height="200" >关注公众号"泛流查题FUNLOOK",超全的查题公众号(已收录1亿+题目)</p>
  72. `
  73. }
  74. function bindingHome() {
  75. let list = document.querySelector('.el-scrollbar__view').children[0]
  76. document.querySelector('.tab-container').addEventListener('click', (e) => {
  77. let text = e.target.innerText
  78. if (text == "热门") config.currURL = HOT_QUESTION
  79. if (text == "最新") config.currURL = NEW_QUESTION
  80. if (text == "热门" || text == "最新") diffImprove(config.currURL)
  81. })
  82. let observer = new MutationObserver( mutations => {
  83. mutations.forEach( mutation => {
  84. if (mutation.type === 'childList') {
  85. reqCount++;
  86. if (reqCount == 50 && list.children.length !== 51) {
  87. diffImprove(config.currURL)
  88. }
  89. }
  90. })
  91. })
  92. observer.observe(list, {
  93. attributes:false,
  94. childList: true,
  95. subtree:false,
  96. })
  97. }
  98.  
  99. async function getMyAnswer() {
  100. const courseId = document.URL.split('/')[6].split('?')[0]
  101. let answered = JSON.parse(localStorage.getItem('answered')) || {}
  102. let currentCourse = answered[courseId] || null
  103. let lastModified = JSON.parse(localStorage.getItem('lastModified')) || new Date() * 1
  104. let current = new Date() * 1
  105. if (currentCourse == null || current - lastModified > 600*1000) {
  106. const data = Object.assign(params)
  107. data.pageSize = 200
  108. await axios.get(MY_ANSWER_API, {params:data}).then( res => {
  109. currentCourse = res.data.rt.myAnswers.map(item => item.qid)
  110. console.log(currentCourse)
  111. answered[courseId] = currentCourse
  112. console.log(currentCourse);
  113. localStorage.setItem('answered', JSON.stringify(answered))
  114. localStorage.setItem('lastModified', JSON.stringify(new Date()*1))
  115. })
  116. }
  117. return answered[courseId]
  118. }
  119.  
  120. async function diffImprove(url=HOT_QUESTION, offset=0) {
  121. if (url.includes('home')) return
  122. let myAnswer, pageAnswer, arr, ans
  123. //params and offset
  124. const data = Object.assign(params)
  125. data.pageIndex = config.offset
  126. config.offset = data.pageIndex + offset
  127. // get data
  128. myAnswer = await getMyAnswer()
  129. await axios.get(url, {params: data}).then( res => {
  130. pageAnswer = res.data.rt.questionInfoList
  131. arr = pageAnswer.map(item => item.questionId)
  132. .filter(item => myAnswer.includes(item))
  133. ans = pageAnswer.filter( item => arr.includes(item.questionId))
  134. .map(item => `${item.userDto.username}${item.content}`)
  135. patchImprove(ans)
  136. })
  137. }
  138. async function patchImprove(res) {
  139. // iterate dom list and add marks
  140. const list = Array.from(document.querySelectorAll('.question-item'))
  141. list.forEach( item => {
  142. const flag = item.querySelector('.user-name').title + item.querySelector('.question-content').title
  143. if (res.includes(flag)) {
  144. const child = item.querySelector(".question-content")
  145. child.innerText += "(已作答)"
  146. child.style.color = 'red'
  147. reqCount = 0
  148. }
  149. })
  150. }
  151. window.onload = () => {
  152. if (state == 'home') setTimeout(home, 1000)
  153. else setTimeout(detail, 1000)
  154.  
  155. async function detail() {
  156. const btn = document.querySelector('.my-answer-btn')
  157. if (btn == null) return
  158. btn.dispatchEvent(e)
  159. setTimeout(() => {
  160. const text = document.querySelector('textarea')
  161. const dialog = document.querySelector('.header-title')
  162. if (!text) return
  163. text.innerText = Grama("default")
  164. text.dispatchEvent(input)
  165. dialog.innerHTML += Render()
  166. binding()
  167. }, 200)
  168. }
  169. async function home() {
  170. bindingHome()
  171. diffImprove()
  172. }
  173. }
  174. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址