Skip to content

Instantly share code, notes, and snippets.

@zkwentz
Created July 19, 2013 01:07
Show Gist options
  • Save zkwentz/6034347 to your computer and use it in GitHub Desktop.
Save zkwentz/6034347 to your computer and use it in GitHub Desktop.
Ingest a Google Group with attached files and upload them to a specific endpoint
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
function dataURItoBlob(dataURI) {
var binary = atob(dataURI.split(',')[1]);
var array = [];
for(var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], {type: 'image/jpeg'});
}
var ingest = function($this)
{
console.log($this.html());
$this.css('background-color','#E0DD1B').find('.GGYB0KICPCB').click();
setTimeout(function(){
var form = new FormData(),
xhr = new XMLHttpRequest();
xhr.open('post','/',true);
var $body = $this.find('.GGYB0KICMBB');
console.log($body.text());
form.append('comments',$body.text());
console.log($body.find('[href^="mailto"]').text());
form.append('submitter',$body.find('[href^="mailto"]').text());
var imageURL = $this.find('.GGYB0KICL0C .gwt-Anchor').first().attr('href');
console.log(imageURL);
if (imageURL)
{
var img = new Image();
img.src = imageURL;
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width =this.width;
canvas.height =this.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
var dataURL = canvas.toDataURL("image/png");
var blob = dataURItoBlob(dataURL);
if (blob.size > 0)
{
form.append('userfile',blob);
console.log(blob);
xhr.onreadystatechange = function() {
if (xhr.readyState == xhr.DONE)
{
if (xhr.status == 200)
{
$this.css('background-color','#1BE042');
}
else
{
$this.css('background-color','#E01B1B');
}
ingest($this.next());
}
}
xhr.send(form);
}
}
}
else
{
$this.css('background-color','#E08E1B');
ingest($this.next());
}
},1000);
}
ingest($('.GGYB0KICDCB').first());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment