Created
October 30, 2011 23:11
-
-
Save tylermenezes/1326576 to your computer and use it in GitHub Desktop.
Extract messages from Google Voice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var el=document.createElement('div'), | |
b=document.getElementsByTagName('body')[0], | |
otherlib=false, | |
msg=''; | |
el.style.position='fixed'; | |
el.style.height='32px'; | |
el.style.width='220px'; | |
el.style.marginLeft='-110px'; | |
el.style.top='0'; | |
el.style.left='50%'; | |
el.style.padding='5px 10px'; | |
el.style.zIndex = 1001; | |
el.style.fontSize='12px'; | |
el.style.color='#222'; | |
el.style.backgroundColor='#f99'; | |
if(typeof jQuery!='undefined') { | |
msg='This page already using jQuery v'+jQuery.fn.jquery; | |
return showMsg(); | |
} else if (typeof $=='function') { | |
otherlib=true; | |
} | |
// more or less stolen form jquery core and adapted by paul irish | |
function getScript(url,success){ | |
var script=document.createElement('script'); | |
script.src=url; | |
var head=document.getElementsByTagName('head')[0], | |
done=false; | |
// Attach handlers for all browsers | |
script.onload=script.onreadystatechange = function(){ | |
if ( !done && (!this.readyState | |
|| this.readyState == 'loaded' | |
|| this.readyState == 'complete') ) { | |
done=true; | |
success(); | |
script.onload = script.onreadystatechange = null; | |
head.removeChild(script); | |
} | |
}; | |
head.appendChild(script); | |
} | |
getScript('http://code.jquery.com/jquery-latest.min.js',function() { | |
if (typeof jQuery=='undefined') { | |
msg='Sorry, but jQuery wasn\'t able to load'; | |
} else { | |
msg='This page is now jQuerified with v' + jQuery.fn.jquery; | |
if (otherlib) {msg+=' and noConflict(). Use $jq(), not $().';} | |
} | |
return showMsg(); | |
}); | |
function showMsg() { | |
el.innerHTML=msg; | |
b.appendChild(el); | |
window.setTimeout(function() { | |
if (typeof jQuery=='undefined') { | |
b.removeChild(el); | |
} else { | |
jQuery(el).fadeOut('slow',function() { | |
jQuery(this).remove(); | |
}); | |
if (otherlib) { | |
$jq=jQuery.noConflict(); | |
} | |
} | |
} ,2500); | |
} | |
})(); | |
var i = 1; | |
var messages = {}; | |
var htmls; | |
function getPage(){ | |
$jq.get("https://www.google.com/voice/b/0/inbox/recent/sms/?page=p" + i + "&v=24718802", function(page){ | |
console.log(i); | |
i++; | |
var p = $jq(page); | |
var j = $jq.parseJSON(p.children("response").children("json").text()).messages; | |
var h = p.children("response").children('html').text(); | |
htmls += "<div class='pagee'>" + h + "</div>"; | |
for(var n in j){ | |
messages[n] = j[n]; | |
} | |
if(i <= 39){ | |
setTimeout("getPage()", 1000); | |
}else{ | |
finished(); | |
} | |
}); | |
} | |
var fMessages = []; | |
function finished(){ | |
$jq("#gc-view").html(htmls); | |
$jq(".gc-message-message-display").children(".gc-message-sms-old").css("display", "block"); | |
$jq(".gc-message-message-display").children(".gc-message-sms-more").css("display", "none"); | |
var me = "+1" + $jq(".phoneNumber").text().replace(/[^\d.]/g, ""); | |
$jq(".gc-message-sms-row").each(function(i, e){ | |
e = $jq(e); | |
var id = e.parents(".gc-message-sms")[0].id | |
var deets = messages[id]; | |
var from = e.children(".gc-message-sms-from").text().replace(/[^a-zA-Z 0-9 ]/g, "").replace(/^\s+|\s+$/g,''); | |
var text = e.children(".gc-message-sms-text").text(); | |
var time = e.children(".gc-message-sms-time").text().replace(/[^a-zA-Z 0-9:]/g, "").replace(/^\s+|\s+$/g,''); | |
var f = {}; | |
f.id = id; | |
f.startTime = parseInt(deets.startTime, 10); | |
f.fromNumber = deets.phoneNumber; | |
f.toNumber = me; | |
f.from = from; | |
f.text = text; | |
f.timeStr = time; | |
f.time = new Date(parseInt(deets.startTime, 10)); | |
var timeParts = f.timeStr.split(':'); | |
var tpTemp = timeParts[1].split(' '); | |
timeParts = [timeParts[0], tpTemp[0], tpTemp[1]]; | |
var hour = parseInt(timeParts[0], 10); | |
if(timeParts[2] == "PM"){ | |
hour += 12; | |
} | |
hour = hour % 24; | |
var minute = parseInt(timeParts[1], 10); | |
var day = f.time.getDate(); | |
var month = f.time.getMonth(); | |
var year = f.time.getFullYear(); | |
f.time = new Date(year, month, day, hour, minute, 0, 0); | |
if(i > 0 && fMessages[i - 1].id == f.id){ | |
while(fMessages[i - 1].time.getHours() > f.time.getHours()){ // it's now past midnight, so add a day. | |
f.time.setTime(f.time.getTime() + (24*60*60*1000)); | |
} | |
} | |
f.timestamp = f.time.getTime(); | |
if(f.from == "Me"){ | |
f.toNumber = f.fromNumber | |
f.fromNumber = me; | |
} | |
fMessages.push(f); | |
}); | |
$jq("#gc-view").html("<textarea>" + JSON.stringify(fMessages) + "</textarea>"); | |
} | |
getPage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment