Showing revision #05db187e of page delete_post_history


Delete Your Post History

Steps:

  1. Press F12 (in firefox)

  2. Click 'Console'

  3. Paste the code

  4. Press enter

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

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

Steps:

1.  Press F12 (in firefox)

2. Click 'Console'

3. Paste the code

4. Press enter

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

```
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.')
  }
})();
```