dati

自动答题

目前为 2018-11-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name dati
  3. // @name:zh-CN 大头答题
  4. // @namespace www.icycat.com
  5. // @description 自动答题
  6. // @description:zh-CN 检测答案自动答题
  7. // @include https://www.douyu.com/9999
  8. // @include https://www.douyu.com/1209
  9. // @include https://www.douyu.com/196
  10. // @version 1.3
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. function checkPreview() {
  15. if (document.querySelector('div[class^="answerPreview"]')) {
  16. console.log('30秒后开始答题');
  17. setTimeout(function(){
  18. console.log('开始检测答案');
  19. checkAnswer(1);
  20. },25000);
  21. return;
  22. }
  23. setTimeout(function() {
  24. checkPreview();
  25. }, 1000);
  26. }
  27.  
  28. function checkAnswer(t) {
  29. var users = ['245155','144327686','2025628','892552'];
  30. for (var i = 0; i < users.length; i++) {
  31. var user = document.querySelectorAll('[data-uid="' + users[i] + '"]');
  32. if (user.length > 0) {
  33. var text = user[user.length - 1].parentNode.parentNode.querySelector('.Barrage-content').innerText;
  34. switch (text.substr(0, 1).toUpperCase()) {
  35. case 'A':
  36. answer(1);
  37. console.log('检测到神仙答案A');
  38. return;
  39. case 'B':
  40. answer(2);
  41. console.log('检测到神仙答案B');
  42. return;
  43. case 'C':
  44. answer(3);
  45. console.log('检测到神仙答案C');
  46. return;
  47. }
  48. }
  49. }
  50. if (t > 10) {
  51. findAnswer(t);
  52. return;
  53. }
  54. t++;
  55. setTimeout(function() {
  56. checkAnswer(t);
  57. }, 100);
  58. }
  59.  
  60. function findAnswer(t) {
  61. var json = {};
  62. json[1] = 0;
  63. json[2] = 0;
  64. json[3] = 0;
  65. var content = document.querySelectorAll('.chat-msg-item').length ? document.querySelectorAll('.chat-msg-item') : document.querySelectorAll('.Barrage-content');
  66. for (var i = 0; i < content.length; i++) {
  67. switch (content[i].innerText.substr(0, 1).toUpperCase()) {
  68. case 'A':
  69. json[1]++;
  70. break;
  71. case 'B':
  72. json[2]++;
  73. break;
  74. case 'C':
  75. json[3]++;
  76. break;
  77. }
  78. }
  79. var tempVal = 0,
  80. tempKey = '';
  81. for (var key in json) {
  82. if (json[key] > tempVal) {
  83. tempKey = key;
  84. tempVal = json[key];
  85. }
  86. }
  87. console.log('检测到最多答案为' + tempKey + '!');
  88. if (tempKey) {
  89. answer(tempKey);
  90. } else {
  91. t++;
  92. if (t < 20) {
  93. setTimeout(function() {
  94. findAnswer(t);
  95. }, 100);
  96. } else {
  97. answer(2);
  98. }
  99. }
  100. }
  101.  
  102. function answer(i) {
  103. var li = document.querySelectorAll('div[class^="answerProblem"] ul li');
  104. if (li.length > 0) {
  105. li[i - 1].click();
  106. console.log('答题完成,19分钟后自动刷新网页');
  107. setTimeout(function() {
  108. window.location.reload();
  109. }, 1140000);
  110. return;
  111. }
  112. setTimeout(function() {
  113. answer(i);
  114. }, 10);
  115. }
  116.  
  117. checkPreview();