diff --git a/README.md b/README.md new file mode 100644 index 0000000..a53cec6 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# samoware-multisave + +A very-special-use-case Firefox extension. + +## Installation + +You can't install samoware-multisave as a regular browser extension as it is not signed by Mozilla. Load it as a temporary extension instead: + +1. Visit the special Firefox page `about:degugging` +2. Click "This Firefox" +3. Click "Load Temporary Add-on …" +4. Select the file `manifest.json` from the extension's project directory. (Actually, you can use any file from the extension.) + +## Known bugs + +* Does not work with Flatpak Firefox (temporary extensions can't seem to be loaded due to [this bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1852990)). Use Firefox from Snap instead (`sudo snap install firefox`). + +## Acknowledgements + +[Samovar icon](https://icons8.com/icon/g1dzsG1bI6vw/samovar) from [Icons8](https://icons8.com/) \ No newline at end of file diff --git a/background.js b/background.js new file mode 100644 index 0000000..da7a730 --- /dev/null +++ b/background.js @@ -0,0 +1,19 @@ +console.log("background.js started!"); + +function handlePageactionClick(tab, onClickData) { + console.log("background.js: executing content script"); + let executing = browser.tabs.executeScript({file: "/contentscript.js"}) + executing.then(onExecuted, onExecutionError); +} + +function onExecuted(result) { + console.log(`background.js: content script execution successful with result: ${result}`); +} + +function onExecutionError(error) { + console.error(`background.js: The following error occured while executing a content script: ${error}`); +} + +// add listener for the extension button +browser.pageAction.onClicked.addListener(handlePageactionClick); + diff --git a/contentscript.js b/contentscript.js new file mode 100644 index 0000000..d9bee42 --- /dev/null +++ b/contentscript.js @@ -0,0 +1,42 @@ +console.log("contentscript.js started!"); + +function getCurrentDate() { + let today = new Date(); + let yyyy = today.getFullYear(); + let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! + let dd = String(today.getDate()).padStart(2, '0'); + return yyyy + "-" + mm + "-" + dd; +} + +function extractFileUrlsAndNames() { + return []; +} + +function onStartedDownload(id) { + console.log(`Started downloading: ${id}`); +} + +function onFailedToStartDownload(error) { + console.log(`Download failed: ${error}`); +} + + +let currentDate = getCurrentDate(); +console.log(`contentscript.js: currentDate is ${currentDate}`); + +let files = extractFileUrlsAndNames(); +console.log(`contentscript.js: files is ${files}`); + +for (let i = 0; i < files.length; i++) { + // prefix files[i].filename with currentDate + let prefixedFilename = currentDate + " " + files[i].filename; + + let downloading = browser.downloads.download({ + url: files[i].url, + filename: prefixedFilename, + saveAs: (i == 0) // raise a path chooser dialog for the first file only; all later files will (hopefully!) be saved to the same folder + }); + downloading.then(onStartedDownload, onFailedToStartDownload); +} + +"contentscript.js has finished"; \ No newline at end of file diff --git a/icons/icons8-samovar-32.png b/icons/icons8-samovar-32.png new file mode 100644 index 0000000..817633b Binary files /dev/null and b/icons/icons8-samovar-32.png differ diff --git a/icons/icons8-samovar-48.png b/icons/icons8-samovar-48.png new file mode 100644 index 0000000..817633b Binary files /dev/null and b/icons/icons8-samovar-48.png differ diff --git a/icons/icons8-samovar-96.png b/icons/icons8-samovar-96.png new file mode 100644 index 0000000..817633b Binary files /dev/null and b/icons/icons8-samovar-96.png differ diff --git a/icons/samoware-multisave-32.png b/icons/samoware-multisave-32.png deleted file mode 100644 index f3b7653..0000000 Binary files a/icons/samoware-multisave-32.png and /dev/null differ diff --git a/icons/samoware-multisave-48.png b/icons/samoware-multisave-48.png deleted file mode 100644 index 4e82f35..0000000 Binary files a/icons/samoware-multisave-48.png and /dev/null differ diff --git a/icons/samoware-multisave-96.png b/icons/samoware-multisave-96.png deleted file mode 100644 index 25591e8..0000000 Binary files a/icons/samoware-multisave-96.png and /dev/null differ diff --git a/manifest.json b/manifest.json index 7bb5887..4b0335c 100644 --- a/manifest.json +++ b/manifest.json @@ -3,26 +3,31 @@ "name": "samoware-multisave", "version": "1.0", - "description": "Whne using the groupware CommuniGate with the web application Samoware, this Browser extension saves all files attached to an openend email to a directory of the user's chhosing, prefixing each entry's filename with the current date. Yes, it's quite specific.", + "description": "When using the groupware CommuniGate with the web application Samoware, this browser extension saves all attachments from the currently opened email to a directory of the user's choosing, prefixing each entry's filename with the current date. Yep, it's quite specific.", "icons": { - "48": "icons/samoware-multisave-48.png", - "96": "icons/samoware-multisave-96.png" + "48": "icons/icons8-samovar-48.png", + "96": "icons/icons8-samovar-96.png" }, "permissions": [ "activeTab", + "tabs", "downloads" ], - "browser_action": { - "default_icon": "icons/samoware-multisave-32.png", - "default_title": "Samoware MultiSave" + "page_action": { + "default_icon": "icons/icons8-samovar-32.png", + "default_title": "Samoware MultiSave", + "show_matches": [ + "https://communigate.aip.de/*" + ] }, "background": { "scripts": [ - "samoware-multisave.js" - ] + "background.js" + ], + "persistent": false } -} +} \ No newline at end of file diff --git a/samoware-multisave.js b/samoware-multisave.js deleted file mode 100644 index 0fe9675..0000000 --- a/samoware-multisave.js +++ /dev/null @@ -1,47 +0,0 @@ - - - -function getCurrentDate() { - let today = new Date(); - let yyyy = today.getFullYear(); - let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! - let dd = String(today.getDate()).padStart(2, '0'); - return yyyy + "-" + mm + "-" + dd; -} - -function extractFileUrlsAndNames() { - return []; -} - -function onStartedDownload(id) { - console.log(`Started downloading: ${id}`); -} - -function onFailed(error) { - console.log(`Download failed: ${error}`); -} - - - -function handleButtonClick(event) { - let currentDate = getCurrentDate(); - - let files = extractFileUrlsAndNames(); - - for (let i = 0; i < files.length; i++) { - // prefix files[i].filename with currentDate - let prefixedFilename = currentDate + " " + files[i].filename; - - let dl = browser.downloads.download({ - url: files[i].url, - filename: prefixedFilename, - saveAs: (i == 0) // raise a path chooser dialog for the first file only; all later files will (hopefully!) be saved to the same folder - }).then(onStartedDownload, onFailed); - } -} - - - - -// add listener for the extension button -browser.browserAction.onClicked.addListener(handleButtonClick); \ No newline at end of file