Showing revision #1689d893 of page delete_post_history


Delete Your Post History

WARNING: Deleted posts and comments cannot be recovered. By deleting your posts, you will also be wiping every comment in every post, including comments made by other users. It's much fairer to the community to manually edit your posts to say [deleted] so you don't wipe out comments that don't belong to you.

Steps:

  1. Press F12 (in firefox)

  2. Click 'Console'

  3. Paste the code shown below

  4. Press enter

  5. When prompted for the user to delete, write the username of the account you're deleting.

The Code (written by Bea):

function deleteUser(name) {
  return Promise.all([
    searchForLast(num => pageExists('/user/'+name+'/comments/'   +num)).then(last => deleteAllPages('/user/'+name+'/comments/'   , last)),
    searchForLast(num => pageExists('/user/'+name+'/submissions/'+num)).then(last => deleteAllPages('/user/'+name+'/submissions/', last))
  ]);
}

function pageExists(url) {
  return fetch(url).then(_=>_.status === 200);
}

async function searchForLast(exists, start) {
  var highLimit = start || 5;
  while(await exists(highLimit)) {
    highLimit *= 2;
    console.log(highLimit);
  }
  
  var lowLimit = highLimit;
  while(!(await exists(lowLimit))) {
    lowLimit = Math.floor(lowLimit*.75);
    console.log(lowLimit);
  }
  
  while(lowLimit !== highLimit-1) {
    var tmp = Math.floor( (highLimit+lowLimit)/2 );
    console.log(highLimit, lowLimit, tmp);
    if (await exists(tmp))
      lowLimit = tmp;
    else
      highLimit = tmp;
  }
  
  return lowLimit;
}

function deleteAllPages(prefix, current) {
  console.log('fetching: ', prefix + current);
  return fetch(prefix + current, { credentials: 'include' })
    .then(_=>_.text())
    .then(html=>(new DOMParser()).parseFromString(html, 'text/html'))
    .then(doc=>deleteAllOnPage(doc))
    .then(() => {
    if (current > 1)
      return deleteAllPages(prefix, --current);
    else
      return true;
  });
}

function deleteAllOnPage(doc) {
  console.log('deleting all on doc: ', doc);
  return Promise.all(Array.prototype.slice.call((doc).querySelectorAll('.comment form[action*="delete"], .submission form[action*="delete"]')).map(post => deletePost(post)));
}

function deletePost(form) {
  console.log('deleting: ', form);
  return fetch(form.action, {
    credentials: 'include',
    method: 'POST',
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    body: 'token=' + form.elements['token'].value
  }).then(_=>_.text());
}

(async function(){
  var name = prompt('Enter user to delete:');
  if(await pageExists('/user/'+name)) {
    deleteUser(name).then((success) => {
      alert('Done.');
    }).catch((error) => {
      alert('Error: ' + error)
    });
  } else {
    alert('User does not exist.')
  }
})();

Source code

**WARNING:**
Deleted posts and comments cannot be recovered. By deleting your posts, you will also be wiping every comment in every post, including comments made by other users. It's much fairer to the community to manually edit your posts to say [deleted] so you don't wipe out comments that don't belong to you.

**Steps:**

1.  Press F12 (in firefox)

2. Click 'Console'

3. Paste the code shown below

4. Press enter

5. When prompted for the user to delete, write the username of the account you're deleting.

**The Code (written by Bea):**

```
function deleteUser(name) {
  return Promise.all([
    searchForLast(num => pageExists('/user/'+name+'/comments/'   +num)).then(last => deleteAllPages('/user/'+name+'/comments/'   , last)),
    searchForLast(num => pageExists('/user/'+name+'/submissions/'+num)).then(last => deleteAllPages('/user/'+name+'/submissions/', last))
  ]);
}

function pageExists(url) {
  return fetch(url).then(_=>_.status === 200);
}

async function searchForLast(exists, start) {
  var highLimit = start || 5;
  while(await exists(highLimit)) {
    highLimit *= 2;
    console.log(highLimit);
  }
  
  var lowLimit = highLimit;
  while(!(await exists(lowLimit))) {
    lowLimit = Math.floor(lowLimit*.75);
    console.log(lowLimit);
  }
  
  while(lowLimit !== highLimit-1) {
    var tmp = Math.floor( (highLimit+lowLimit)/2 );
    console.log(highLimit, lowLimit, tmp);
    if (await exists(tmp))
      lowLimit = tmp;
    else
      highLimit = tmp;
  }
  
  return lowLimit;
}

function deleteAllPages(prefix, current) {
  console.log('fetching: ', prefix + current);
  return fetch(prefix + current, { credentials: 'include' })
    .then(_=>_.text())
    .then(html=>(new DOMParser()).parseFromString(html, 'text/html'))
    .then(doc=>deleteAllOnPage(doc))
    .then(() => {
    if (current > 1)
      return deleteAllPages(prefix, --current);
    else
      return true;
  });
}

function deleteAllOnPage(doc) {
  console.log('deleting all on doc: ', doc);
  return Promise.all(Array.prototype.slice.call((doc).querySelectorAll('.comment form[action*="delete"], .submission form[action*="delete"]')).map(post => deletePost(post)));
}

function deletePost(form) {
  console.log('deleting: ', form);
  return fetch(form.action, {
    credentials: 'include',
    method: 'POST',
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    body: 'token=' + form.elements['token'].value
  }).then(_=>_.text());
}

(async function(){
  var name = prompt('Enter user to delete:');
  if(await pageExists('/user/'+name)) {
    deleteUser(name).then((success) => {
      alert('Done.');
    }).catch((error) => {
      alert('Error: ' + error)
    });
  } else {
    alert('User does not exist.')
  }
})();
```