Last active
December 17, 2015 13:49
-
-
Save frockenstein/5620344 to your computer and use it in GitHub Desktop.
Greasemonkey Image Upload
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
// ==UserScript== | |
// @name test upload | |
// @namespace namespace | |
// @description description | |
// @include https://post.craigslist.org/* | |
// @version 1 | |
// @grant all | |
// ==/UserScript== | |
$ = unsafeWindow.jQuery; | |
function getDataFromUrl(url) { | |
var canvas = document.createElement('canvas'), | |
ctx = canvas.getContext('2d'), | |
img = new Image(); | |
img.src = url; | |
img.onload = function() { | |
canvas.setAttribute('width', img.width); | |
canvas.setAttribute('height', img.height); | |
ctx.drawImage(img, 0, 0); | |
document.forms[0].appendChild(img); | |
} | |
return canvas.mozGetAsFile('image.png'); | |
//return canvas.toDataURL('image.png'); | |
} | |
if (location.search.indexOf('editimage') > -1) { | |
var url = 'http://boomtownphotos.s3.amazonaws.com/charleston/orig_boomver_1_1313035-1.jpg'; | |
var file = getDataFromUrl(url); | |
console.log(file); | |
debugger; | |
var fd = new FormData(document.forms[0]); | |
fd.append('file', file, 'image.png'); | |
//alert('submitting'); | |
if (confirm('submit?')) document.forms[0].submit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment