Compare commits

..

No commits in common. "fbc13d6b55a5d2f8ab6852c42115946d375db526" and "71779f4cdc3350482d32c437cecb24e408fad27c" have entirely different histories.

7 changed files with 25 additions and 74 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
*.code-workspace
tmp.md
utils/

View File

@ -1,33 +1,19 @@
console.log("background.js starts now");
console.log("background.js started!");
function handlePageactionClick(tab, onClickData) {
console.log("background.js: executing content script");
let executing = browser.scripting.executeScript({
files: [ "/contentscript.js" ],
target: {
tabId: tab.id,
allFrames: false
}
});
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: ${JSON.stringify(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}`);
}
let gettingAllPermissions = browser.permissions.getAll();
gettingAllPermissions.then((allPermissions) => {
console.log(JSON.stringify(allPermissions))
});
// add listener for the extension button
browser.pageAction.onClicked.addListener(handlePageactionClick);

View File

@ -9,63 +9,34 @@ function getCurrentDate() {
}
function extractFileUrlsAndNames() {
console.log("contentscript.js: this is extractFileUrlsAndNames()");
// get the correct frame
let frame = document.querySelector("iframe.js-mail-content");
// get all divs containing attachments
let divs = frame.contentWindow.document.body.querySelectorAll("div.samoware-mail-message__attach__item[attachment-ref]");
console.log(`contentscript.js: found ${divs.length} div containing attachments`);
let urlsAndFilenames = []
// loop over divs and extract attachment information
divs.forEach(div => {
let url = div.getAttribute("attachment-ref");
let filename = div.getAttribute("file-name");
// if filename is null, derive it from url
if ( ! filename ) {
let splitUrl = url.split("/");
filename = splitUrl[splitUrl.length-1];
}
urlsAndFilenames.push({url: url, filename: filename});
})
//console.log(`contentscript.js: urlsAndFilenames is ${JSON.stringify(urlsAndFilenames)}`);
return urlsAndFilenames;
return [];
}
function onStartedDownload(id) {
console.log(`contentscript.js: Started downloading: ${id}`);
console.log(`Started downloading: ${id}`);
}
function onFailedToStartDownload(error) {
console.log(`contentscript.js: Download failed: ${error}`);
console.log(`Download failed: ${error}`);
}
// get today's date
let currentDate = getCurrentDate();
console.log(`contentscript.js: currentDate is ${currentDate}`);
let urlsAndFilenames = extractFileUrlsAndNames();
let files = extractFileUrlsAndNames();
console.log(`contentscript.js: files is ${files}`);
// loop over attachments
for (let i = 0; i < urlsAndFilenames.length; i++) {
// prefix filename
let prefixedFilename = currentDate + " - " + urlsAndFilenames[i].filename;
console.log(`contentscript.js: prefixedFilename is ${prefixedFilename}`);
for (let i = 0; i < files.length; i++) {
// prefix files[i].filename with currentDate
let prefixedFilename = currentDate + " " + files[i].filename;
// start download
let downloading = browser.downloads.download({
url: urlsAndFilenames[i].url,
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
saveAs: (i == 0) // raise a path chooser dialog for the first file only; all later files will (hopefully!) be saved to the same folder
});
console.log(`contentscript.js: downloading is ${downloading}`);
// resolve Promise
downloading.then(onStartedDownload, onFailedToStartDownload);
}
console.log("contentscript.js: has finished");
"contentscript.js: this is the final line";
"contentscript.js has finished";

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -1,38 +1,33 @@
{
"manifest_version": 3,
"manifest_version": 2,
"name": "samoware-multisave",
"version": "1.0",
"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/samovar-48.png",
"96": "icons/samovar-96.png"
"48": "icons/icons8-samovar-48.png",
"96": "icons/icons8-samovar-96.png"
},
"permissions": [
"activeTab",
"scripting",
"tabs",
"downloads"
],
"host_permissions": [
"*://localhost/*",
"https://communigate.aip.de/"
],
"page_action": {
"default_icon": "icons/samovar-32.png",
"default_icon": "icons/icons8-samovar-32.png",
"default_title": "Samoware MultiSave",
"show_matches": [
"https://communigate.aip.de/*",
"*://localhost/*"
"https://communigate.aip.de/*"
]
},
"background": {
"scripts": [
"background.js"
]
],
"persistent": false
}
}