考试题库划词搜索

适用与超星,智慧树等任意考试网站搜索一之题库的答案,支持划词搜索、拖拽和自定义token(加密显示)

  1. // ==UserScript==
  2. // @name 考试题库划词搜索
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7
  5. // @description 适用与超星,智慧树等任意考试网站搜索一之题库的答案,支持划词搜索、拖拽和自定义token(加密显示)
  6. // @match *://*/*
  7. // @grant GM_xmlhttpRequest
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @connect q.icodef.com
  11. // @author 有问题联系q: 2430486030
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // 创建搜索框和结果显示区域
  19. const container = document.createElement('div');
  20. container.style.cssText = `
  21. position: fixed;
  22. top: 10px;
  23. right: 10px;
  24. z-index: 9999;
  25. background-color: #f0f0f0;
  26. border-radius: 5px;
  27. padding: 10px;
  28. box-shadow: 0 0 10px rgba(0,0,0,0.1);
  29. font-family: Arial, sans-serif;
  30. cursor: move;
  31. `;
  32.  
  33. const searchBox = document.createElement('input');
  34. searchBox.type = 'text';
  35. searchBox.placeholder = '输入问题搜索答案';
  36. searchBox.style.cssText = `
  37. width: 200px;
  38. padding: 5px;
  39. border: 1px solid #ccc;
  40. border-radius: 3px;
  41. font-size: 14px;
  42. cursor: text;
  43. margin-bottom: 5px;
  44. `;
  45.  
  46. const tokenInput = document.createElement('input');
  47. tokenInput.type = 'password';
  48. tokenInput.placeholder = '输入你的token';
  49. tokenInput.style.cssText = `
  50. width: 170px;
  51. padding: 5px;
  52. border: 1px solid #ccc;
  53. border-radius: 3px 0 0 3px;
  54. font-size: 14px;
  55. cursor: text;
  56. margin-bottom: 5px;
  57. `;
  58.  
  59. const toggleTokenVisibility = document.createElement('button');
  60. toggleTokenVisibility.textContent = '👁️';
  61. toggleTokenVisibility.style.cssText = `
  62. width: 30px;
  63. padding: 5px;
  64. border: 1px solid #ccc;
  65. border-left: none;
  66. border-radius: 0 3px 3px 0;
  67. font-size: 14px;
  68. cursor: pointer;
  69. background-color: #f0f0f0;
  70. `;
  71.  
  72. const tokenInputWrapper = document.createElement('div');
  73. tokenInputWrapper.style.cssText = `
  74. display: flex;
  75. margin-bottom: 5px;
  76. `;
  77. tokenInputWrapper.appendChild(tokenInput);
  78. tokenInputWrapper.appendChild(toggleTokenVisibility);
  79.  
  80. const saveTokenButton = document.createElement('button');
  81. saveTokenButton.textContent = '保存Token';
  82. saveTokenButton.style.cssText = `
  83. padding: 5px;
  84. margin-left: 5px;
  85. cursor: pointer;
  86. `;
  87.  
  88. const resultDiv = document.createElement('div');
  89. resultDiv.style.cssText = `
  90. margin-top: 10px;
  91. max-width: 300px;
  92. max-height: 200px;
  93. overflow-y: auto;
  94. background-color: white;
  95. padding: 10px;
  96. border-radius: 3px;
  97. font-size: 14px;
  98. line-height: 1.4;
  99. cursor: default;
  100. `;
  101.  
  102. container.appendChild(tokenInputWrapper);
  103. container.appendChild(saveTokenButton);
  104. container.appendChild(searchBox);
  105. container.appendChild(resultDiv);
  106. document.body.appendChild(container);
  107.  
  108. // 读取保存的token
  109. let token = GM_getValue('oneTokenValue', '');
  110. tokenInput.value = token;
  111.  
  112. // 切换token可见性
  113. toggleTokenVisibility.addEventListener('click', function() {
  114. if (tokenInput.type === 'password') {
  115. tokenInput.type = 'text';
  116. toggleTokenVisibility.textContent = '🔒';
  117. } else {
  118. tokenInput.type = 'password';
  119. toggleTokenVisibility.textContent = '👁️';
  120. }
  121. });
  122.  
  123. // 保存token
  124. saveTokenButton.addEventListener('click', function() {
  125. token = tokenInput.value.trim();
  126. GM_setValue('oneTokenValue', token);
  127. alert('Token已保存');
  128. });
  129.  
  130. // 添加拖拽功能
  131. let isDragging = false;
  132. let dragOffsetX, dragOffsetY;
  133.  
  134. container.addEventListener('mousedown', function(e) {
  135. if (e.target === container) {
  136. isDragging = true;
  137. dragOffsetX = e.clientX - container.offsetLeft;
  138. dragOffsetY = e.clientY - container.offsetTop;
  139. }
  140. });
  141.  
  142. document.addEventListener('mousemove', function(e) {
  143. if (isDragging) {
  144. container.style.left = (e.clientX - dragOffsetX) + 'px';
  145. container.style.top = (e.clientY - dragOffsetY) + 'px';
  146. container.style.right = 'auto';
  147. }
  148. });
  149.  
  150. document.addEventListener('mouseup', function() {
  151. isDragging = false;
  152. });
  153.  
  154. // 添加事件监听器
  155. searchBox.addEventListener('keypress', function(e) {
  156. if (e.key === 'Enter') {
  157. searchAnswer(this.value);
  158. }
  159. });
  160.  
  161. // 添加划词搜索功能
  162. let selectionTimeout;
  163. document.addEventListener('selectionchange', function() {
  164. clearTimeout(selectionTimeout);
  165. selectionTimeout = setTimeout(() => {
  166. const selectedText = window.getSelection().toString().trim();
  167. if (selectedText) {
  168. searchBox.value = selectedText;
  169. searchAnswer(selectedText);
  170. }
  171. }, 2000); // 2秒延迟
  172. });
  173.  
  174. // 搜索答案的函数
  175. function searchAnswer(question) {
  176. if (!token) {
  177. resultDiv.textContent = '请先设置你的Token';
  178. return;
  179. }
  180.  
  181. const simple = "true";
  182. const split = "%23";
  183. const url = `https://q.icodef.com/api/v1/q/${encodeURIComponent(question)}?simple=${simple}&token=${token}&split=${split}`;
  184.  
  185. resultDiv.textContent = '搜索中...';
  186.  
  187. GM_xmlhttpRequest({
  188. method: "GET",
  189. url: url,
  190. onload: function(response) {
  191. console.log(response);
  192. if (response.status === 200) {
  193. const result = JSON.parse(response.response);
  194. if (result.data) {
  195. resultDiv.textContent = `搜索结果:${result.data}`;
  196. } else {
  197. resultDiv.textContent = '未找到相关答案';
  198. }
  199. } else {
  200. const result = JSON.parse(response.response);
  201. resultDiv.textContent = result.msg || '搜索失败,请稍后再试';
  202. }
  203. },
  204. onerror: function(error) {
  205. console.error('搜索出错:', error);
  206. resultDiv.textContent = '搜索出错,请检查网络连接';
  207. }
  208. });
  209. }
  210. })();

QingJ © 2025

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