mcdamo / tab-image-saver

Firefox addon to save images from open tabs
https://addons.mozilla.org/firefox/addon/tab-image-saver/
Mozilla Public License 2.0
40 stars 13 forks source link

tab-image-saver Addon Version Build Status

Tab Image Saver is a Firefox addon that makes it easy to save images from browser tabs you have open.

Download from Firefox Addons.

Features

By default this addon saves the largest image found on the active tab.

You may control how this functions by changing the addon preferences at in Firefox > Add-ons > Extensions > Tab Image Saver > Preferences or right-click the toolbar icon.

Path rules

Path rules are a flexible method for setting the image filenames when downloading.

The Path rules syntax is based off template strings, this will be familiar to anyone who has coded Javascript.

Path rules are processed top-down: if the first rule does not evaluate to a valid path then it will proceed to the next rule in the list and so on.

Variables

The following variables are available for use in Path rules

Variable Description Example*
alt image's alt content Caption
name image's url filename without extension filename
xName image's filename from Content-Disposition header filename
ext image's url extension jpg
xExt image's extension from Content-Disposition header jpg
xMimeExt image's extension from Content-Type header jpg
host image's url hostname example.com
path image's url path path/to
index image number starting at '1', incremented for each image 1
tabTitle tab's page title (JPEG Image, 500 x 500 pixels)
tabHost tab's url hostname example.com
tabPath tab's url path path/to
tabFile tab's url filename without extension filename
tabExt tab's url extension jpg

*Example source:

<img src="http://example.com/path/to/filename.jpg" alt="Caption">

Boolean logic

Empty variables can be skipped with boolean logic using double-pipe: ||

Example
${name}.${ext||xExt||xMimeExt||'jpg'}

This will attempt to find the filename extension from the URL, Content-Disposition header, Content-Type header, and finally if all else fails will use jpg

Methods

String methods can be chained to variables or strings in the Path rule.

Zero padding

The padStart method can be used to string pad the index variable.

Example
img_${index.padStart(4, 0)}.jpg

This will use the index of the image in the active download session. The index is incremented for each image saved and processed in tab order. The output will be zero padded, such as img_0001.jpg

String replacement and regular expressions

The replace method can use regular expresions on variables.

Example

Using replace(), if alt variable contains a pipe symbol | then it and any trailing characters are removed:

${alt.replace(/\s*\|.*/, '')}

Path sanitization helpers

Path sanitization helper methods will quickly remove most problematic characters from a string.

Rulesets

Rulesets can apply rules and options to a specific domain or url of the tab page.

Rulesets are tested in order from top to bottom. Any pages that are unmatched by a Ruleset will default to the Global settings.

The standard form of domain rule allows for simple wildcard matching (*).

Domain rules can also be interpreted as a regular expression by wrapping in hash characters (#).

Matching domains

The following examples are for https://example.com/page.html

Domain rule Match
example.com/ Yes
example.co Yes
example.co/ No
ample.com/ Yes
e*e.com/ Yes
/page.html Yes
#//example.[^/]{3}/# Yes

Download method

The download method does not need to be changed unless you are using the cache workaround or having issues with downloads.

Method Advantages Disadvantages
Fetch fast cancellation does not use cache #91
Content-fetch (default) multi-account containers; cache-workaround slowest
Download multi-account containers; cache-workaround; fastest Clear download history does not work #93

FAQ

Filenames are _name_._ext_

Path rules are not in the latest format. Follow the update instructions

Cache is not used

Since Firefox 85.0 the network partitioning means that the addon cannot access the browser cache and images are re-fetched from the network for every download.

This security feature can be disabled to improve download performance by editing Firefox config:

about:config -> privacy.partition.network_state -> false

Images fail to download

If images load in the browser but fail to download this is often caused by Tracking Protection.

In Firefox settings try reducing the protection level from Strict or adding a site exception.

Acknowledgements

Libraries:

Graphics: