Skip to content

Instantly share code, notes, and snippets.

@disco0
Last active November 25, 2023 10:34
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save disco0/e6b210aff85ddc0bbf9e0eedeb989a03 to your computer and use it in GitHub Desktop.
Save disco0/e6b210aff85ddc0bbf9e0eedeb989a03 to your computer and use it in GitHub Desktop.
Imagus Sieve #doc

Imagus Seive Configuration

A basic outline on seive configuration in Imagus—based on previous posts by developer, with additions based on own usage.

Extension Implementation

Input Processing

Before it's sent to matching, every URL has its protocol and subdomain removed using the following regex:

/^https?:\/\/(?:www\.)?/

This is to allow the use of ^. If you don't start to with a protocol, it will be readded later. For example, the url https://some.url/thumbnail.jpg will be sent to the seive as some.url/thumbnail.jpg.


Fields

link

Regex match expression applied to the href attribute of a link (anchor tag).

url

Replacement.

Only active when res is set (next parameter). Generates a URL for res instead of using the link or image address.

res

Regex match expression.

If there is no way to get the larger image address with link or img, this will load the page (if url parameter is not set, then the link or image address is used, otherwise the url replace) in background and will parse the content, and match the image URL.


res Field Details

res has different effects based on input:

Basic Formats:

  • Regexp: First group from the match will be the full image URL.

  • Regexp - Multiple groups: Starting with the second group, captures will be concatenated to be used as caption.

  • Second Line Additional Regexp: First group from the second regex match will be the caption.

JavaScript:

JavaScript can be evaluated by beginning with a colon and newline, like so:

:

A $ variable will be available in that piece of code, which holds the resolved content, including the $._ property.

Return Values:

  • Falsy values: Triggers the yellow spinner.
  • String: Resolved URL.
  • URL + Caption Array [URL, caption]
  • Array of URL + Caption arrays: Gallery

img

Regex matching the src attribute of an IMG tag or style (eg. background-image: url(thumbnail)) for any elements.

to

to can have multiple lines, every one of them will be converted to a result URL. If # is the first character in a line then it marks the URL as hi-res.

If # is not the first then it may be followed by space separated strings closed by a # sign again. This will generate URLs for every variant. E.g. //some.url/path/full-image.#jpg png gif#, which will generate three URLs, testing them in order.

Also, at the end of the line you can add #{media_extension}, so the the extension will recognize it as video or audio, instead of image (default). E.g., https://some.url/path/without/extension?id=13#mp4

The :\n works in here as well (but the $ value there will have only the matched groups).

Javascript RegExp can be used with the builtin constructor:

RegExp('yourRegexInput')

The conversion happens with a simple URL.replace(yourRegex, rule.to).

note

Notes.

Options

Loop

image

It will recheck the result, e.g., a Google image link may point to a twitter thumbnail, and if you enable loop on Google images, then the resolved twitter thumbnail will be checked again, so it can get the larger image.

Decode URL

Some providers, like Bing, Yandex, etc. puts the encoded image address as a parameter in the URL.

Use img parameter

if both link and res or img are set, then img will be preferred.


Sources

Reddit Post

Taken from replies of this post.

First Reply

to can have multiple lines, every one of them will be converted to a result URL. If # is the first character in a line then it marks the URL as hi-res.

If # is not the first then it may be followed by space separated strings closed by a # sign again. This will generate URLs for every variant. E.g. //some.url/path/full-image.#jpg png gif#, which will generate three URLs, testing them in order.

Also, at the end of the line you can add #{media_extension}, so the the extension will recognize it as video or audio, instead of image (default). E.g., https://some.url/path/without/extension?id=13#mp4

Javascript RegExp is used (obviously). In the code it's simply RegExp('yourRegexInput'). The conversion happens with a simple URL.replace(yourRegex, rule.to).

res has different formats. If you simply write a regexp there, then the first group from the match will be the full image URL. If you have multiple groups, then starting with the second they will be concatenated to be used as caption. If you write a second regexp in a new line, then it's first group from the match will be the caption.

If res starts with :\n (so colon plus new line) then you can write JavaScript code there, and do whatever you want. A $ variable will be available in that piece of code, which holds the resolved content for example ($._). From res you can return null, this will make the spinner yellow. Other falsy values will hide the spinner. You can return a string, that will be the URL. An array with two members [URL, caption]. An array with multiple of the previous is an album.

The :\n works in to as well (but the $ value there will have only the matched groups).

From every URL, before it's sent to matching, the https?://(www\.)? part is removed (and added to the result URL later, if you don't start to with a protocol). So, you're basically matching some.url/thumbnail.jpg instead of https://some.url/thumbnail.jpg. The reason for this is to allow the use of ^ (which you already noticed).

Second Response

Well, I'm the lazy kind who doesn't write documentation. I've always wanted to though...

link matches the href attributes from a tags (so, something that is a page, and not a direct media file/thumbnail). img matches src from img tag (some something that is known to be an image file).

If res is used then link will be resolved. If you don't want to use link you can use the url parameter to modify the URL which will be resolved.

Possible (basic) combinations: (link or img) > to (both can be set at the same time and they would resolve to to, link with higher priority), (img or img) (> url)? > res, if link, res, img, and to is set at the same time, then link will be paired with res, and img with to.

The checkboxes beside the link and img have tooltips. The case-insensitiveness applies to the regex, the loop and decodeURI applies to the result URL.

Forum Post

I will, when the time comes. Though, the basics probably won't change much, so...

Practically regular expressions is the only knowledge , need to have (and a bit Javascript and HTML.). Parameters:

link

Regex, working on "href" attribute of a link (anchor tag).

url

replacement, it has meaning only when 'res. (next parameter) is set. Generates a URL for 'res. if , need other, instead of link or image address.

res

regex match, if there is no way to get the larger image address with link' or Img", this will load the page (if Lir parameter is not set, then the link or image address is used, otherwise the .urP replace) in background and will parse the content, and match the image URL.

img

Regex, in for src attribute of an IMG tag or style, background-image: url(thumbnail) for any elements.

to

(Multiple) replacement or function, a link or image address will be replaced this based on link or img.

note

Notes.

Loop

It will recheck the result, e.g., a Google image link may point to a twitter thumbnail, and if you enable loop on Google images, then the resolved twitter thumbnail will be checked again, so it can get the larger image.

Decode URL

Some providers, like Bing, Yandex, etc. puts the encoded image address as a parameter in the URL.

Use img parameter

if both link and res or img are set, then img will be preferred.

Additional Info

Rules dont' belong to specific sites, so all rules will be checked on any site when you hover your mouse on a link or thumbnail-like object. If no link parameter set/matched, and img is present, then img will be used on link address as well (this is when someone links to a thumbnail image), so no need to set the same value for link and img, it's enough for the img (at least, this feature will be introduced) in v0.8.10).


Corrections and addtional information welcome (especially from dev).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment