dati

自动答题

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

  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.2
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. function checkPreview() {
  15. if (document.querySelector('div[class^="answerPreview"]')) {
  16. checkAnswer(1);
  17. console.log('30秒后开始答题,检测答案中..');
  18. return;
  19. }
  20. setTimeout(function() {
  21. checkPreview();
  22. }, 1000);
  23. }
  24.  
  25. function checkAnswer(t) {
  26. var users = ['37丶机器人', '冻猫', 'Desperado柚丶追梦', '钱江湖畔丶姜中陪伴', '枫哥的健身卡', '头顶青天的姜琴', '赵海洋家在临沂', '幽深眼睛', '枫一样的EM', '小姜尸头很大'];
  27. for (var i = 0; i < users.length; i++) {
  28. var user = document.querySelectorAll('[data-nn="' + users[i] + '"]');
  29. if (user.length > 0) {
  30. var text = user[user.length - 1].parentNode.parentNode.querySelector('.chat-msg-item').innerText;
  31. switch (text.substr(0, 1).toUpperCase()) {
  32. case 'A':
  33. answer(1);
  34. console.log('检测到神仙答案A');
  35. return;
  36. case 'B':
  37. answer(2);
  38. console.log('检测到神仙答案B');
  39. return;
  40. case 'C':
  41. answer(3);
  42. console.log('检测到神仙答案C');
  43. return;
  44. }
  45. }
  46. }
  47. if (t > 270) {
  48. findAnswer();
  49. return;
  50. }
  51. t++;
  52. setTimeout(function() {
  53. checkAnswer(t);
  54. }, 100);
  55. }
  56.  
  57. function findAnswer() {
  58. var json = {};
  59. json[1] = 0;
  60. json[2] = 0;
  61. json[3] = 0;
  62. var content = document.querySelectorAll('.chat-msg-item').length ? document.querySelectorAll('.chat-msg-item') : document.querySelectorAll('.Barrage-content');
  63. for (var i = 0; i < content.length; i++) {
  64. switch (content[i].innerText.substr(0, 1).toUpperCase()) {
  65. case 'A':
  66. json[1]++;
  67. break;
  68. case 'B':
  69. json[2]++;
  70. break;
  71. case 'C':
  72. json[3]++;
  73. break;
  74. }
  75. }
  76. var tempVal = 0,
  77. tempKey = '';
  78. for (var key in json) {
  79. if (json[key] > tempVal) {
  80. tempKey = key;
  81. tempVal = json[key];
  82. }
  83. }
  84. console.log('检测到最多答案为:' + tempKey);
  85. answer(tempKey);
  86. }
  87.  
  88. function answer(i) {
  89. var li = document.querySelectorAll('div[class^="answerProblem"] ul li');
  90. if (li.length > 0) {
  91. li[i - 1].click();
  92. console.log('答题完成,19分钟后自动刷新网页');
  93. setTimeout(function() {
  94. window.location.reload();
  95. }, 1140000);
  96. return;
  97. }
  98. setTimeout(function() {
  99. answer(i);
  100. }, 20);
  101. }
  102.  
  103. checkPreview();