// ==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); }