Coder Social home page Coder Social logo

mcdamo / tab-image-saver Goto Github PK

View Code? Open in Web Editor NEW
39.0 9.0 14.0 2.41 MB

Firefox addon to save images from open tabs

Home Page: https://addons.mozilla.org/firefox/addon/tab-image-saver/

License: Mozilla Public License 2.0

JavaScript 96.62% CSS 3.20% HTML 0.19%

tab-image-saver's Introduction

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.

  • Multitasking Support - run addon concurrently in separate windows
  • Keyboard shortcut options
  • Select from active tab, tabs to the left/right of current tab, or all tabs.
  • Cancel running operations
  • Set minimum image size in pixels
  • Option to only save tabs with images, ignoring tabs with webpages
  • Filenames renamed automatically
  • Display badge on icon with runtime information and count of downloads
  • Close tabs after saving
  • Hide saved images from download history
  • Show notification when complete

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.

  • sanitizeFile("string", "_") removes all slashes and replaces illegal characters with underscores to create a valid filename.
  • sanitizePath("string", "_") replaces illegal characters with underscores and retains slashes to allow multi-level folders.

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:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.