From 254084fbca929395eac9100fa4738a16689b029a Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Fri, 13 Sep 2019 02:22:34 +1000 Subject: [PATCH 1/2] Added the ability to save multiple images using the new saveImageHint keybind. --- background_scripts/actions.js | 6 ++++++ content_scripts/hints.js | 4 ++++ content_scripts/mappings.js | 1 + 3 files changed, 11 insertions(+) diff --git a/background_scripts/actions.js b/background_scripts/actions.js index 96b8591b..42ea8030 100644 --- a/background_scripts/actions.js +++ b/background_scripts/actions.js @@ -85,6 +85,12 @@ Actions = (function() { } }; + _.saveImage = function(o) { + var filename = o.url.replace(/(.*\/|\?.*)/g, '') + console.log('Attempting to save image ' + filename + ' (' + typeof(filename) + ')'); + chrome.downloads.download({ url: o.url, filename: filename, saveAs: false }); + }; + _.addFrame = function(o) { Frames.add(o.sender.tab.id, o.port, o.request.isCommandFrame); }; diff --git a/content_scripts/hints.js b/content_scripts/hints.js index ad6556b6..b83d3ccc 100644 --- a/content_scripts/hints.js +++ b/content_scripts/hints.js @@ -140,6 +140,9 @@ Hints.dispatchAction = function(link, shift) { case 'fullimage': RUNTIME('openLinkTab', {active: false, url: link.src, noconvert: true}); break; + case 'saveimage': + RUNTIME('saveImage', {url: link.src,}); + break; case 'image': case 'multiimage': var url = 'https://www.google.com/searchbyimage?image_url=' + link.src; @@ -739,6 +742,7 @@ Hints.create = function(type, multi) { multiyank: '(multi-yank)', image: '(reverse-image)', fullimage: '(full image)', + saveimage: '(save image)', tabbed: '(tabbed)', tabbedActive: '(tabbed)', window: '(window)', diff --git a/content_scripts/mappings.js b/content_scripts/mappings.js index a7de76f6..769c28d1 100644 --- a/content_scripts/mappings.js +++ b/content_scripts/mappings.js @@ -438,6 +438,7 @@ Mappings.actions = { yankUrl: function() { Hints.create('yank'); }, multiYankUrl: function() { Hints.create('multiyank'); }, fullImageHint: function() { Hints.create('fullimage'); }, + saveImageHint: function() { Hints.create('saveimage'); }, yankDocumentUrl: function() { RUNTIME('getRootUrl', function(url) { Clipboard.copy(url); From 7b98cd04786d68a6fe03b06b716d620227cc76da Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Fri, 13 Sep 2019 03:04:17 +1000 Subject: [PATCH 2/2] Remove debug console.log() --- background_scripts/actions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/background_scripts/actions.js b/background_scripts/actions.js index 42ea8030..4feac212 100644 --- a/background_scripts/actions.js +++ b/background_scripts/actions.js @@ -87,7 +87,6 @@ Actions = (function() { _.saveImage = function(o) { var filename = o.url.replace(/(.*\/|\?.*)/g, '') - console.log('Attempting to save image ' + filename + ' (' + typeof(filename) + ')'); chrome.downloads.download({ url: o.url, filename: filename, saveAs: false }); };