Advertisement
Guest User

voat cleaner

a guest
Feb 8th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. BEGIN INSTRUCTIONS                                  
  3. this is a phantomjs script. http://phantomjs.org/
  4. there are two scripts here. one deletes your submissions and one deletes your comments.
  5.  
  6. copy the first script into a file. call the file deletesubmissions.js
  7. copy the second script into a file. call the file deletecomments.js
  8. find phantomjs.exe and put it in the same directory as those two files.
  9.  
  10. change the username and password at the start of each script to be your username and password.
  11.  
  12. open a command line and type: phantomjs deletesubmissions.js to delete your submissions
  13. open a command line and type: phantomjs deletecomments.js to delete your comments
  14.  
  15. look for these two lines in deletesubmissions.js. there are corresponding lines in deletecomments.js.
  16. 1. navigate("#scp", getSubmissions);
  17. 2. //deleteFromSubmissionLinksFile();
  18. line one gets all the links to delete and saves them to a file.
  19. line two reads the list of links to delete out of the file. then it goes to that link and deletes your submission.
  20. so first run the script with line 2 commented out. then run it with line 1 commented out.
  21.  
  22. it will not work perfectly and you will probably have to run it a few times.
  23.  
  24. Feel free to improve, modify, and distribute these scripts.
  25. END INSTRUCTIONS
  26. */
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. var username = "YOURUSERNAME";
  41. var password = "YOURPASSWORD";
  42. //////////////////////////////////////////////////////
  43.  
  44. phantom.onError = function(msg, trace) {
  45.     var msgStack = ['PHANTOM ERROR: ' + msg];
  46.     if (trace && trace.length) {
  47.         msgStack.push('TRACE:');
  48.         trace.forEach(function(t) {
  49.             msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
  50.         });
  51.     }
  52.     console.error(msgStack.join('\n'))
  53. };
  54.  
  55. var page = require('webpage').create();
  56.  
  57.  
  58.  
  59. function click(selector) {
  60.     page.evaluate(function(selector) {
  61.         document.querySelector(selector).click();
  62.     }, selector);
  63. }
  64.  
  65. function navigate(selector, callback) {
  66.     page.onLoadFinished = function() {
  67.         page.onLoadFinished = null;
  68.         callback();
  69.     };
  70.     click(selector);
  71. }
  72.  
  73. function navigateByUrl(url, callback) {
  74.     page.onLoadFinished = function() {
  75.         page.onLoadFinished = null;
  76.         setTimeout(callback, 0);
  77.     };
  78.     page.evaluate(function(url) {
  79.         window.location.href = url;
  80.     }, url);
  81. }
  82.  
  83. var allLinks = [];
  84. var curPage = 0;
  85. function getSubmissions() {
  86.     function getLinks() {
  87.         curPage++;
  88.         console.log("getting links for page " + curPage);
  89.         var links = page.evaluate(function() {
  90.             var links = [];
  91.             var a = document.querySelectorAll(".submission a.comments");
  92.             for(var i = 0; i < a.length; i++) {
  93.                 links.push("https://voat.co" + a[i].getAttribute("href"));
  94.             }
  95.             return links;
  96.         });
  97.         allLinks = [].concat(allLinks, links);
  98.     }
  99.  
  100.     (function run() {
  101.         getLinks();
  102.        
  103.         var nextPage = page.evaluate(function() {
  104.             return document.querySelector(".btn-whoaverse-paging [rel='next']") !== null;
  105.         });
  106.  
  107.         if(nextPage && curPage < 999999) {
  108.             navigate(".btn-whoaverse-paging [rel='next']", run);
  109.         }
  110.         else {
  111.             console.log("got all submission links");
  112.             require("fs").write("submissionLinks", allLinks.join('\n'));
  113.             //deleteSubmissions();;
  114.         }
  115.     })();
  116. }
  117.  
  118. function deleteFromSubmissionLinksFile() {
  119.     allLinks = require("fs").read("submissionLinks").split("\n");
  120.     console.log("read " + allLinks.length + " from the submissionLinks file.");
  121.     deleteSubmissions();
  122. }
  123.  
  124. function deleteSubmissions() {
  125.     console.log("starting delete...");
  126.     function deleteSubmission(callback) {
  127.         console.log("deleting submission " + done);
  128.         page.evaluate(function() {
  129.             document.querySelector("#siteTable .submission .del-button").click();
  130.             document.querySelector("#deletestatusmesssage .yes").click();
  131.         });
  132.         setTimeout(callback, 1000);
  133.     }
  134.  
  135.     var done = 0;
  136.     var todo = allLinks.length;
  137.     function deleteNext() {
  138.         if(done === todo) {
  139.             console.log("DELETE COMPLETE!");
  140.         }
  141.         else {
  142.             deleteSubmission(function() {
  143.                 navigateByUrl(allLinks[done++], deleteNext);
  144.             });            
  145.         }
  146.     }
  147.     navigateByUrl(allLinks[done++], deleteNext);    
  148. }
  149.  
  150. console.log("opening https://voat.co");
  151. page.open("https://voat.co", function() {
  152.     console.log("logging in...");
  153.     page.evaluate(function(username, password) {
  154.         document.querySelector("#UserName").value = username;
  155.         document.querySelector("#Password").value = password;
  156.         document.querySelector("[type='submit']").click();
  157.     }, username, password);
  158.     setTimeout(function() {
  159.         var loggedIn = page.evaluate(function() {
  160.             return document.querySelector(".logged-in");
  161.         });
  162.         if(loggedIn) {
  163.             console.log("logged in");
  164.             navigate("#scp", getSubmissions);
  165.             //deleteFromSubmissionLinksFile();
  166.         }
  167.         else {
  168.             console.log("couldn't log in");
  169.         }
  170.     }, 5000);
  171. });
  172.                
  173. // phantom.exit();
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218. var username = "YOURUSERNAME";
  219. var password = "YOURPASSWORD";
  220. //////////////////////////////////////////////////////
  221.  
  222. phantom.onError = function(msg, trace) {
  223.     var msgStack = ['PHANTOM ERROR: ' + msg];
  224.     if (trace && trace.length) {
  225.         msgStack.push('TRACE:');
  226.         trace.forEach(function(t) {
  227.             msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
  228.         });
  229.     }
  230.     console.error(msgStack.join('\n'))
  231. };
  232.  
  233. var page = require('webpage').create();
  234.  
  235.  
  236.  
  237. function click(selector) {
  238.     page.evaluate(function(selector) {
  239.         document.querySelector(selector).click();
  240.     }, selector);
  241. }
  242.  
  243. function navigate(selector, callback) {
  244.     page.onLoadFinished = function() {
  245.         page.onLoadFinished = null;
  246.         callback();
  247.     };
  248.     click(selector);
  249. }
  250.  
  251. function navigateByUrl(deletecomments.jsurl, callback) {
  252.     page.onLoadFinished = function() {
  253.         page.onLoadFinished = null;
  254.         setTimeout(callback, 0);
  255.     };
  256.     page.evaluate(function(url) {
  257.         window.location.href = url;
  258.     }, url);
  259. }
  260.  
  261. var allLinks = [];
  262. var curPage = 0;
  263. function getComments() {
  264.     function getLinks() {
  265.         curPage++;
  266.         console.log("getting links for page " + curPage);
  267.         page.render("page.png");
  268.         var links = page.evaluate(function() {
  269.             var links = [];
  270.             var a = document.querySelectorAll(".thread .first:nth-child(2) a");
  271.             for(var i = 0; i < a.length; i++) {
  272.                 links.push("https://voat.co" + a[i].getAttribute("href"));
  273.             }
  274.             return links;
  275.         });
  276.         allLinks = [].concat(allLinks, links);
  277.     }
  278.  
  279.     (function run() {
  280.         getLinks();
  281.  
  282.         var nextPage = page.evaluate(function() {
  283.             return document.querySelector(".btn-whoaverse-paging [rel='next']") !== null;
  284.         });
  285.        
  286.         if(nextPage && curPage < 999999) {
  287.             navigate(".btn-whoaverse-paging [rel='next']", run);
  288.         }
  289.         else {
  290.             console.log("got all comment links");
  291.             require("fs").write("commentLinks", allLinks.join('\n'));
  292.             //deleteComments();
  293.         }
  294.     })();
  295. }
  296.  
  297. function deleteFromCommentLinksFile() {
  298.     allLinks = require("fs").read("commentLinks").split("\n");
  299.     console.log("read " + allLinks.length + " from the commentLinks file.");
  300.     deleteComments();
  301. }
  302.  
  303. function deleteComments() {
  304.     console.log("starting delete...");
  305.     function deleteComment(callback) {
  306.         console.log("deleting comment " + done);
  307.         page.evaluate(function() {
  308.             document.querySelector(".toggle.del-button a").click();
  309.             document.querySelector(".toggle.del-button .yes").click();
  310.         });
  311.         setTimeout(callback, 1000);
  312.     }
  313.  
  314.     var done = 0;
  315.     var todo = allLinks.length;
  316.     function deleteNext() {
  317.         if(done === todo) {
  318.             console.log("DELETE COMPLETE!");
  319.         }
  320.         else {
  321.             deleteComment(function() {
  322.                 navigateByUrl(allLinks[done++], deleteNext);
  323.             });            
  324.         }
  325.     }
  326.     navigateByUrl(allLinks[done++], deleteNext);    
  327. }
  328.  
  329. console.log("opening https://voat.co");
  330. page.open("https://voat.co", function() {
  331.     console.log("logging in...");
  332.     page.evaluate(function(username, password) {
  333.         document.querySelector("#UserName").value = username;
  334.         document.querySelector("#Password").value = password;
  335.         document.querySelector("[type='submit']").click();
  336.     }, username, password);
  337.     setTimeout(function() {
  338.         var loggedIn = page.evaluate(function() {
  339.             return document.querySelector(".logged-in");
  340.         });
  341.         if(loggedIn) {
  342.             console.log("logged in");
  343.             navigate("#ccp", getComments);
  344.             //deleteFromCommentLinksFile();
  345.         }
  346.         else {
  347.             console.log("couldn't log in");
  348.         }
  349.     }, 5000);
  350. });
  351.                
  352. // phantom.exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement