How to develop custom filters for the Imagus hover zoom extension?

一曲冷凌霜 提交于 2019-12-02 18:28:12

The fieds can contain a JavaScript function or a Regex.

  • link recives the address of any link you hover over.
  • url uses captured parentheses values from the link field to make an url.
  • res recives whatever page, in text, that was pointed to by url or link.

If one of them is empty, that step is skipped, e.g. no url and res just loads from link's output.
A simple example is the xkcd filter:
link:

^(xkcd\.(?:org|com)/\d{1,5})/?$

Finds links to xkcd comics. If you're unfamiliar with regex, anything between the parentheses is saved and can be used in Imagus as "$n" to refer to the nth capture. Note that if there's a "?:" after the first parentheses it wont get captured.

url:

$1/info.0.json

This simply appends "/info.0.json" to the address from link.

res:

:
if ($._[0] != '{') $ = null;
else $ = JSON.parse($._), $ = [$.img, [$.year, ('0'+$.month).slice(-2),
('0'+$.day).slice(-2)].join('-') + ' | ' + $.safe_title + ' - ' + $.alt + ' ' +
$.link];
return $;

This javascript function parses the JSON file and returns an array where the first element is the link and the second is the caption text displayed under the hoverzoomed image. If you return just a link then the caption will be the alt text of the link.

  • img is used as link is, but for image sources
  • to is used as res or url is

A simple use case is when you want to redirect from thumbnails to hires. Like the filter for wikimapia.org.
img:

^(photos\.wikimapia\.org/p/[^_]+_(?!big))[^.]+

This finds any wikimapia image that doesn't have big in the name.
to:

$1big

Adds big to the url.

  • note is just for notes.

Some filters have links to API docs here.

Now, there's no documentation for this feature yet so I probably missed a lot, but hopfully it'll be enough.

Cheers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!