RaaW

Reddit as a Weapon script. Parts and idea by /u/noeatnosleep, enhanced by /u/enim, /u/creesch, and /u/djimbob. RaaW adds links for page-wide voting and reporting. It adds a 'report to /r/spam' link, an 'analyze user submission domains' link, and a 'report to /r/botwatchman' link to userpages. RaaW disables the np. domain. RaaW Adds a 'show source' button for comments. DISCLIAMER: USE THIS AT YOUR OWN RISK. IF MISUSED, IT WILL LEAD TO YOUR ACCOUNT BEING SHADOWBANNED QUICKLY!

当前为 2014-09-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RaaW
  3. // @version 2.4.1
  4. // @namespace RaaW
  5. // @description Reddit as a Weapon script. Parts and idea by /u/noeatnosleep, enhanced by /u/enim, /u/creesch, and /u/djimbob. RaaW adds links for page-wide voting and reporting. It adds a 'report to /r/spam' link, an 'analyze user submission domains' link, and a 'report to /r/botwatchman' link to userpages. RaaW disables the np. domain. RaaW Adds a 'show source' button for comments. DISCLIAMER: USE THIS AT YOUR OWN RISK. IF MISUSED, IT WILL LEAD TO YOUR ACCOUNT BEING SHADOWBANNED QUICKLY!
  6. // @include http://www.reddit.com/user/*
  7. // @include http://www.reddit.com/r/*
  8. // @include http://*reddit.com/*
  9. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. this.$ = this.jQuery = jQuery.noConflict(true);
  13.  
  14. var currentPage = document.URL;
  15. var parsedPage = currentPage.split('/');
  16. var modHash = null;
  17. var currentUser = null;
  18. var subreddit = null;
  19. var commentIDs = [];
  20. var topicIDs = [];
  21. var subredditList = [];
  22. var reportID = [];
  23.  
  24. var commentPage;
  25. commentPage = document.getElementsByClassName('comment');
  26.  
  27. function getHash(callback) {
  28. var query = new XMLHttpRequest();
  29. query.onreadystatechange = function () {
  30. if (query.readyState == 4) {
  31. var info = JSON.parse(query.responseText);
  32. modHash = info.data.modhash;
  33. callback();
  34. }
  35. }
  36. query.open('GET', 'http://www.reddit.com/api/me.json', true);
  37. query.send(null);
  38. }
  39.  
  40. function generateToolbar () {
  41. $(document).find('#header')[0].style.paddingTop='18px';
  42. var newToolbar = document.createElement("div");
  43. newToolbar.id = "newToolbar";
  44. document.body.insertBefore(newToolbar,document.body.firstChild);
  45. var subredditbar = document.getElementById('sr-header-area');
  46. newToolbar.style.cssText="color:black;background-color:'#f0f0f0';border-bottom:1px black solid;font-family:verdana, arial, helvetica, sans-serif;font-size:90%;height:12px;padding:3px 0px 3px 6px;text-transform:uppercase;width:100%;z-index:+999999;position:fixed;top:0;";
  47. newToolbar.style.backgroundColor='#f0f0f0';
  48. newToolbar.style.paddingLeft = '6px';
  49. newToolbar.style.paddingTop = '3px';
  50. newToolbar.style.paddingBottom = '3px';
  51. newToolbar.style.top='0px';
  52. newToolbar.innerHTML += "<a id='downvoteComment' style='color:black;' href='#'>DOWNVOTE ALL</a> | <a id='upvoteComment' style='color:black;' href='#'>UPVOTE ALL</a> |";
  53. if (commentPage.length == 0) {
  54. newToolbar.innerHTML += " <a id=reportComment style='color:black;' href='#'>REPORT POSTS</a> ";
  55. }
  56. else {
  57. newToolbar.innerHTML += "<a id=reportComment style='color:black;' href='#'> REPORT ALL</a> ";
  58. }
  59. if (parsedPage[3] == 'user'){
  60. newToolbar.innerHTML += "<a id='botwatchmanSend' style='color:black;' href='#'> | BOTWATCHMAN </a> <a id='analyzeSend' style='color:black;' href='#'> | ANALYZE </a> <a id='reportUserToSpam' style='color:black;' href='#'> | REPORT ON /R/SPAM </a>";
  61. }
  62.  
  63. }
  64.  
  65.  
  66. function doStuff() {
  67. $('#reportComment').on('click',function(e) {
  68. for(var i = 0; i < reportID.length; i++) {reportItem(i, 3);}
  69. alert('All items on this page were reported.');
  70. });
  71. $('#downvoteComment').on('click',function(e){
  72. theDownvoter();
  73. });
  74. $('#upvoteComment').on('click',function(e){
  75. theUpvoter();
  76. });
  77. $('#reportUserToSpam').on('click',function(e){
  78. reportToSpam();
  79. });
  80. $('#analyzeSend').on('click',function(e){
  81. analyzeSend();
  82. });
  83. $('#botwatchmanSend').on('click',function(e){
  84. botwatchmanSend();
  85. });
  86. }
  87.  
  88. function buildReportArray() {
  89. if (commentPage.length == 0) {
  90. var threads;
  91. threads = $('#siteTable').find('.thing');
  92. for (i = 0; i < threads.length; i++) {
  93. reportID.push(threads[i].getAttribute('data-fullname'));
  94. }
  95. }
  96. else if (commentPage.length != 0) {
  97. var threads;
  98. threads = $('.commentarea').find('.thing');
  99. for (i = 0; i < threads.length; i++) {
  100. reportID.push(threads[i].getAttribute('data-fullname'));
  101. }
  102. }
  103. }
  104.  
  105. function reportItem(index, num) {
  106. if(num == 3) {var fullname = topicIDs[index];}
  107. else{var fullname = commentIDs[index];}
  108. $.post('http://www.reddit.com/api/report', {'id': fullname, 'uh': modHash});
  109. }
  110.  
  111.  
  112. function theDownvoter() {
  113. if (parsedPage[3] == 'user'){
  114. var items = $('#siteTable').find('.arrow.down');
  115. Array.prototype.forEach.call(items, function(el, i){
  116. setTimeout(function(){
  117. el.click();
  118. },100 + ( i * 400 ));
  119. });
  120. return false;
  121. }
  122. else {
  123. if (commentPage.length == 0) {
  124. var items = $('#siteTable').find('.arrow.down');
  125. Array.prototype.forEach.call(items, function(el, i){
  126. setTimeout(function(){
  127. el.click();
  128. },100 + ( i * 400 ));
  129. });
  130. return false;
  131. }
  132. else {
  133. var items = $('.commentarea').find('.arrow.down');
  134. Array.prototype.forEach.call(items, function(el, i){
  135. setTimeout(function(){
  136. el.click();
  137. },100 + ( i * 400 ));
  138. });
  139. return false;
  140. }
  141. }
  142. }
  143.  
  144. function theUpvoter() {
  145. if (parsedPage[3] == 'user'){
  146. var items = $('#siteTable').find('.arrow.up');
  147. Array.prototype.forEach.call(items, function(el, i){
  148. setTimeout(function(){
  149. el.click();
  150. },100 + ( i * 400 ));
  151. });
  152. return false;
  153. }
  154. else {
  155. if (commentPage.length == 0) {
  156. var items = $('#siteTable').find('.arrow.up');
  157. Array.prototype.forEach.call(items, function(el, i){
  158. setTimeout(function(){
  159. el.click();
  160. },100 + ( i * 400 ));
  161. });
  162. return false;
  163. }
  164. else {
  165. var items = $('.commentarea').find('.arrow.up');
  166. Array.prototype.forEach.call(items, function(el, i){
  167. setTimeout(function(){
  168. el.click();
  169. },100 + ( i * 400 ));
  170. });
  171. return false;
  172. }
  173. }
  174. }
  175.  
  176. function reportToSpam(){
  177. var username = $(document).find('.pagename.selected').text();
  178. window.open('http://www.reddit.com/r/spam/submit?title=overview for '+ username + '&resubmit=true&url=http://www.reddit.com/user/' + username + "?");
  179. }
  180.  
  181. function analyzeSend(){
  182. var username = $(document).find('.pagename.selected').text();
  183. window.open('http://www.reddit.com/message/compose/?to=analyzereddit&subject=analyze&message='+ username);
  184. }
  185.  
  186. function botwatchmanSend(){
  187. var username = $(document).find('.pagename.selected').text();
  188. window.open('http://www.reddit.com/r/botwatchman/submit?title=overview for '+ username + '&resubmit=true&url=http://www.reddit.com/user/' + username + "?");
  189. }
  190.  
  191. if (document.documentElement.lang === 'np') {
  192. document.documentElement.lang = 'en-us';
  193. }
  194.  
  195. //disable .np
  196.  
  197. document.body.classList.add('subscriber');
  198.  
  199. delete_function = function(thread_root) {
  200. 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)"]');
  201. for(var i=0; i < elmnts.length; i++) {
  202. setTimeout(
  203. (function(_elmnt) {
  204. return function() {
  205. var event = document.createEvent('UIEvents');
  206. event.initUIEvent('click', true, true, window, 1);
  207. _elmnt.dispatchEvent(event);
  208. }}
  209. )(elmnts[i]), 1500*i); // 1.5s timeout prevents overloading reddit.
  210. };
  211. }
  212.  
  213. //source reveal (creesch)
  214.  
  215. $('.comments-page .comment .flat-list.buttons').each(function () { // this targets each flat-list belonging to comments on a comment page.
  216. $(this).append('<li><a class="view-source" href="javascript:void(0)">view source</a></li>'); // it then adds the view source button in the belonging function
  217. });
  218.  
  219. $('body').on('click', '.view-source', function () { // On clicking of the view source button we do what we want to do. Note that we start with body since that is a constant dom element. If you try to target added dom elements directly it will not work.
  220. var $this = $(this), // We posisbly want to reuse $(this), it is cleaner to define jquery objects you want to reuse.
  221. $parentThing = $this.closest('.thing'),
  222. thingId = $parentThing.attr('data-fullname'); // we need an id to throw at the api, luckily it is is present in the html.
  223. if($parentThing.find('#box-' + thingId).length) { // Lets see if we already did do this before.
  224. $parentThing.find('#box-' + thingId).toggle(); // we did, toggle
  225. } else { // we did not, grab the info.
  226. $.getJSON('/api/info.json?id=' + thingId, function () { // lets do an ajax call to grab the info we need.
  227. console.log("success"); // you can remove this, basically lets you know a json call is done.
  228. })
  229. .done(function (data) { // by doing the stuff we need to do in .done we make sure we have the data needed since ajax is async.
  230. var commentBody = data.data.children[0].data.body; // json is basically an object.
  231. var commentSourceBox = '<textarea style="display:block" rows="10" cols="50">'+ commentBody + '</textarea>'; // build the source box.
  232. $parentThing.find('.flat-list').first().before(commentSourceBox); // and add it to the .thing, note that I use .first() if I didn't do that it would add the source box for all child comments as well.
  233. });
  234. }
  235. });
  236.  
  237.  
  238. //nuke (djimbob)
  239. delete_function = function(thread_root) {
  240. 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)"]');
  241. for(var i=0; i < elmnts.length; i++) {
  242. setTimeout(
  243. (function(_elmnt) {
  244. return function() {
  245. var event = document.createEvent('UIEvents');
  246. event.initUIEvent('click', true, true, window, 1);
  247. _elmnt.dispatchEvent(event);
  248. }}
  249. )(elmnts[i]), 1500*i); // 1.5s timeout prevents overloading reddit.
  250. };
  251. }
  252. if(document.querySelector('body.moderator')){ // only execute if you are a moderator
  253. var nuke_button = new Array();
  254. var divels = document.querySelectorAll('div.noncollapsed');
  255. var comment_ids = new Array();
  256. var use_image = false;
  257. // create img DOM element to clone
  258. if(use_image) {
  259. try {
  260. var img_element = document.createElement('img');
  261. img_element.setAttribute('alt', 'Nuke!');
  262. img_element.setAttribute('src', chrome.extension.getURL('nuke.png'));
  263. } catch(e) {
  264. use_image = false;
  265. }
  266. }
  267. for (var i = 0; i < divels.length; i++) {
  268. var author_link = divels[i].querySelector('p.tagline>a.author,p.tagline>span.author,p.tagline>em');
  269. // p.tagline>a.author is normal comment;
  270. // some author deleted comments seem to have either
  271. // p.tagline>span.author or p.tagline>em
  272. comment_ids[i] = divels[i].getAttribute('data-fullname');
  273. // console.log(i + ':' + comment_ids);
  274. if(author_link) {
  275. // create link DOM element with img inside link
  276. nuke_button[i] = document.createElement('a')
  277. nuke_button[i].setAttribute('href', 'javascript:void(0)');
  278. nuke_button[i].setAttribute('title', 'Nuke!');
  279. nuke_button[i].setAttribute('id', 'nuke_'+i);
  280. if(use_image) {
  281. nuke_button[i].appendChild(img_element.cloneNode(true));
  282. } else {
  283. nuke_button[i].innerHTML= "[Nuke]";
  284. }
  285. // append after the author's name
  286. author_link.parentNode.insertBefore(nuke_button[i], author_link.nextSibling);
  287. // Add listener for click; using IIFE to function with _i as value of i when created; not when click
  288. nuke_button[i].addEventListener('click',
  289. (function(_i) {
  290. return function() {
  291. var continue_thread = divels[_i].querySelectorAll('span.morecomments>a');
  292. var comment_str = " comments?";
  293. if(continue_thread.length > 0) {
  294. comment_str = "+ comments (more after expanding collapsed threads; there will be a pause before the first deletion to retrieve more comments)?";
  295. }
  296. var delete_button = divels[_i].querySelectorAll('form input[value="removed"]~span.option.error a.yes,a[onclick^="return big_mod_action($(this), -1)"]');
  297. // form input[value="removed"]~span.option.error a.yes -- finds the yes for normal deleting comments.
  298. // a.pretty-button.neutral finds the 'remove' button for flagged comments
  299. if (confirm("Are you sure you want to nuke the following " + delete_button.length + comment_str)) {
  300. for (var indx=0; indx < continue_thread.length; indx++) {
  301. var elmnt = continue_thread[indx];
  302. setTimeout(
  303. function() {
  304. var event = document.createEvent('UIEvents');
  305. event.initUIEvent('click', true, true, window, 1);
  306. elmnt.dispatchEvent(event);
  307. }, 2000*indx); // wait two seconds before each ajax call before clicking each "load more comments"
  308. }
  309. if(indx > 0) {
  310. setTimeout(function() {delete_function(comment_ids[_i])},
  311. 2000*(indx + 2)); // wait 4s after last ajax "load more comments"
  312. } else {
  313. delete_function(comment_ids[_i]); // call immediately if not "load more comments"
  314. }
  315. }
  316. }
  317. }
  318. )(i)); // end of IIFE (immediately invoked function expression)
  319. }
  320. }
  321. }
  322.  
  323. linkswapping
  324.  
  325. document.addEventListener("DOMContentLoaded", replaceLinks, false );
  326.  
  327. if( document.readyState === "complete" ) {
  328. replaceLinks();
  329. }
  330.  
  331. function replaceLinks() {
  332. Array.forEach( document.links, function(a) {
  333. a.href = a.href.replace( "(r|f)/mod/?$", "r/mod/about/unmoderated/");
  334. a.href = a.href.replace( "https?://(?i.)?imgur.com", "http://imgur.com");
  335. });
  336. }
  337.  
  338. generateToolbar(), getHash(),buildReportArray(), doStuff();