diff --git a/CHANGELOG.md b/CHANGELOG.md index d025514..c80bc98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v5.8.0 + +- Added option to also resize images from the original e-mail when using forward / reply (#15). This feature also works with autoresize.\ +- Fixed wrong variable name in content_script.js, that caused the log to console option to always be disabled. +- Added a simple "How to use" section to readme. + ## v5.7.2 - Fixed - the image is not resized when right clicking inline image, selecting resize image and clicking ok. (#23)\ diff --git a/README.md b/README.md index 8f0096e..31ea424 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,28 @@ Since the original repo is no longer mantained and became read-only on 28th of D Each time a compatible (JPG/PNG/BMP) image is attached to/inserted into new e-mail the user has the ability to resize the image. The resized image replaces previously inserted / attached one. +## Installation + +Head over to [release page](https://github.com/memeller/shrunked/releases/latest) and download the xpi. \ +If you are using Firefox, you will need to right click on the link and select "Save link as...", otherwise Firefox will try to install the xpi file in Firefox.\ +Open Thunderbird, open Add-ons (Tools -> Add-ons and Themes), select "Install Add-on From File..."\ +![install from file](/images/install_from_file.png)\ +and select the downloaded xpi. + +## How to use + +After installing the add-on, some options are set by default. Please adjust the options if, for example, you want images to be resized in reply/forward mode.\ +![png options](/images/options.png)\ +Each time you attach/insert an image into an email, a small notfication will appear asking if you would like to resize the image(s).\ +![png options](/images/notification.png)\ +If you select 'Yes', a small window will appear allowing you to set the target dimensions, see the size of the image before and after, etc.\ +![png options](/images/popup.png)\ +After confirming the resize, the attachments / inline images will be replaced with their resized versions.\ + ## New in this fork (vs darkrojan's version): -- Added Autoresize (currently works only for newly added attachments / inline images). This can be enabled for all images / inline only / attachments only. When enabled, each time an image is inserted / attached, the requirements for the resize function are checked (file size / dimensions, the ones set in options panel). If the image should be resized, it will be resized and replaced automatically, without any user interaction. +- Added support for resizing images when forwarding / replying to messages. This can be enabled in the options, disabled by default. +- Added Autoresize. This can be enabled for all images / inline only / attachments only. When enabled, each time an image is inserted / attached, the requirements for the resize function are checked (file size / dimensions, the ones set in options panel). If the image should be resized, it will be resized and replaced automatically, without any user interaction. - Added PL lang support, - BMP support (converted to JPG when resized), - PNG support, @@ -28,11 +47,6 @@ It is used by default, to use the previous algorithm please uncheck the correspo - If the selected file cannot be resized, the context menu item is disabled and shows additional information instead of item being hidden. - Console logging can be disabled. -## Installation -Head over to [release page](https://github.com/memeller/shrunked/releases/latest) and download the xpi. \ -If you are using Firefox you need to right click the link and select "Save link as...", otherwise Firefox will try to install the xpi file in Firefox.\ -Open Thunderbird, open Add-ons (Tools -> Add-ons and Themes), select "Install Add-on From File..."\ -![install from file](/images/install_from_file.png)\ -and select the downloaded xpi. + ## Known issues diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 54d86b0..328717e 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -29,6 +29,9 @@ "advanced.autoResize.inline": { "message": "Auto resize inline images" }, + "advanced.resizeInReplyForward.label": { + "message": "Also resize images when replying / forwarding them" + }, "advanced.orient.label": { "message": "Automatically rotate images" }, diff --git a/_locales/pl/messages.json b/_locales/pl/messages.json index 5f1e1d4..28f6fcc 100644 --- a/_locales/pl/messages.json +++ b/_locales/pl/messages.json @@ -29,6 +29,9 @@ "advanced.autoResize.inline": { "message": "Automatycznie zmniejszaj tylko dodane w treści" }, + "advanced.resizeInReplyForward.label": { + "message": "Zmniejszaj również obrazki w trakcie ich forwardowania / w odopowiedzi" + }, "advanced.orient.label": { "message": "Automatycznie obróć obrazki" }, diff --git a/api/shrunked.js b/api/shrunked.js index c56787b..13d04cc 100644 --- a/api/shrunked.js +++ b/api/shrunked.js @@ -267,6 +267,7 @@ var shrunked = class extends ExtensionCommon.ExtensionAPI { "options.logenabled": false, "options.contextInfo": true, "options.autoResize": "off", + "options.resizeInReplyForward": false, resizeAttachmentsOnSend: false, }; @@ -292,14 +293,16 @@ var shrunked = class extends ExtensionCommon.ExtensionAPI { return prefsToStore; }, showNotification(tab, imageCount) { + return new Promise((resolve, reject) => { let question = localeData.localizeMessage( imageCount == 1 ? "question.single" : "question.plural" ); - + let nativeTab = tabManager.get(tab.id).nativeTab; + //message display notification from https://github.com/jobisoft/notificationbar-API/blob/master/notificationbar/implementation.js let notifyBox = - nativeTab.gComposeNotification || nativeTab.gNotification.notificationbox; + nativeTab.gComposeNotification || ((nativeTab.gNotification)?nativeTab.gNotification.notificationbox:null) || nativeTab.chromeBrowser.contentWindow.messageBrowser.contentWindow.gMessageNotificationBar.msgNotificationBar; let notification = notifyBox.getNotificationWithValue("shrunked-notification"); if (imageCount == 0) { if (notification) { diff --git a/api/shrunked.json b/api/shrunked.json index e2d5b95..3874e59 100644 --- a/api/shrunked.json +++ b/api/shrunked.json @@ -91,6 +91,10 @@ "type":"boolean", "optional":true }, + "resizeInReplyForward":{ + "type":"boolean", + "optional":true + }, "autoResize":{ "type":"string", "optional":true diff --git a/background.js b/background.js index 05e95b8..af79016 100644 --- a/background.js +++ b/background.js @@ -7,18 +7,19 @@ async function shouldResize(attachment, checkSize = true) { if (!checkSize) { return true; } - let { fileSizeMinimum } = await browser.storage.local.get({ fileSizeMinimum: 100 }); - let file = await browser.compose.getAttachmentFile(attachment.id); - return file.size >= fileSizeMinimum * 1024; + let file = await browser.compose.getAttachmentFile(attachment.id); + return file.size >= fileSizeMinimum * 1024; } //get options and defaults from config let options={} let defaults={} +let fileSizeMinimum=100; //check options on start and forward the logenabled/contextinfo setting to shrunked api loadOptions().then((response)=> { options=response.options; defaults=response.defaults; + fileSizeMinimum=response.fileSizeMinimum; logenabled=response.options.logenabled; contextInfo=response.options.contextInfo; if(logenabled) @@ -38,7 +39,6 @@ browser.composeScripts.register({ }, ], }); - browser.runtime.onMessage.addListener(async (message, sender, callback) => { // Image added to body of message. Return a promise to the sender. if (message.type == "resizeFile") { @@ -53,6 +53,11 @@ browser.runtime.onMessage.addListener(async (message, sender, callback) => { if (message.type == "doResize") { doResize(message.tabId, message.maxWidth, message.maxHeight, message.quality); } + if (message.type == "getOptions") { + if(options.resizeInReplyForward) + await processAllAttachments(sender.tab,null,true); + return options; + } return undefined; }); @@ -122,12 +127,18 @@ browser.shrunked.onAttachmentContextClicked.addListener(async (tab, indicies) => // Message sending. browser.compose.onBeforeSend.addListener(async (tab, details) => { + await processAllAttachments(tab,details,false); +}); +async function processAllAttachments(tab, details,isOnDemand=false) { let result = {}; - let { resizeAttachmentsOnSend } = await browser.storage.local.get({ - resizeAttachmentsOnSend: false, - }); - if (!resizeAttachmentsOnSend) { - return result; + if(!isOnDemand) + { + let { resizeAttachmentsOnSend } = await browser.storage.local.get({ + resizeAttachmentsOnSend: false, + }); + if (!resizeAttachmentsOnSend) { + return result; + } } tabMap.delete(tab.id); @@ -136,7 +147,7 @@ browser.compose.onBeforeSend.addListener(async (tab, details) => { for (let a of attachments) { if (await shouldResize(a)) { let file = await browser.compose.getAttachmentFile(a.id); - let promise = beginResize(tab, file, false).then(async destFile => { + let promise = beginResize(tab, file, isOnDemand,false,true).then(async destFile => { if (destFile === null) { return; } @@ -152,14 +163,13 @@ browser.compose.onBeforeSend.addListener(async (tab, details) => { if (!promises.length) { return result; } - - await showOptionsDialog(tab); + if(!isOnDemand) + await showOptionsDialog(tab); await Promise.all(promises).catch(() => { result.cancel = true; }); return result; -}); - +} // Get a promise that resolves when resizing is complete. // For auto resize we need to know if the image isInline and if this is an event that should trigger auto resize. This method is called multiple times, not only when adding attachemnt function beginResize(tab, file, notification = true,isInline=false,shouldResizeAuto=false) { @@ -169,6 +179,7 @@ function beginResize(tab, file, notification = true,isInline=false,shouldResizeA } let sourceFiles = tabMap.get(tab.id); sourceFiles.push({ promise: { resolve, reject }, file }); + //check if autoResize is on and if current event should trigger it (shouldResizeAuto) and also if auto resize is turned on for this type of image (inline/attachment) if(options.autoResize!="off" && shouldResizeAuto && ((options.autoResize=="inline" && isInline) || (options.autoResize=="attached" && !isInline) || options.autoResize=="all")) { @@ -260,11 +271,14 @@ async function loadOptions(selectedOption=null) "options.logenabled":false, "options.contextInfo":true, "options.autoResize":"off", + "options.resizeInReplyForward":false, "default.maxWidth": 500, "default.maxHeight": 500, "default.quality": 75, "default.saveDefault": true, + "fileSizeMinimum": 100 }); + fileSizeMinimum=options['fileSizeMinimum']; defaults = { maxWidth: options['default.maxWidth'], maxHeight: options['default.maxHeight'], @@ -280,11 +294,12 @@ async function loadOptions(selectedOption=null) logenabled: options["options.logenabled"], contextInfo: options["options.contextInfo"], autoResize:options["options.autoResize"], + resizeInReplyForward:options["options.resizeInReplyForward"] }; } - return {"options":options,"defaults":defaults}; + return {"options":options,"defaults":defaults,"fileSizeMinimum":fileSizeMinimum}; } function cancelResize(tabId) { if (!tabMap.has(tabId)) { diff --git a/compose_script.js b/compose_script.js index 58d5428..dae654d 100644 --- a/compose_script.js +++ b/compose_script.js @@ -4,12 +4,27 @@ let config = { characterData: false, subtree: true, }; -let logenabled=false; +let resizeWhenForwardReply= false; +let logenabled = false; +async function startup(){ + browser.runtime.sendMessage({ + type: "getOptions", + }).then((response)=>{ + resizeWhenForwardReply=response["resizeInReplyForward"]; + logenabled = response["logenabled"]; + if(resizeWhenForwardReply) + parseInlineAtStart(); + }) + + + +} +startup(); let observer = new MutationObserver(function(mutations) { for (let mutation of mutations) { if (mutation.addedNodes && mutation.addedNodes.length) { if(logenabled) - console.log("Nodes added to message: " + mutation.addedNodes.length); + console.log("Nodes added to message: " + mutation.addedNodes.length); for (let target of mutation.addedNodes) { maybeResizeInline(target); } @@ -17,12 +32,19 @@ let observer = new MutationObserver(function(mutations) { } }); observer.observe(document.body, config); -browser.storage.local.get({ - "options.logenabled": false, -}).then((response) => + +async function parseInlineAtStart() { - logenabled = logenabled["options.logenabled"]; -}); + if(logenabled) + console.log(`parsing inline images at compose start`); + let existingInline=document.body.getElementsByTagName("IMG"); + for(let i=0;i { + console.error(err); + return; }); - if (destFile === null) { + + if (destFile === null || destFile === undefined) { return; } let destURL = await new Promise(resolve => { @@ -131,7 +157,7 @@ async function maybeResizeInline(target) { }; reader.readAsDataURL(destFile); }); - + target.setAttribute("src", destURL); target.removeAttribute("width"); target.removeAttribute("height"); diff --git a/content/config.js b/content/config.js index e7154be..4ff9107 100644 --- a/content/config.js +++ b/content/config.js @@ -33,6 +33,7 @@ async function getAll() { "options.logenabled":false, "options.contextInfo":false, "options.autoResize":"off", + "options.resizeInReplyForward": false, resizeAttachmentsOnSend: false, }); @@ -71,6 +72,7 @@ async function getAll() { cb_logenabled.checked=prefs["options.logenabled"] cb_contextInfoEnabled.checked=prefs["options.contextInfo"] s_autoResize.value=prefs["options.autoResize"] + cb_forwardReplyResize.checked=prefs["options.resizeInReplyForward"] // cb_logenabled.checked = prefs["log.enabled"]; s_resizeonsend.value = prefs.resizeAttachmentsOnSend; @@ -112,6 +114,7 @@ addEventListener("load", async () => { cb_logenabled.addEventListener("change", setCheckbox); cb_contextInfoEnabled.addEventListener("change", setCheckbox); s_autoResize.addEventListener("change", setAutoResizeOption); + cb_forwardReplyResize.addEventListener("change", setCheckbox); browser.storage.onChanged.addListener(() => { if (!settingFromThisPage) { getAll(); @@ -191,4 +194,4 @@ async function setAutoResizeOption() { "options.autoResize": s_autoResize.value, }); settingFromThisPage = false; -} +} \ No newline at end of file diff --git a/content/config.xhtml b/content/config.xhtml index e5de78e..69421d3 100644 --- a/content/config.xhtml +++ b/content/config.xhtml @@ -65,6 +65,7 @@ +