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-10-04 提交的版本,查看 最新版本

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