RaaW

Reddit as a Weapon script. Parts and idea by /u/noeatnosleep, enhanced by /u/enim, /u/creesch. Allows page-wide voting and reporting, report to spam link, and analize user submissions links. Disables np. domain, and 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.1.2
  4. // @namespace RaaW
  5. // @description Reddit as a Weapon script. Parts and idea by /u/noeatnosleep, enhanced by /u/enim, /u/creesch. Allows page-wide voting and reporting, report to spam link, and analize user submissions links. Disables np. domain, and 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='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. }
  112.  
  113. function buildReportArray() {
  114. if (commentPage.length == 0) {
  115. var threads;
  116. threads = $('#siteTable').find('.thing');
  117. for (i = 0; i < threads.length; i++) {
  118. reportID.push(threads[i].getAttribute('data-fullname'));
  119. }
  120. }
  121. else if (commentPage.length != 0) {
  122. var threads;
  123. threads = $('.commentarea').find('.thing');
  124. for (i = 0; i < threads.length; i++) {
  125. reportID.push(threads[i].getAttribute('data-fullname'));
  126. }
  127. }
  128. }
  129.  
  130. function reportItem(index, num) {
  131. if(num == 3) {var fullname = topicIDs[index];}
  132. else{var fullname = commentIDs[index];}
  133. $.post('http://www.reddit.com/api/report', {'id': fullname, 'uh': modHash});
  134. }
  135.  
  136.  
  137. function theDownvoter() {
  138. if (parsedPage[3] == 'user'){
  139. var items = $('#siteTable').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. else {
  148. if (commentPage.length == 0) {
  149. var items = $('#siteTable').find('.arrow.down');
  150. Array.prototype.forEach.call(items, function(el, i){
  151. setTimeout(function(){
  152. el.click();
  153. },100 + ( i * 400 ));
  154. });
  155. return false;
  156. }
  157. else {
  158. var items = $('.commentarea').find('.arrow.down');
  159. Array.prototype.forEach.call(items, function(el, i){
  160. setTimeout(function(){
  161. el.click();
  162. },100 + ( i * 400 ));
  163. });
  164. return false;
  165. }
  166. }
  167. }
  168.  
  169. function theUpvoter() {
  170. if (parsedPage[3] == 'user'){
  171. var items = $('#siteTable').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. else {
  180. if (commentPage.length == 0) {
  181. var items = $('#siteTable').find('.arrow.up');
  182. Array.prototype.forEach.call(items, function(el, i){
  183. setTimeout(function(){
  184. el.click();
  185. },100 + ( i * 400 ));
  186. });
  187. return false;
  188. }
  189. else {
  190. var items = $('.commentarea').find('.arrow.up');
  191. Array.prototype.forEach.call(items, function(el, i){
  192. setTimeout(function(){
  193. el.click();
  194. },100 + ( i * 400 ));
  195. });
  196. return false;
  197. }
  198. }
  199. }
  200.  
  201. function reportToSpam(){
  202. var username = $(document).find('.pagename.selected').text();
  203. window.open('http://www.reddit.com/r/spam/submit?title=overview for '+ username + '&resubmit=true&url=http://www.reddit.com/user/' + username + "?");
  204. }
  205.  
  206. function analyzeSend(){
  207. var username = $(document).find('.pagename.selected').text();
  208. window.open('http://www.reddit.com/message/compose/?to=analyzereddit&subject=analyze&message='+ username);
  209. }
  210.  
  211. if (document.documentElement.lang === 'np') {
  212. document.documentElement.lang = 'en-us';
  213. }
  214.  
  215. //disable .np
  216.  
  217. document.body.classList.add('subscriber');
  218.  
  219. delete_function = function(thread_root) {
  220. 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)"]');
  221. for(var i=0; i < elmnts.length; i++) {
  222. setTimeout(
  223. (function(_elmnt) {
  224. return function() {
  225. var event = document.createEvent('UIEvents');
  226. event.initUIEvent('click', true, true, window, 1);
  227. _elmnt.dispatchEvent(event);
  228. }}
  229. )(elmnts[i]), 1500*i); // 1.5s timeout prevents overloading reddit.
  230. };
  231. }
  232.  
  233. //source reveal (creesch)
  234.  
  235. $('.comments-page .comment .flat-list.buttons').each(function () { // this targets each flat-list belonging to comments on a comment page.
  236. $(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
  237. });
  238.  
  239. $('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.
  240. var $this = $(this), // We posisbly want to reuse $(this), it is cleaner to define jquery objects you want to reuse.
  241. $parentThing = $this.closest('.thing'),
  242. thingId = $parentThing.attr('data-fullname'); // we need an id to throw at the api, luckily it is is present in the html.
  243. if($parentThing.find('#box-' + thingId).length) { // Lets see if we already did do this before.
  244. $parentThing.find('#box-' + thingId).toggle(); // we did, toggle
  245. } else { // we did not, grab the info.
  246. $.getJSON('/api/info.json?id=' + thingId, function () { // lets do an ajax call to grab the info we need.
  247. console.log("success"); // you can remove this, basically lets you know a json call is done.
  248. })
  249. .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.
  250. var commentBody = data.data.children[0].data.body; // json is basically an object.
  251. var commentSourceBox = '<textarea style="display:block" rows="10" cols="50">'+ commentBody + '</textarea>'; // build the source box.
  252. $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.
  253. });
  254. }
  255. });
  256.  
  257. generateToolbar(), getHash(),buildReportArray(), doStuff();