Advertisement
Guest User

voat cleaner

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