Last active
October 13, 2015 05:18
-
-
Save tobbez/4145444 to your computer and use it in GitHub Desktop.
whatimg url 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
/* this scripts needs to run on whatimg.com */ | |
if (document.location.pathname == '/upload.php' | |
&& document.location.hash == '#whatcd-script') { | |
document.addEventListener('DOMContentLoaded', function () { | |
window.parent.postMessage(document.getElementsByClassName('input_field')[0].value, "*"); | |
}); | |
} |
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
/* this script needs to run on what.cd */ | |
if (['/upload.php', '/torrents.php', '/requests.php', '/artist.php'].indexOf(document.location.pathname) !== -1) { | |
document.addEventListener('DOMContentLoaded', function () { | |
var sendImage = function (url) { | |
var iframe = document.createElement('iframe'); | |
iframe.width = 0; | |
iframe.height = 0; | |
document.body.appendChild(iframe); | |
iframe.contentWindow.document.write( '<form id="whatimg_form" name="whatimg_form" action="https://whatimg.com/upload.php#whatcd-script" method="POST">\ | |
<input type="hidden" name="userfile[]" value="' + url + '"/>\ | |
<input type="hidden" name="upload_to" value="0" />\ | |
<input type="hidden" name="upload_type" value="url-standard" />\ | |
</form>\ | |
<script type="text/javascript">\ | |
document.whatimg_form.submit();\ | |
</script>'); | |
}; | |
var image = document.querySelectorAll('input[name="image"]')[0]; | |
if (typeof image === 'undefined') return; | |
var btn = document.createElement('input'); | |
btn.type = 'submit'; | |
btn.value = 'WhatIMG'; | |
btn.id = 'wimg_submit'; | |
btn.addEventListener('click', function (e) { | |
e.preventDefault(); | |
msg.textContent = 'Uploading...'; | |
sendImage(image.value); | |
}); | |
image.parentNode.insertBefore(btn, image.nextSibling); | |
var msg = document.createElement('span'); | |
msg.id = 'whatimg_msg'; | |
msg.style.marginLeft = '2em'; | |
image.parentNode.insertBefore(msg, image.nextSibling.nextSibling); | |
var recvMessage = function (e) { | |
if (e.origin == 'https://whatimg.com') { | |
msg.textContent = ''; | |
image.value = e.data; | |
} | |
}; | |
window.addEventListener('message', recvMessage, false); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment