diff --git a/chrome/just-save.js b/chrome/just-save.js index 6cd3c83..57af295 100644 --- a/chrome/just-save.js +++ b/chrome/just-save.js @@ -1,4 +1,10 @@ 'use strict'; +// FIXME: need to keep this on a separate codebase due to +// need for separate manifest file because persistent attribute is rejected +// https://bugzilla.mozilla.org/show_bug.cgi?id=1253565 +// should be able to revert to single codebase when Firefox 48 is released + +// FIXME: figure out how to prevent toolbar icon from being added in chrome // adding browser shim for chrome support window.browser = chrome; @@ -20,46 +26,44 @@ browser.runtime.onInstalled.addListener(event => { browser.contextMenus.removeAll(result => { logResult(result); - const handleMenuClick = clickContext => { - if (clickContext.menuItemId !== 'just-save') { - return; - } - - const url = clickContext.srcUrl || clickContext.linkUrl || clickContext.pageUrl; - - if (!url) { - return console.error(`No url found for current click context`); - } - - const filename = undefined; - - const downloadOptions = { - url, - filename - // filename, - // conflictAction: 'prompt', //not implemented yet in firefox, defaults to uniquify - // saveAs: false //not implemented yet in firefox, defaults to false - }; - - browser.downloads.download( - downloadOptions, - logResult - ); - }; - const menuProperties = { id: 'just-save', title: 'Just Save', contexts: ['all'] }; - + browser.contextMenus.create( menuProperties, logResult ); - - // FIXME: appears to stop working after restarting chrome - // might need to add another listener for a different event - browser.contextMenus.onClicked.addListener(handleMenuClick); }); }); + +const handleMenuClick = clickContext => { + if (clickContext.menuItemId !== 'just-save') { + return; + } + + const url = clickContext.srcUrl || clickContext.linkUrl || clickContext.pageUrl; + + if (!url) { + return console.error(`No url found for current click context`); + } + + const filename = undefined; + + const downloadOptions = { + url, + filename + // filename, + // conflictAction: 'prompt', //not implemented yet in firefox, defaults to uniquify + // saveAs: false //not implemented yet in firefox, defaults to false + }; + + browser.downloads.download( + downloadOptions, + logResult + ); +}; + +browser.contextMenus.onClicked.addListener(handleMenuClick); \ No newline at end of file diff --git a/chrome/manifest.json b/chrome/manifest.json index 6ef2c9a..a7d6c6b 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Just Save", - "version": "0.0.1", + "version": "0.0.2", "description": "A simple WebExtension for skipping the \"Save As\" dialog when saving images, pages and links.", "icons": { diff --git a/firefox/manifest.json b/firefox/manifest.json index 5c6a1fc..5d74bcc 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Just Save", - "version": "0.0.1", + "version": "0.0.2", "description": "A simple WebExtension for skipping the \"Save As\" dialog when saving images, pages and links.", "icons": {