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.3.5
  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. $('#upvoteAndOpen').click(function() {
  78. for(var i = 0; i < 25; i++) {
  79. upVote(i);
  80. var strippedTopic = topicIDs[i].split('_');
  81. var strippedComment = commentIDs[i].split('_');
  82. var url = 'http://www.reddit.com/r/' + subredditList[i] + '/comments/' + strippedTopic[1] + '/xml/' + strippedComment[1];
  83. window.open(url);
  84. }
  85. });
  86. $('#downvoteAndOpen').click(function() {
  87. for(var i = 0; i < 25; i++) {
  88. downVote(i);
  89. var strippedTopic = topicIDs[i].split('_');
  90. var strippedComment = commentIDs[i].split('_');
  91. var url = 'http://www.reddit.com/r/' + subredditList[i] + '/comments/' + strippedTopic[1] + '/xml/' + strippedComment[1];
  92. window.open(url);
  93. }
  94. });
  95. $('#netralvoteAndOpen').click(function() {
  96. for(var i = 0; i < 25; i++) {
  97. neutralVote(i);
  98. var strippedTopic = topicIDs[i].split('_');
  99. var strippedComment = commentIDs[i].split('_');
  100. var url = 'http://www.reddit.com/r/' + subredditList[i] + '/comments/' + strippedTopic[1] + '/xml/' + strippedComment[1];
  101. window.open(url);
  102. }
  103.  
  104. });
  105. $('#reportUserToSpam').on('click',function(e){
  106. reportToSpam();
  107. });
  108. $('#analyzeSend').on('click',function(e){
  109. analyzeSend();
  110. });
  111. $('#botwatchmanSend').on('click',function(e){
  112. botwatchmanSend();
  113. });
  114. }
  115.  
  116. function buildReportArray() {
  117. if (commentPage.length == 0) {
  118. var threads;
  119. threads = $('#siteTable').find('.thing');
  120. for (i = 0; i < threads.length; i++) {
  121. reportID.push(threads[i].getAttribute('data-fullname'));
  122. }
  123. }
  124. else if (commentPage.length != 0) {
  125. var threads;
  126. threads = $('.commentarea').find('.thing');
  127. for (i = 0; i < threads.length; i++) {
  128. reportID.push(threads[i].getAttribute('data-fullname'));
  129. }
  130. }
  131. }
  132.  
  133. function reportItem(index, num) {
  134. if(num == 3) {var fullname = topicIDs[index];}
  135. else{var fullname = commentIDs[index];}
  136. $.post('http://www.reddit.com/api/report', {'id': fullname, 'uh': modHash});
  137. }
  138.  
  139.  
  140. function theDownvoter() {
  141. if (parsedPage[3] == 'user'){
  142. var items = $('#siteTable').find('.arrow.down');
  143. Array.prototype.forEach.call(items, function(el, i){
  144. setTimeout(function(){
  145. el.click();
  146. },100 + ( i * 400 ));
  147. });
  148. return false;
  149. }
  150. else {
  151. if (commentPage.length == 0) {
  152. var items = $('#siteTable').find('.arrow.down');
  153. Array.prototype.forEach.call(items, function(el, i){
  154. setTimeout(function(){
  155. el.click();
  156. },100 + ( i * 400 ));
  157. });
  158. return false;
  159. }
  160. else {
  161. var items = $('.commentarea').find('.arrow.down');
  162. Array.prototype.forEach.call(items, function(el, i){
  163. setTimeout(function(){
  164. el.click();
  165. },100 + ( i * 400 ));
  166. });
  167. return false;
  168. }
  169. }
  170. }
  171.  
  172. function theUpvoter() {
  173. if (parsedPage[3] == 'user'){
  174. var items = $('#siteTable').find('.arrow.up');
  175. Array.prototype.forEach.call(items, function(el, i){
  176. setTimeout(function(){
  177. el.click();
  178. },100 + ( i * 400 ));
  179. });
  180. return false;
  181. }
  182. else {
  183. if (commentPage.length == 0) {
  184. var items = $('#siteTable').find('.arrow.up');
  185. Array.prototype.forEach.call(items, function(el, i){
  186. setTimeout(function(){
  187. el.click();
  188. },100 + ( i * 400 ));
  189. });
  190. return false;
  191. }
  192. else {
  193. var items = $('.commentarea').find('.arrow.up');
  194. Array.prototype.forEach.call(items, function(el, i){
  195. setTimeout(function(){
  196. el.click();
  197. },100 + ( i * 400 ));
  198. });
  199. return false;
  200. }
  201. }
  202. }
  203.  
  204. function reportToSpam(){
  205. var username = $(document).find('.pagename.selected').text();
  206. window.open('http://www.reddit.com/r/spam/submit?title=overview for '+ username + '&resubmit=true&url=http://www.reddit.com/user/' + username + "?");
  207. }
  208.  
  209. function analyzeSend(){
  210. var username = $(document).find('.pagename.selected').text();
  211. window.open('http://www.reddit.com/message/compose/?to=analyzereddit&subject=analyze&message='+ username);
  212. }
  213.  
  214. function botwatchmanSend(){
  215. var username = $(document).find('.pagename.selected').text();
  216. window.open('http://www.reddit.com/r/botwatchman/submit?title=overview for '+ username + '&resubmit=true&url=http://www.reddit.com/user/' + username + "?");
  217. }
  218.  
  219. if (document.documentElement.lang === 'np') {
  220. document.documentElement.lang = 'en-us';
  221. }
  222.  
  223. //disable .np
  224.  
  225. document.body.classList.add('subscriber');
  226.  
  227. delete_function = function(thread_root) {
  228. 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)"]');
  229. for(var i=0; i < elmnts.length; i++) {
  230. setTimeout(
  231. (function(_elmnt) {
  232. return function() {
  233. var event = document.createEvent('UIEvents');
  234. event.initUIEvent('click', true, true, window, 1);
  235. _elmnt.dispatchEvent(event);
  236. }}
  237. )(elmnts[i]), 1500*i); // 1.5s timeout prevents overloading reddit.
  238. };
  239. }
  240.  
  241. //source reveal (creesch)
  242.  
  243. $('.comments-page .comment .flat-list.buttons').each(function () { // this targets each flat-list belonging to comments on a comment page.
  244. $(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
  245. });
  246.  
  247. $('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.
  248. var $this = $(this), // We posisbly want to reuse $(this), it is cleaner to define jquery objects you want to reuse.
  249. $parentThing = $this.closest('.thing'),
  250. thingId = $parentThing.attr('data-fullname'); // we need an id to throw at the api, luckily it is is present in the html.
  251. if($parentThing.find('#box-' + thingId).length) { // Lets see if we already did do this before.
  252. $parentThing.find('#box-' + thingId).toggle(); // we did, toggle
  253. } else { // we did not, grab the info.
  254. $.getJSON('/api/info.json?id=' + thingId, function () { // lets do an ajax call to grab the info we need.
  255. console.log("success"); // you can remove this, basically lets you know a json call is done.
  256. })
  257. .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.
  258. var commentBody = data.data.children[0].data.body; // json is basically an object.
  259. var commentSourceBox = '<textarea style="display:block" rows="10" cols="50">'+ commentBody + '</textarea>'; // build the source box.
  260. $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.
  261. });
  262. }
  263. });
  264.  
  265.  
  266. //nuke (djimbob)
  267. delete_function = function(thread_root) {
  268. 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)"]');
  269. for(var i=0; i < elmnts.length; i++) {
  270. setTimeout(
  271. (function(_elmnt) {
  272. return function() {
  273. var event = document.createEvent('UIEvents');
  274. event.initUIEvent('click', true, true, window, 1);
  275. _elmnt.dispatchEvent(event);
  276. }}
  277. )(elmnts[i]), 1500*i); // 1.5s timeout prevents overloading reddit.
  278. };
  279. }
  280. if(document.querySelector('body.moderator')){ // only execute if you are a moderator
  281. var nuke_button = new Array();
  282. var divels = document.querySelectorAll('div.noncollapsed');
  283. var comment_ids = new Array();
  284. var use_image = false;
  285. // create img DOM element to clone
  286. if(use_image) {
  287. try {
  288. var img_element = document.createElement('img');
  289. img_element.setAttribute('alt', 'Nuke!');
  290. img_element.setAttribute('src', chrome.extension.getURL('nuke.png'));
  291. } catch(e) {
  292. use_image = false;
  293. }
  294. }
  295. for (var i = 0; i < divels.length; i++) {
  296. var author_link = divels[i].querySelector('p.tagline>a.author,p.tagline>span.author,p.tagline>em');
  297. // p.tagline>a.author is normal comment;
  298. // some author deleted comments seem to have either
  299. // p.tagline>span.author or p.tagline>em
  300. comment_ids[i] = divels[i].getAttribute('data-fullname');
  301. // console.log(i + ':' + comment_ids);
  302. if(author_link) {
  303. // create link DOM element with img inside link
  304. nuke_button[i] = document.createElement('a')
  305. nuke_button[i].setAttribute('href', 'javascript:void(0)');
  306. nuke_button[i].setAttribute('title', 'Nuke!');
  307. nuke_button[i].setAttribute('id', 'nuke_'+i);
  308. if(use_image) {
  309. nuke_button[i].appendChild(img_element.cloneNode(true));
  310. } else {
  311. nuke_button[i].innerHTML= "[Nuke]";
  312. }
  313. // append after the author's name
  314. author_link.parentNode.insertBefore(nuke_button[i], author_link.nextSibling);
  315. // Add listener for click; using IIFE to function with _i as value of i when created; not when click
  316. nuke_button[i].addEventListener('click',
  317. (function(_i) {
  318. return function() {
  319. var continue_thread = divels[_i].querySelectorAll('span.morecomments>a');
  320. var comment_str = " comments?";
  321. if(continue_thread.length > 0) {
  322. comment_str = "+ comments (more after expanding collapsed threads; there will be a pause before the first deletion to retrieve more comments)?";
  323. }
  324. var delete_button = divels[_i].querySelectorAll('form input[value="removed"]~span.option.error a.yes,a[onclick^="return big_mod_action($(this), -1)"]');
  325. // form input[value="removed"]~span.option.error a.yes -- finds the yes for normal deleting comments.
  326. // a.pretty-button.neutral finds the 'remove' button for flagged comments
  327. if (confirm("Are you sure you want to nuke the following " + delete_button.length + comment_str)) {
  328. for (var indx=0; indx < continue_thread.length; indx++) {
  329. var elmnt = continue_thread[indx];
  330. setTimeout(
  331. function() {
  332. var event = document.createEvent('UIEvents');
  333. event.initUIEvent('click', true, true, window, 1);
  334. elmnt.dispatchEvent(event);
  335. }, 2000*indx); // wait two seconds before each ajax call before clicking each "load more comments"
  336. }
  337. if(indx > 0) {
  338. setTimeout(function() {delete_function(comment_ids[_i])},
  339. 2000*(indx + 2)); // wait 4s after last ajax "load more comments"
  340. } else {
  341. delete_function(comment_ids[_i]); // call immediately if not "load more comments"
  342. }
  343. }
  344. }
  345. }
  346. )(i)); // end of IIFE (immediately invoked function expression)
  347. }
  348. }
  349. }
  350.  
  351. //queue linkswap
  352.  
  353. document.addEventListener("DOMContentLoaded", replaceLinks, false );
  354.  
  355. if( document.readyState === "complete" ) {
  356. replaceLinks();
  357. }
  358.  
  359. function replaceLinks() {
  360. Array.forEach( document.links, function(a) {
  361. a.href = a.href.replace( "r/mod", "r/mod/about/unmoderated/" );
  362. });
  363. }
  364. generateToolbar(), getHash(),buildReportArray(), doStuff();