Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- BEGIN INSTRUCTIONS
- this is a phantomjs script. http://phantomjs.org/
- there are two scripts here. one deletes your submissions and one deletes your comments.
- copy the first script into a file. call the file deletesubmissions.js
- copy the second script into a file. call the file deletecomments.js
- find phantomjs.exe and put it in the same directory as those two files.
- change the username and password at the start of each script to be your username and password.
- open a command line and type: phantomjs deletesubmissions.js to delete your submissions
- open a command line and type: phantomjs deletecomments.js to delete your comments
- look for these two lines in deletesubmissions.js. there are corresponding lines in deletecomments.js.
- 1. navigate("#scp", getSubmissions);
- 2. //deleteFromSubmissionLinksFile();
- line one gets all the links to delete and saves them to a file.
- line two reads the list of links to delete out of the file. then it goes to that link and deletes your submission.
- so first run the script with line 2 commented out. then run it with line 1 commented out.
- it will not work perfectly and you will probably have to run it a few times.
- Feel free to improve, modify, and distribute these scripts.
- END INSTRUCTIONS
- */
- var username = "YOURUSERNAME";
- var password = "YOURPASSWORD";
- //////////////////////////////////////////////////////
- phantom.onError = function(msg, trace) {
- var msgStack = ['PHANTOM ERROR: ' + msg];
- if (trace && trace.length) {
- msgStack.push('TRACE:');
- trace.forEach(function(t) {
- msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
- });
- }
- console.error(msgStack.join('\n'))
- };
- var page = require('webpage').create();
- function click(selector) {
- page.evaluate(function(selector) {
- document.querySelector(selector).click();
- }, selector);
- }
- function navigate(selector, callback) {
- page.onLoadFinished = function() {
- page.onLoadFinished = null;
- callback();
- };
- click(selector);
- }
- function navigateByUrl(url, callback) {
- page.onLoadFinished = function() {
- page.onLoadFinished = null;
- setTimeout(callback, 0);
- };
- page.evaluate(function(url) {
- window.location.href = url;
- }, url);
- }
- var allLinks = [];
- var curPage = 0;
- function getSubmissions() {
- function getLinks() {
- curPage++;
- console.log("getting links for page " + curPage);
- var links = page.evaluate(function() {
- var links = [];
- var a = document.querySelectorAll(".submission a.comments");
- for(var i = 0; i < a.length; i++) {
- links.push("https://voat.co" + a[i].getAttribute("href"));
- }
- return links;
- });
- allLinks = [].concat(allLinks, links);
- }
- (function run() {
- getLinks();
- var nextPage = page.evaluate(function() {
- return document.querySelector(".btn-whoaverse-paging [rel='next']") !== null;
- });
- if(nextPage && curPage < 999999) {
- navigate(".btn-whoaverse-paging [rel='next']", run);
- }
- else {
- console.log("got all submission links");
- require("fs").write("submissionLinks", allLinks.join('\n'));
- //deleteSubmissions();;
- }
- })();
- }
- function deleteFromSubmissionLinksFile() {
- allLinks = require("fs").read("submissionLinks").split("\n");
- console.log("read " + allLinks.length + " from the submissionLinks file.");
- deleteSubmissions();
- }
- function deleteSubmissions() {
- console.log("starting delete...");
- function deleteSubmission(callback) {
- console.log("deleting submission " + done);
- page.evaluate(function() {
- document.querySelector("#siteTable .submission .del-button").click();
- document.querySelector("#deletestatusmesssage .yes").click();
- });
- setTimeout(callback, 1000);
- }
- var done = 0;
- var todo = allLinks.length;
- function deleteNext() {
- if(done === todo) {
- console.log("DELETE COMPLETE!");
- }
- else {
- deleteSubmission(function() {
- navigateByUrl(allLinks[done++], deleteNext);
- });
- }
- }
- navigateByUrl(allLinks[done++], deleteNext);
- }
- console.log("opening https://voat.co");
- page.open("https://voat.co", function() {
- console.log("logging in...");
- page.evaluate(function(username, password) {
- document.querySelector("#UserName").value = username;
- document.querySelector("#Password").value = password;
- document.querySelector("[type='submit']").click();
- }, username, password);
- setTimeout(function() {
- var loggedIn = page.evaluate(function() {
- return document.querySelector(".logged-in");
- });
- if(loggedIn) {
- console.log("logged in");
- navigate("#scp", getSubmissions);
- //deleteFromSubmissionLinksFile();
- }
- else {
- console.log("couldn't log in");
- }
- }, 5000);
- });
- // phantom.exit();
- var username = "YOURUSERNAME";
- var password = "YOURPASSWORD";
- //////////////////////////////////////////////////////
- phantom.onError = function(msg, trace) {
- var msgStack = ['PHANTOM ERROR: ' + msg];
- if (trace && trace.length) {
- msgStack.push('TRACE:');
- trace.forEach(function(t) {
- msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
- });
- }
- console.error(msgStack.join('\n'))
- };
- var page = require('webpage').create();
- function click(selector) {
- page.evaluate(function(selector) {
- document.querySelector(selector).click();
- }, selector);
- }
- function navigate(selector, callback) {
- page.onLoadFinished = function() {
- page.onLoadFinished = null;
- callback();
- };
- click(selector);
- }
- function navigateByUrl(deletecomments.jsurl, callback) {
- page.onLoadFinished = function() {
- page.onLoadFinished = null;
- setTimeout(callback, 0);
- };
- page.evaluate(function(url) {
- window.location.href = url;
- }, url);
- }
- var allLinks = [];
- var curPage = 0;
- function getComments() {
- function getLinks() {
- curPage++;
- console.log("getting links for page " + curPage);
- page.render("page.png");
- var links = page.evaluate(function() {
- var links = [];
- var a = document.querySelectorAll(".thread .first:nth-child(2) a");
- for(var i = 0; i < a.length; i++) {
- links.push("https://voat.co" + a[i].getAttribute("href"));
- }
- return links;
- });
- allLinks = [].concat(allLinks, links);
- }
- (function run() {
- getLinks();
- var nextPage = page.evaluate(function() {
- return document.querySelector(".btn-whoaverse-paging [rel='next']") !== null;
- });
- if(nextPage && curPage < 999999) {
- navigate(".btn-whoaverse-paging [rel='next']", run);
- }
- else {
- console.log("got all comment links");
- require("fs").write("commentLinks", allLinks.join('\n'));
- //deleteComments();
- }
- })();
- }
- function deleteFromCommentLinksFile() {
- allLinks = require("fs").read("commentLinks").split("\n");
- console.log("read " + allLinks.length + " from the commentLinks file.");
- deleteComments();
- }
- function deleteComments() {
- console.log("starting delete...");
- function deleteComment(callback) {
- console.log("deleting comment " + done);
- page.evaluate(function() {
- document.querySelector(".toggle.del-button a").click();
- document.querySelector(".toggle.del-button .yes").click();
- });
- setTimeout(callback, 1000);
- }
- var done = 0;
- var todo = allLinks.length;
- function deleteNext() {
- if(done === todo) {
- console.log("DELETE COMPLETE!");
- }
- else {
- deleteComment(function() {
- navigateByUrl(allLinks[done++], deleteNext);
- });
- }
- }
- navigateByUrl(allLinks[done++], deleteNext);
- }
- console.log("opening https://voat.co");
- page.open("https://voat.co", function() {
- console.log("logging in...");
- page.evaluate(function(username, password) {
- document.querySelector("#UserName").value = username;
- document.querySelector("#Password").value = password;
- document.querySelector("[type='submit']").click();
- }, username, password);
- setTimeout(function() {
- var loggedIn = page.evaluate(function() {
- return document.querySelector(".logged-in");
- });
- if(loggedIn) {
- console.log("logged in");
- navigate("#ccp", getComments);
- //deleteFromCommentLinksFile();
- }
- else {
- console.log("couldn't log in");
- }
- }, 5000);
- });
- // phantom.exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement