rj1
about | log | files | refs | license
commit cee53f724ee29f14ab308ccf9f2f9edb319f0fe8
author: rj1 <[email protected]>
date:   Tue, 16 Aug 2022 13:42:02 -0500

first

Diffstat:
AREADME.md | 8++++++++
Aicon.png | 0
Amanifest.json | 24++++++++++++++++++++++++
Aupload.js | 36++++++++++++++++++++++++++++++++++++
4 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,8 @@ +# POST Image Firefox extension + +## todo + +- allow users to change url/post parameters +- checkbox for open new url in browser +- checkbox for place new url in clipboard + diff --git a/icon.png b/icon.png Binary files differ. diff --git a/manifest.json b/manifest.json @@ -0,0 +1,24 @@ +{ + "manifest_version": 2, + "name": "POST Image", + "version": "0.1", + "icons": { + "200": "icon.png" + }, + "permissions" : [ + "contextMenus", + "tabs", + "http://*/*", + "https://*/*" + ], + "background": { + "scripts": ["upload.js"] + }, + "content_scripts" : [ + { + "matches" : ["http://*/*", "https://*/*"], + "css" : [], + "js" : [] + } + ] +} diff --git a/upload.js b/upload.js @@ -0,0 +1,36 @@ +browser.contextMenus.create({ + title: "Upload image [POST]", + contexts: ["image"], + onclick: function(info, tab) { + // get the image from cache: + var download = new XMLHttpRequest(); + download.onload = function() { + var filename = info.srcUrl.split(/[\\/]/).pop(); + + // if filename has no extension, add .png to it + // TODO: detect filetype and add the proper extension + if(filename == filename.split('.')) { + filename = filename + '.png'; + } + + var fd = new FormData(); + fd.append("files[]", download.response, filename); + var upload = new XMLHttpRequest(); + upload.responseType = 'json'; + + upload.onload = function() { + url = upload.response.files[0].url; + browser.tabs.create({url: url}); + } + + // upload image + upload.open('POST', 'https://uguu.se/upload.php'); + upload.send(fd); + }; + // get uguu url + download.responseType = 'blob'; + download.open('GET', info.srcUrl); + download.send(); + } +}); +