teddlyK

Spaz's Reddit Delete (Tedpilled Edition)

Sep 25th, 2019
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Spaz's Reddit Delete (Tedpilled Edition)
  3. // @namespace   Reddit
  4. // @include     http*://*.reddit.com/user/*
  5. // @version     1
  6. // @description Replaces all VISIBLE comments with garbage text, then deletes the comment. Works with RES!
  7. // ==/UserScript==
  8.  
  9. RD = unsafeWindow.RedditDelete = {};
  10. RD.DELAY_SAVE   = 2 * 1000;
  11. RD.DELAY_DELETE = 3 * 1000;
  12. RD.chars      = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz><.-,+!@#$%^&*;:[]~';
  13. RD.started    = false;
  14.  
  15. function __getRNGString(maxLength) {
  16.   var rnum, repl_str = '';
  17.  
  18.   for (var x = 0; x < maxLength; x++){
  19.     rnum = Math.floor(Math.random() * RD.chars.length);
  20.     repl_str += RD.chars.charAt(rnum, 1);
  21.   }
  22.  
  23.   return repl_str;
  24. }
  25.  
  26. function _setupEnv() {
  27.   if (RD.started) return;
  28.  
  29.   RD.numDel       = 0;
  30.   RD.contentCtnr  = document.querySelector('div.content');
  31.   RD.infoBar      = document.createElement('span');
  32.   RD.userName     = document.querySelector('span.user > a:not(.login-required)').innerHTML;
  33.   RD.infoBar.setAttribute('class', 'nextprev');
  34.   RD.started      = true;
  35. }
  36.  
  37. function _setupUI() {
  38.   //Build DELETE-ALL Link
  39.   var delAllLink        = document.createElement('a');
  40.   delAllLink.innerHTML  = 'SECURE DELETE ALL COMMENTS';
  41.   delAllLink.onclick    = _promptDeleteAll;
  42.   delAllLink.style.cssText = "color: rgb(200, 0, 0); text-shadow: -1px 0px 6px rgba(0,0,0, 0.7);";
  43.  
  44.   //Add to infoBar!
  45.   RD.infoBar.appendChild(delAllLink);
  46.   RD.contentCtnr.insertBefore(RD.infoBar, RD.contentCtnr.firstChild);
  47. }
  48.  
  49. function _promptDeleteAll() {
  50.   var doDelete = confirm("Are you sure you want to delete all comments on the screen?\n\n"
  51.     + "ProTip: If you want to delete ALL, use RES and use 'Never Ending Reddit' feature to show ALL comments.");
  52.  
  53.   if (!doDelete) return;
  54.  
  55.   _deleteAll();
  56. }
  57.  
  58. function _deleteAll() {
  59.   var modalCntr = RD.modalCntr = document.createElement('div');
  60.   var modalMsg  = RD.modalMsg  = document.createElement('div');
  61.   var cancelBtn  = document.createElement('button');
  62.   modalCntr.style.cssText = ''
  63.    + 'position: fixed; top: 0; left: 0; right: 0; bottom: 0;'
  64.    + 'height: 100%; width: 100%; background: rgba(0,0,0,0.8);'
  65.  
  66.   modalMsg.style.cssText = ''
  67.    + 'position: absolute; font-size: 32px; transform: translateX(-50%); top: 50%; left: 50%;'
  68.  
  69.   cancelBtn.style.cssText = ''
  70.    + 'position: absolute; font-size: 22px;'
  71.    + 'transform: translateX(-50%); top: 63%; left: 50%;'
  72.  
  73.   cancelBtn.innerHTML = "Cancel";
  74.   cancelBtn.onclick = function() {
  75.     RD.modalMsg.innerHTML = "Cancelling..."
  76.     RD.numDel = RD.comments.length;
  77.   }
  78.  
  79.   RD.comments = __getVisibleComments();
  80.   RD.numDel     = 0;
  81.  
  82.   modalCntr.appendChild(modalMsg);
  83.   modalCntr.appendChild(cancelBtn);
  84.   document.body.appendChild(modalCntr);
  85.  
  86.   __deleteCommentIndex(0);
  87. }
  88.  
  89. function __getVisibleComments() {
  90.   var foundComments = [];
  91.  
  92.   var entries     = RD.contentCtnr.querySelectorAll('.entry.likes');
  93.   var entry       = null;
  94.   var entryAuthor = '';
  95.  
  96.   for (var idx = 0; idx < entries.length; idx++) {
  97.     entry = entries[idx];
  98.     entryAuthor = entry.querySelector('.author');
  99.  
  100.     if (!entryAuthor || entryAuthor.innerHTML !== RD.userName) continue;
  101.  
  102.     foundComments.push(entry);
  103.   };
  104.  
  105.   return foundComments;
  106. }
  107.  
  108. function __deleteCommentIndex(idx) {
  109.   var comment = RD.comments[idx];
  110.  
  111.   __overwriteComment(comment, function(comment) {
  112.     __deleteComment(comment, function() {
  113.       var complete = RD.numDel >= RD.comments.length;
  114.       if (false === complete) {
  115.         RD.numDel++;
  116.         __deleteCommentIndex(RD.numDel);
  117.       } else {
  118.         window.location.reload();
  119.       }
  120.     });
  121.   });
  122. }
  123.  
  124. function __overwriteComment(comment, callback) {
  125.   var editLink = comment.querySelector('.edit-usertext');
  126.   var editText, newText, saveLink;
  127.  
  128.   RD.modalMsg.innerHTML = 'Overwriting ' + (RD.numDel + 1) + ' of ' + RD.comments.length + '...';
  129.  
  130.   if (!editLink) { if (callback) callback(comment); return; }
  131.  
  132.   //Enable editing...
  133.   editLink.click();
  134.   editText = comment.querySelector('textarea');
  135.   saveBtn = comment.querySelector('.usertext-buttons .save');
  136.  
  137.   //Replace Text with RNG string
  138.   newText         = __getRNGString(25);
  139.   editText.value  = "[The Industrial Revolution and it's consequences have been a disaster for the human race.](https://theanarchistlibrary.org/library/fc-industrial-society-and-its-future.pdf)" + "\n\n[Get this overwrite script](https://pastebin.com/fYJTPiYW)" + "\n\n^(" + newText + ")";
  140.  
  141.   //Do the save...
  142.   saveBtn.click();
  143.   setTimeout(function() { if (callback) callback(comment); }, RD.DELAY_SAVE);
  144. }
  145.  
  146. function __deleteComment(comment, callback) {
  147.   RD.modalMsg.innerHTML = 'Deleting ' + (RD.numDel + 1) + ' of ' + RD.comments.length + '...';
  148.  
  149.   var deleteLink = comment.querySelector('form.del-button .togglebutton')
  150.   var yesLink;
  151.  
  152.   //Enable deleting...
  153.   deleteLink.click();
  154.   yesLink = comment.querySelector('.option.error.active a.yes');
  155.  
  156.   if (!yesLink) { if (callback) callback(); return; }
  157.  
  158.   //Delay clicking YES so the user can see it
  159.   setTimeout(function() {
  160.     //Do the delete...
  161.     //yesLink.click();
  162.     setTimeout(function() { if (callback) callback(); }, RD.DELAY_DELETE);
  163.   }, 250);
  164. }
  165.  
  166. (function() {
  167.   _setupEnv();
  168.   _setupUI();
  169. })();
Add Comment
Please, Sign In to add comment