Reddit Mod Nuke Userscript

This userscript helps reddit moderators delete threads.

目前为 2014-08-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Reddit Mod Nuke Userscript
  3. // @namespace RMNU
  4. // @version 3.141.592.653
  5. // @include htt*://*.reddit.com/*
  6. // @author djimbob (dr jimbob)
  7. // @description This userscript helps reddit moderators delete threads.
  8. // ==/UserScript==
  9.  
  10. delete_function = function(thread_root) {
  11. var elmnts = document.getElementsByClassName('id-'+thread_root)[0].querySelectorAll('form input[value="removed"]~span.option.error a.yes,a[onclick^="return big_mod_action($(this), -1)"]');
  12. for(var i=0; i < elmnts.length; i++) {
  13. setTimeout(
  14. (function(_elmnt) {
  15. return function() {
  16. var event = document.createEvent('UIEvents');
  17. event.initUIEvent('click', true, true, window, 1);
  18. _elmnt.dispatchEvent(event);
  19. }}
  20. )(elmnts[i]), 1500*i); // 1.5s timeout prevents overloading reddit.
  21. };
  22. }
  23.  
  24. if(document.querySelector('body.moderator')){ // only execute if you are a moderator
  25. var nuke_button = new Array();
  26. var divels = document.querySelectorAll('div.noncollapsed');
  27. var comment_ids = new Array();
  28.  
  29.  
  30. for (var i = 0; i < divels.length; i++) {
  31. var author_link = divels[i].querySelector('p.tagline>a.author,p.tagline>span.author,p.tagline>em');
  32. // p.tagline>a.author is normal comment;
  33. // some author deleted comments seem to have either
  34. // p.tagline>span.author or p.tagline>em
  35. comment_ids[i] = divels[i].parentElement.parentElement.getAttribute('data-fullname');
  36. if(author_link) {
  37. // create link DOM element
  38. nuke_button[i] = document.createElement('a')
  39. nuke_button[i].setAttribute('href', 'javascript:void(0)');
  40. nuke_button[i].setAttribute('title', 'Nuke!');
  41. nuke_button[i].setAttribute('id', 'nuke_'+i);
  42. nuke_button[i].innerHTML= "[<strong>Nuke</strong>]";
  43. // append after the author's name
  44. author_link.parentNode.insertBefore(nuke_button[i], author_link.nextSibling);
  45.  
  46. // Add listener for click; using IIFE to function with _i as value of i when created; not when clicked
  47. nuke_button[i].addEventListener('click',
  48. (function(_i) {
  49. return function() {
  50. var continue_thread = divels[_i].parentElement.parentElement.querySelectorAll('span.morecomments>a');
  51. var comment_str = " comments?";
  52. if(continue_thread.length > 0) {
  53. comment_str = "+ comments (more after expanding collapsed threads; there will be a pause before the first deletion to retrieve more comments)?";
  54. }
  55. var delete_button = divels[_i].parentElement.parentElement.querySelectorAll('form input[value="removed"]~span.option.error a.yes,a[onclick^="return big_mod_action($(this), -1)"]');
  56. // form input[value="removed"]~span.option.error a.yes -- finds the yes for normal deleting comments.
  57. // a.pretty-button.neutral finds the 'remove' button for flagged comments
  58. if (confirm("Are you sure you want to nuke the following " + delete_button.length + comment_str)) {
  59. for (var indx=0; indx < continue_thread.length; indx++) {
  60. var elmnt = continue_thread[indx];
  61. setTimeout(
  62. function() {
  63. var event = document.createEvent('UIEvents');
  64. event.initUIEvent('click', true, true, window, 1);
  65. elmnt.dispatchEvent(event);
  66. }, 2000*indx); // wait two seconds before each ajax call before clicking each "load more comments"
  67. }
  68. if(indx > 0) {
  69. setTimeout(function() {delete_function(comment_ids[_i])},
  70. 2000*(indx + 2)); // wait 4s after last ajax "load more comments"
  71. } else {
  72. delete_function(comment_ids[_i]); // call immediately if not "load more comments"
  73. }
  74. }
  75. }
  76. }
  77. )(i)); // end of IIFE (immediately invoked function expression)
  78. }
  79. }
  80. }