Skip to content

Commit

Permalink
feat: add the ability to save multiple images
Browse files Browse the repository at this point in the history
using the new saveImageHint keybind.
  • Loading branch information
Jake Mannens authored and b-coimbra committed May 22, 2022
1 parent 0765eb3 commit 9acad46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions background_scripts/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
4 changes: 4 additions & 0 deletions content_scripts/hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)',
Expand Down
1 change: 1 addition & 0 deletions content_scripts/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9acad46

Please sign in to comment.