52pojie-helper

1.填充验证码。2.填充评论。3.缩进右侧条。

  1. // ==UserScript==
  2. // @name 52pojie-helper
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 1.填充验证码。2.填充评论。3.缩进右侧条。
  6. // @author nameldk
  7. // @match https://www.52pojie.cn/thread-*.html
  8. // @match https://www.52pojie.cn/forum.php?mod=viewthread*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. /**
  16. * 填充验证码
  17. */
  18. function inputAns() {
  19. function getInput(){
  20. return document.querySelector('#seccodeqS0 input[name="secanswer"]');
  21. }
  22.  
  23. function fill() {
  24. var input = getInput();
  25. var ans = document.querySelector('#seccodeqS0_menu');
  26. if (input && ans) {
  27. input.value = ans.innerText.replace(/.+答案:/,"");
  28. } else {
  29. console.warn('empty', input, ans);
  30. }
  31. }
  32. function bind() {
  33. var input = getInput();
  34. var a = document.querySelector('#seccodeqS0 a');
  35. if(a) {
  36. a.addEventListener('click', function(){
  37. setTimeout(function(){
  38. var input = getInput();
  39. bind();
  40. fill();
  41. input.blur();
  42. }, 500);
  43. });
  44. } else {
  45. console.warn('no a click');
  46. }
  47. }
  48. fill();
  49. bind();
  50. }
  51.  
  52. /**
  53. * 填充评论
  54. */
  55. function inputComment(){
  56. var commentInput = document.querySelector('#fastpostmessage');
  57. var commentList = [];
  58. var list = document.querySelectorAll('td[id^="postmessage"]');
  59.  
  60. function getOne() {
  61. return commentList[Math.random()*commentList.length|0];
  62. }
  63.  
  64. function change(){
  65. commentInput.value = getOne() + getOne();
  66. commentInput.focus();
  67. commentInput.blur();
  68. }
  69.  
  70. if (list) {
  71. var a = document.querySelector('#secqaa_qS0');
  72. if (a && a.parentNode) {
  73. var c = document.createElement('a');
  74. c.text='换评论';
  75. c.href='javascrit:;';
  76. c.onclick = function(){
  77. change();
  78. };
  79. a.parentNode.appendChild(c);
  80. }
  81.  
  82. var i = 0;
  83. for (var o of list){
  84. if ((i++) == 0) continue;
  85. commentList[commentList.length] = o.innerText.replace(/.+? 发表于 .+? .+?:.+?/,'').replace(/\s+/,'');
  86. }
  87. change();
  88. }
  89. }
  90.  
  91. /**
  92. * 缩进右侧条
  93. */
  94. function indentBar() {
  95. var jz52top = document.querySelector('#jz52top');
  96.  
  97. if (jz52top){
  98. jz52top.style.right = '-30px';
  99. jz52top.addEventListener('mouseover', function(){
  100. this.style.right = '0px';
  101. });
  102. jz52top.addEventListener('mouseout', function(){
  103. this.style.right = '-30px';
  104. });
  105. }
  106.  
  107. }
  108.  
  109.  
  110. setTimeout(function(){
  111. indentBar();
  112. inputAns();
  113. inputComment();
  114. }, 1000);
  115. })();