RaaW2

Reddit as a Weapon script. Parts and idea by /u/noeatnosleep, enhanced by /u/enim

目前为 2014-08-13 提交的版本,查看 最新版本

此脚本不应直接安装,它是供其他脚本使用的外部库。如果你需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/4195/13278/RaaW2.js

  1. // ==UserScript==
  2. // @name RaaW2
  3. // @version 1.0
  4. // @namespace RaaW2
  5. // @description Reddit as a Weapon script. Parts and idea by /u/noeatnosleep, enhanced by /u/enim
  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='#'>DOWNVOTER</a> | <a id='upvoteComment' style='color:black;' href='#'>UPVOTER</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 COMMENTS</a> ";
  58. }
  59. if (parsedPage[3] == 'user'){
  60. newToolbar.innerHTML += "<a id='upvoteAndOpen' style='color:black;' href='#'> | UPVOTE AND OPEN </a> <a id='downvoteAndOpen' style='color:black;' href='#'> | DOWNVOTE AND OPEN </a> <a id='reportUserToSpam' style='color:black;' href='#'> | REPORT ON /R/SPAM </a> <a id='analyze' style='color:black;' href='#'> | analyze </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').on('click',function(e){
  78. clickYourUpvotes();
  79. });
  80. $('#downvoteAndOpen').on('click',function(e){
  81. clickYourDownvotes();
  82. });
  83. $('#reportUserToSpam').on('click',function(e){
  84. reportToSpam();
  85. });
  86. $('#analyze').on('click',function(e){
  87. analyze();
  88. });
  89. }
  90.  
  91. function buildReportArray() {
  92. if (commentPage.length == 0) {
  93. var threads;
  94. threads = $('#siteTable').find('.thing');
  95. for (i = 0; i < threads.length; i++) {
  96. reportID.push(threads[i].getAttribute('data-fullname'));
  97. }
  98. }
  99. else if (commentPage.length != 0) {
  100. var threads;
  101. threads = $('.commentarea').find('.thing');
  102. for (i = 0; i < threads.length; i++) {
  103. reportID.push(threads[i].getAttribute('data-fullname'));
  104. }
  105. }
  106. }
  107.  
  108. function reportItem(index, num) {
  109. if(num == 3) {var fullname = topicIDs[index];}
  110. else{var fullname = commentIDs[index];}
  111. $.post('http://www.reddit.com/api/report', {'id': fullname, 'uh': modHash});
  112. }
  113.  
  114.  
  115. function theDownvoter() {
  116. if (parsedPage[3] == 'user'){
  117. var items = $('#siteTable').find('.arrow.down');
  118. Array.prototype.forEach.call(items, function(el, i){
  119. setTimeout(function(){
  120. el.click();
  121. },100 + ( i * 400 ));
  122. });
  123. return false;
  124. }
  125. else {
  126. if (commentPage.length == 0) {
  127. var items = $('#siteTable').find('.arrow.down');
  128. Array.prototype.forEach.call(items, function(el, i){
  129. setTimeout(function(){
  130. el.click();
  131. },100 + ( i * 400 ));
  132. });
  133. return false;
  134. }
  135. else {
  136. var items = $('.commentarea').find('.arrow.down');
  137. Array.prototype.forEach.call(items, function(el, i){
  138. setTimeout(function(){
  139. el.click();
  140. },100 + ( i * 400 ));
  141. });
  142. return false;
  143. }
  144. }
  145. }
  146.  
  147. function theUpvoter() {
  148. if (parsedPage[3] == 'user'){
  149. var items = $('#siteTable').find('.arrow.up');
  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. if (commentPage.length == 0) {
  159. var items = $('#siteTable').find('.arrow.up');
  160. Array.prototype.forEach.call(items, function(el, i){
  161. setTimeout(function(){
  162. el.click();
  163. },100 + ( i * 400 ));
  164. });
  165. return false;
  166. }
  167. else {
  168. var items = $('.commentarea').find('.arrow.up');
  169. Array.prototype.forEach.call(items, function(el, i){
  170. setTimeout(function(){
  171. el.click();
  172. },100 + ( i * 400 ));
  173. });
  174. return false;
  175. }
  176. }
  177. }
  178.  
  179. function clickYourUpvotes() {
  180. var clickandupvote = [];
  181. $('#siteTable').find('.flat-list.buttons').find('.first').find('a.comments, a.bylink').each(function(index,value){
  182. clickandupvote.push($(this).attr('href'));
  183. });
  184. for (i=0;i < clickandupvote.length;i++){
  185. window.open(clickandupvote[i]);
  186. }
  187. var items = $('#siteTable').find('.arrow.up');
  188. Array.prototype.forEach.call(items, function(el, i){
  189. setTimeout(function(){
  190. el.click();
  191. },100 + ( i * 400 ));
  192. });
  193. return false;
  194. }
  195.  
  196. function clickYourDownvotes() {
  197. var clickandupvote = [];
  198. $('#siteTable').find('.flat-list.buttons').find('.first').find('a.comments, a.bylink').each(function(index,value){
  199. clickandupvote.push($(this).attr('href'));
  200. });
  201. for (i=0;i < clickandupvote.length;i++){
  202. window.open(clickandupvote[i]);
  203. }
  204. var items = $('#siteTable').find('.arrow.down');
  205. Array.prototype.forEach.call(items, function(el, i){
  206. setTimeout(function(){
  207. el.click();
  208. },100 + ( i * 400 ));
  209. });
  210. return false;
  211. }
  212. function reportToSpam(){
  213. var username = $(document).find('.pagename.selected').text();
  214. window.open('http://www.reddit.com/r/spam/submit?title=overview for '+ username + '&url=http://www.reddit.com/user/' + username );
  215. }
  216.  
  217. function analyze(){
  218. var username = $(document).find('.pagename.selected').text();
  219. window.open('http://www.reddit.com/message/compose/?to=analyzereddit&subject=analyze&message= for '+ username );
  220. }
  221.  
  222. generateToolbar(), getHash(),buildReportArray(), doStuff();