Guest User

Greasemonkey

a guest
May 22nd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.53 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Reddit Overwrite
  3. // @namespace Reddit
  4. // @description This script will overwrite your Reddit comment history. To use it, go to Reddit, log in, click on your username, then click on the comments tab, then click on the new OVERWRITE button. If you want to modify the message that is left over your comments, it is on line 88. This script works MUCH more efficiently if you use Reddit Enhancement Suite with the Never Ending Reddit feature enabled to scroll down to your oldest comments before hitting the button.
  5. // @include https://*.reddit.com/*
  6. // @include http://*.reddit.com/*
  7. // @version 1.3.9
  8. // @run-at document-start
  9. // ==/UserScript==
  10.  
  11.  
  12. unsafeWindow.to_delete = [];
  13. unsafeWindow.num_user_comments = 0;
  14. unsafeWindow.deleted = 0;
  15. unsafeWindow.span = '';
  16. unsafeWindow.user = '';
  17.  
  18.  
  19. unsafeWindow.delete_comment = function(thing_id, from_delete_all)
  20. {
  21. try{
  22. var thing = document.querySelector("input[name='thing_id'][value='" + thing_id + "']");
  23.  
  24.  
  25. var status = thing.parentNode.querySelector("div.usertext-edit > div.bottom-area > div.usertext-buttons > span.status").innerHTML;
  26.  
  27. var error = false;
  28. if ((status.indexOf("error") != -1) || (status.indexOf("submitting") != -1)){
  29. error = true;
  30. } else {
  31. // var del_form = thing.parentNode.parentNode.querySelector("ul.buttons > li > form.del-button");
  32. // unsafeWindow.toggle(del_form.querySelector("span.main > a"));
  33. // del_form.querySelector("span.error > a.yes").click();
  34. unsafeWindow.deleted++;
  35. }
  36.  
  37. if (from_delete_all){
  38. if (unsafeWindow.to_delete.length != 0)
  39. {
  40. unsafeWindow.span.innerHTML = "OVERWRITING COMMENT " + (unsafeWindow.deleted + 1) + " OF " + unsafeWindow.num_user_comments;
  41. var next_thing_id = unsafeWindow.to_delete.pop();
  42. unsafeWindow.setTimeout(unsafeWindow.overwrite_comment, 2000, next_thing_id, from_delete_all);
  43. }
  44. else
  45. {
  46. if (unsafeWindow.num_user_comments - unsafeWindow.deleted != 0){
  47. unsafeWindow.num_user_comments = unsafeWindow.num_user_comments - unsafeWindow.deleted;
  48. UpdateDeleteAllSpan();
  49. unsafeWindow.span.innerHTML = "<span>Failed to overwrite " + unsafeWindow.num_user_comments + " comments</span><br>" + unsafeWindow.span.innerHTML;
  50. } else
  51. unsafeWindow.span.style.display = 'none';
  52.  
  53. }
  54. } else {
  55. if (error)
  56. alert("Failed to overwrite your comment. Overwrite aborted.");
  57. else
  58. unsafeWindow.num_user_comments--;
  59. UpdateDeleteAllSpan();
  60. }
  61. return (error ? -1 : 0);
  62. }catch(er){
  63. alert(er);
  64. if (from_delete_all) unsafeWindow.location.reload();
  65. return -99;
  66. }
  67. }
  68.  
  69. unsafeWindow.overwrite_comment = function(thing_id, from_delete_all)
  70. {
  71. try{
  72. var edit_form = document.querySelector("input[name='thing_id'][value='" + thing_id + "']").parentNode;
  73.  
  74. edit_form.querySelector("div.usertext-edit > div.bottom-area > div.usertext-buttons > button.cancel").click();
  75.  
  76.  
  77. var edit_btn = edit_form.parentNode.querySelector("ul > li > a.edit-usertext");
  78. if (edit_btn) edit_btn.click();
  79. var edit_textbox = edit_form.querySelector("div.usertext-edit > div > textarea");
  80. var repl_str = '';
  81. var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz><.-,+!#$%^&*();:[]~";
  82. // for(var x = 0; x < edit_textbox.value.length; x++){
  83. // if (edit_textbox.value.substr(x,1) == '\n'){
  84. // repl_str += '\n';
  85. // }else{
  86. // var rnum = Math.floor(Math.random() * chars.length);
  87. // repl_str += chars.charAt(rnum, 1);
  88. // }
  89. // }
  90. edit_textbox.value = "This comment has been overwritten by an open source script to protect this user&apos;s privacy. It was created to help protect users from doxing, stalking, and harassment. \n\n If you would also like to protect yourself, add the Chrome extension [TamperMonkey](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo), or the Firefox extension [GreaseMonkey](https://addons.mozilla.org/en-us/firefox/addon/greasemonkey/) and add [this open source script](https://greasyfork.org/en/scripts/10380-reddit-overwrite). \n\n Then simply click on your username on Reddit, go to the comments tab, scroll down as far as possibe (hint:use [RES](http://www.redditenhancementsuite.com/)), and hit the new OVERWRITE button at the top.";
  91. edit_form.querySelector("div.usertext-edit > div.bottom-area > div.usertext-buttons > button.save").click();
  92. unsafeWindow.setTimeout(unsafeWindow.delete_comment, 2000, thing_id, from_delete_all);
  93. return 0;
  94. }catch(e){
  95. alert("Error interacting with overwrite form: " + e);
  96. return -99;
  97. }
  98. };
  99.  
  100.  
  101. unsafeWindow.delete_all = function()
  102. {
  103. try{
  104. unsafeWindow.num_user_comments = 0;
  105. unsafeWindow.deleted = 0;
  106. unsafeWindow.to_delete = [];
  107. var comments = document.querySelectorAll("a.author");
  108.  
  109. for (var i = 0; i < comments.length; i++)
  110. {
  111. if (comments[i].innerHTML != unsafeWindow.user) continue;
  112. var thing_id = comments[i].parentNode.parentNode.querySelector("form.usertext > input[name='thing_id']").value;
  113. if (unsafeWindow.to_delete.indexOf(thing_id) == -1){
  114. unsafeWindow.to_delete.push(thing_id);
  115. unsafeWindow.num_user_comments++;
  116. }
  117. }
  118.  
  119. unsafeWindow.span.innerHTML = "TRYING TO Overwrite COMMENT 1 OF " + unsafeWindow.num_user_comments;
  120. var next_thing_id = unsafeWindow.to_delete.pop();
  121. unsafeWindow.overwrite_comment(next_thing_id, true);
  122. } catch(e){
  123. alert("YOU ARE MOST LIKELY NOT ON THE COMMENTS TAB! /n/n Error trying to delete all your comments.\nError: " + e + " Stack:" + e.stack);
  124. unsafeWindow.location.reload()
  125. }
  126. };
  127.  
  128. function add_delete_links(ev)
  129. {
  130. unsafeWindow.user = document.querySelector("span.user > a:not(.login-required)").innerHTML;
  131. if (!unsafeWindow.user){return;}
  132. var comments = document.querySelectorAll("a.author");
  133. unsafeWindow.num_user_comments = 0;
  134. for (var i = 0; i < comments.length; i++)
  135. {
  136. if (comments[i].innerHTML != unsafeWindow.user) continue;
  137. try{
  138. var main_parent = comments[i].parentNode.parentNode;
  139. var thing_id = main_parent.querySelector("form > input[name='thing_id']").value;
  140. var list = main_parent.querySelector("ul.flat-list");
  141. if (list.querySelector("li.secure_delete")) continue;
  142. unsafeWindow.num_user_comments++;
  143.  
  144. var addedlink = document.createElement("li");
  145. addedlink.setAttribute('class', 'secure_delete');
  146. var dlink = document.createElement("a");
  147. dlink.setAttribute('class','bylink secure_delete');
  148. dlink.setAttribute('onClick','javascript:var ret = overwrite_comment("' + thing_id + '", false);');
  149. dlink.setAttribute('href', 'javascript:void(0)');
  150. // dlink.appendChild(document.createTextNode('SECURE DELETE'));
  151. addedlink.appendChild(dlink);
  152. main_parent.querySelector("ul.flat-list").appendChild(addedlink);
  153. }catch(e){}
  154. }
  155.  
  156. unsafeWindow.span = document.createElement("span");
  157. unsafeWindow.span.setAttribute('class', 'nextprev secure_delete_all');
  158. UpdateDeleteAllSpan();
  159.  
  160. }
  161.  
  162. function UpdateDeleteAllSpan()
  163. {
  164. if (unsafeWindow.num_user_comments){
  165. unsafeWindow.span.innerHTML = "";
  166. var dlink = document.createElement("a");
  167. dlink.setAttribute('class','bylink');
  168. dlink.setAttribute('onClick','javascript:return delete_all()');
  169. dlink.setAttribute('href', 'javascript:void(0)');
  170. dlink.appendChild(document.createTextNode('OVERWRITE ALL visible comment(s) on this page'));
  171. unsafeWindow.span.appendChild(dlink);
  172. document.querySelector("div.content").insertBefore(unsafeWindow.span,document.querySelector("div.content").firstChild);
  173. } else if (unsafeWindow.span != null) {
  174. unsafeWindow.span.style.display = 'none';
  175. }
  176. }
  177.  
  178. window.addEventListener("DOMContentLoaded",add_delete_links, false);
Add Comment
Please, Sign In to add comment