答题Plus

获得你满意的答案

  1. // ==UserScript==
  2. // @name 答题Plus
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 获得你满意的答案
  6. // @author Zszen
  7. // @match http://47.105.51.227:9214/resources/exam/*
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_download
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var label = 'Zszen '
  15. var url = window.location.href;
  16. var res = /\/\/(.+?\..*?)(\/|\?)/.exec(url);
  17. var res2 = /\/\/(.+?\..*?)(:|\/|\?)/.exec(url);
  18. var site = res[1];
  19. var siteIP = res2[1];
  20. if(siteIP == '47.105.51.227'){
  21. var pool_questions = ELs('div',
  22. el=>el.className=='list-group-item shenyue',
  23. el=>{
  24. var el2 = el.children[0];
  25. el2.addEventListener('mouseout',()=>{
  26. //show_div(false);
  27. });
  28. el2.addEventListener('mouseover',()=>{
  29. var title = /\d+、(.*?)\[/.exec(el.textContent)[1];
  30. console.log("https://www.asklib.com/s/"+title);
  31. GM_xmlhttpRequest({
  32. method: "GET",
  33. url: "https://www.asklib.com/s/"+title,
  34. onload: function(res) {
  35. var txt = res.responseText
  36. var links = /\<a href\=\"(.*?)\"\>参考答案\<\/a\>/.exec(txt);
  37. console.log("https://www.asklib.com"+links[1]);
  38. GM_xmlhttpRequest({
  39. method: "GET",
  40. url: "https://www.asklib.com"+links[1],
  41. onload: function(res) {
  42. var txt = res.responseText;
  43. var d = /\<div class\=\"listleft \">([\d\D]+)\<div class=\"listright\"/.exec(txt)[1]
  44. //console.log(d);
  45. //var reg = /\>(.+?)\</g;
  46. var matches = d.split('\n')
  47. var pool_contents = [];
  48. for(var k in matches){
  49. var txt_line = matches[k];
  50. txt_line = txt_line.replace(/\<.*?\>/g, '');
  51. txt_line = txt_line.replace(/(\<|\>|\t+| +)/g, '');
  52. //console.log([txt_line])
  53. if(txt_line!=""){
  54. pool_contents.push(txt_line)
  55. }
  56. }
  57.  
  58. var pool_quests = [];
  59. var answer_title_index = pool_contents.indexOf('参考答案:');
  60. pool_quests.push(pool_contents[answer_title_index+1]);
  61. var question_title_index = pool_contents.indexOf('问题:');
  62. pool_quests.push(pool_contents[question_title_index+1]);
  63. pool_quests = pool_quests.concat(pool_contents[question_title_index+2].match(/(A|B|C|D)\.(.(?!\.))*/g));
  64. show_div(true, pool_quests.join('\n'));
  65. }
  66. });
  67. }
  68. });
  69. })
  70. }
  71. );
  72. }
  73.  
  74. function get_div(){
  75. var div = null;
  76. if(document.getElementsByClassName('div answers').length==0){
  77. div = document.createElement('div');
  78. div.className = 'div answers';
  79. div.style = "padding:10px;width:200px;height:auto;position:fixed;background-color:#232323;color:#FFEfff;text-decoration-thickness:0.1em;font-size:120%;right:20px;top:100px;opacity:.65;border-radius:10px"
  80. document.body.appendChild(div);
  81. }else{
  82. div = document.getElementsByClassName('div answers')[0];
  83. }
  84. return div;
  85. }
  86.  
  87. function show_div(visible, content){
  88. var div = get_div();
  89. if(visible){
  90. div.style.display = 'block';
  91. }else{
  92. div.style.display = 'none';
  93. }
  94. if(content==null) return;
  95. div.innerText = content;
  96. }
  97.  
  98. function ELs(tagName, conditionFun, dealFun, parent){
  99. if(parent==null) parent = document;
  100. var tags = [...parent.getElementsByTagName(tagName)];
  101. if(conditionFun){
  102. tags = tags.filter(conditionFun);
  103. }
  104. if(dealFun){
  105. tags.forEach(dealFun);
  106. }
  107. return tags;
  108. }
  109.  
  110.  
  111.  
  112. // Your code here...
  113. })();