Skip to content

Instantly share code, notes, and snippets.

@dmadisetti
Forked from frockenstein/GreasemonkeyUpload.js
Last active December 17, 2015 13:59
Show Gist options
  • Save dmadisetti/5621268 to your computer and use it in GitHub Desktop.
Save dmadisetti/5621268 to your computer and use it in GitHub Desktop.
Craigslist with auth
// Hats off to https://gist.github.com/hackable/1294667
var express = require('express'),
request = require('request'),
BufferList = require('bufferlist').BufferList,
sys = require('sys'),
fs = require('fs');
var app = express.createServer();
app.get('/', function(req, res) {
if(req.param("url")) {
var url = unescape(req.param("url"));
request({
uri:url,
encoding: 'binary'
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data_uri_prefix = "data:" + response.headers["content-type"] + ";base64,";
var image = new Buffer(body.toString(), "binary").toString("base64");
var image = data_uri_prefix + image;
res.send(image);
}else{
res.send('you brokes me!!');
}
return
});
}else{
res.send('Dude. Specify a url');
}
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
// ==UserScript==
// @name test upload
// @namespace namespace
// @description description
// @include https://post.craigslist.org/*
// @version 1
// ==/UserScript==
$ = unsafeWindow.jQuery;
if (location.search.indexOf('editimage') > -1) {
GM_xmlhttpRequest({
method: "GET",
url: "http://server?url=", //what ever you specify the url to be
onload: function(xhr) {
run(xhr.responseText);
}
});
}
function run(data){
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
img = new Image();
img.onload = function() {
canvas.setAttribute('width', img.width);
canvas.setAttribute('height', img.height);
ctx.drawImage(img, 0, 0);
var blob = canvas.mozGetAsFile('image.jpg');
sendBlob(blob);
}
img.src = data;
}
function sendBlob(file){
var name1 = $('.addmore form input:nth-child(1)').attr('name');
var value1 = $('.addmore form input:nth-child(1)').attr('value');
var name2 = $('.addmore form input:nth-child(2)').attr('name');
// submit as a multipart form, along with any other data
var form = new FormData();
var xhr = new XMLHttpRequest();
xhr.open('POST', location, true); // Post to current URL
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) { // Success?
alert('Success');
} else {
alert('Error submitting image: ' + xhr.status);
}
}
};
// Name : Value
form.append(name1, value1);
// Name : Value
form.append(name2, 'add');
// Name : Value
form.append('file', file);
if(confirm('submit?'))
xhr.send(form);
}
@dmadisetti
Copy link
Author

Hells to the yeah. Submits funky bird image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment