如何为Imagus hover zoom extension开发自定义滤镜? [英] How to develop custom filters for the Imagus hover zoom extension?

查看:125
本文介绍了如何为Imagus hover zoom extension开发自定义滤镜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我读到有关 。



  



我认为自己精通Javascript,DOM和正则表达式,但尝试猜测这是做什么只是痛苦,所以我寻找文档。好像有一个 MyOpera博客,现在是项目的网站暂时托管在Google文档上。



该页面没有提到任何关于如何开发过滤器(或筛子,如该页面中所写的那样?)



所以,如何开发一个自定义过滤器?我不知道所有的可能性(它似乎非常灵活),但即使只是修改URL这样的简单例子也会很好。 (将 /thumb/123.jpg 转入 /large/123.jpg 或其他)。



甚至只是字段的解释。它们似乎是:




  • link

  • url

  • res

  • img

  • to

  • note < - 可能评论


解决方案

fieds可以包含JavaScript函数或Regex。




  • link可以显示您悬停的任何链接的地址。

  • url使用链接字段中捕获的括号值来创建网址。

  • res重新获取url或链接指向的任何文本页面。



如果其中一个为空,则跳过该步骤,例如没有url和res只是从链接的输出加载。

一个简单的例子是xkcd过滤器:

链接:

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

查找xkcd漫画的链接。如果您不熟悉正则表达式,则括号之间的任何内容都会被保存,并且可以在Imagus中用作$ n来表示第n次捕获。请注意,如果第一个括号后面有?:则不会被捕获。



url:

  $ 1 / info.0.json 

这只是将/info.0.json附加到链接的地址。



res:

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

此javascript函数解析JSON文件并返回一个数组,其中第一个元素是链接,第二个元素是链接是在hoverzoomed图像下显示的标题文本。
如果您只返回一个链接,那么标题将是该链接的替代文字。




  • img用作链接是,但对于图像来源

  • 来用作res或url是



一个简单的用途case是您想要从缩略图重定向到雇用的时间。
喜欢wikimapia.org的过滤器。

img:

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

这会找到名称中没有大字的任何维基马皮亚图片。

to:

  $ 1big 

增加大量到网址。




  • 注意仅供注释。



有些过滤器在这里有指向API文档的链接。



现在,还没有关于此功能的文档,所以我可能错过了很多,但很快就会足够。



干杯。


After I read about Hover Zoom being evil (yikes!), two articles made me instantly switch to another one, called Imagus:

Imagus seems to fit the bill by doing pretty much what Hover Zoom also could, but in addition, it seems to support custom filters (to support more sites), in addition to the huge bunch it already comes packed with.

In the options page, on Chrome, the filters section looks deliciously hackable:

  

However, at the same time, it seems to be written in what I would call Perl Javascript.

  

I consider myself well-versed in Javascript, DOM and Regex, but it's just painful to try to guess what that is doing, so I looked for documentation. It seems like there was an MyOpera blog, and now the website of the project is, for the time being, hosted on Google Docs.

The page doesn't mention anything about how to develop "filters" (or "sieves", as written in that page?)

So, how can I develop a custom filter? I'm not aware of all the possibilities (it seems to be pretty flexible), but even a simple example like just modifying URLs would be good. (turning /thumb/123.jpg into /large/123.jpg or something).

Or even just an explanation of the fields. They seem to be:

  • link
  • url
  • res
  • img
  • to
  • note <- Probably Comment

解决方案

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.

这篇关于如何为Imagus hover zoom extension开发自定义滤镜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆