Skip to content

Instantly share code, notes, and snippets.

@andrewshatnyy
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewshatnyy/7ff412c6a255f3100a4f to your computer and use it in GitHub Desktop.
Save andrewshatnyy/7ff412c6a255f3100a4f to your computer and use it in GitHub Desktop.
Google Voice messages / history purger (For those who think: "how to remove all my history and messages from google voice")
// this script is to be pasted into google chrome when you on messages page
// !!! ACTHUNG: IT WILL DESTROY ALL OF YOUR MESSAGES !!!
// I think it will remove everything including history
// Be careful. Make sure you don't need all of you N*k messages
// TO REMOVE HISTORY
// 1. go to history page
// 2. check what url is called for load messages and when you delete messages forever
// 3. replace urs accordinly in loadMessages, deleteAllWith
function loadMessages() {
// load messages
// if you have problems in this call
// go to your network panel and check what url is called
// when you reload messages page
var xhr = new XMLHttpRequest();
// url is different when cleaning archive
xhr.open('GET', '/voice/b/0/inbox/recent/all/?v=75984049');
xhr.onload = function(e) {
if (this.status === 200) {
var xmlDoc = parseXml(this.response);
var json = messagesJson(xmlDoc);
var ids = getMessageIds(json);
if (!(ids && ids.length > 0)) {
return alert('done cleaning your shit');
}
var params = getParams(ids);
return deleteAllWith(params);
}
throw new Error('Some err while getting messages:' + this.status + ' ' + this.response);
};
xhr.send();
}
function messagesJson (xmlDoc) {
var jsonNode = xmlDoc.getElementsByTagName('json')[0];
if (!jsonNode) throw new Error('No json node in response. Fudge....');
return JSON.parse(jsonNode.textContent);
}
function parseXml (response) {
var parser = new DOMParser();
return parser.parseFromString(response,"text/xml");
}
function getMessageIds (json) {
return Object.keys(json.messages);
}
function getParams (messageIds) {
// prepare params for posting the form
var ids = messageIds.map(function(id){return 'messages='+id;});
// get id for the request so Google don't bitch about your post
var se = document.querySelector('[name=_rnr_se]');
ids.push('trash=1'); // optional with archive
ids.push(se.name+'='+se.value);
return ids.join('&');
}
function whenDeleteSent () {
if (this.status === 200) {
return loadMessages();
}
throw new Error('Some err while deleting:' + this.status + ' ' + this.response);
}
function deleteAllWith (params) {
// perform the post to delete texts
// same as with loadMessages (look into your network requests)
var xhr = new XMLHttpRequest();
// url is different when cleaning archive
xhr.open('POST', '/voice/b/0/inbox/deleteMessages/', true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8')
xhr.onload = whenDeleteSent;
xhr.send(params);
}
loadMessages();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment