many changes
This commit is contained in:
parent
6c5da9538a
commit
bb21c27949
20
README.md
Normal file
20
README.md
Normal file
@ -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/)
|
||||
19
background.js
Normal file
19
background.js
Normal file
@ -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);
|
||||
|
||||
42
contentscript.js
Normal file
42
contentscript.js
Normal file
@ -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";
|
||||
BIN
icons/icons8-samovar-32.png
Normal file
BIN
icons/icons8-samovar-32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
BIN
icons/icons8-samovar-48.png
Normal file
BIN
icons/icons8-samovar-48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
BIN
icons/icons8-samovar-96.png
Normal file
BIN
icons/icons8-samovar-96.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 385 B |
Binary file not shown.
|
Before Width: | Height: | Size: 522 B |
Binary file not shown.
|
Before Width: | Height: | Size: 966 B |
@ -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
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
Loading…
Reference in New Issue
Block a user