请翻译这个 JavaScript 胡言乱语? [英] Translate this JavaScript Gibberish please?

查看:47
本文介绍了请翻译这个 JavaScript 胡言乱语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改和更新旧的 Greasemonkey 脚本,目标是自动向所有亚马逊链接添加会员 ID.我是 JavaScript 的新手,但我通常很擅长修改任何语言的现有脚本.这里只有一行令我无法理解.

I'm trying to modify and update an old Greasemonkey script with the goal of automatically adding an affiliate ID to all Amazon links. I'm a novice when it comes to JavaScript, but I'm usually pretty good about modifying existing scripts in any language. There's just one line here that I can't wrap my head around.

我开始用的脚本已经过时了,不知道是语法有问题还是链接格式有变化.有人可以帮我了解这条线在做什么,以便我可以对其进行更改吗?

The script I started with is outdated, so I don't know if there is a problem with the syntax or if the link format has changed. Can somebody please help me understand what this line is doing so I can make changes to it?

const affiliateLink = /(obidos.(ASIN.{12}([^\/]*(=|%3D)[^\/]*\/)*|redirect[^\/]*.(tag=)?))[^\/&]+/i;

推荐答案

好吧,你问的 :)

开始正则表达式:

/

开始群组操作:

(

搜索文本obidos"后跟任意单个字符

Search for the text "obidos" followed by any single character

奥比都斯.

打开另一个组操作符:

(

搜索文本ASIN"后跟任意 12 个字符

Search for the text "ASIN" followed by any 12 characters

ASIN.{12}

另一组操作:

(

后跟 0 个或多个非斜杠字符:

Followed by 0 or more characters that are not slashes:

[^\/]*

搜索 '=' 字符或 url 编码的 '=' (%3D) 的组操作:

Group operation searching for an '=' character or a url encoded '=' (%3D):

(=|%3D)

后跟 0 个或多个非斜杠字符:

Followed by 0 or more characters that are not slashes:

[^\/]*

后跟斜杠(并关闭当前组),可以重复 0 次或多次:

Followed by slash (and closes the current group), which can be repeated 0 or more times:

\/)*

如果找到前一组或匹配栏右侧的所有内容,则允许模式匹配:

Allows the pattern to match if the previous group was found OR everything to the right of the bar is matched:

|

匹配文本重定向"后跟 0 个或多个非斜杠字符:

Matches the text "redirect" followed by 0 or more chatacters that are not a slash:

重定向[^\/]*

匹配任何单个字符,后跟可选的文本tag=":

Matches any single character, followed optionally by the text "tag=":

.(tag=)?

关闭我们目前仍在其中的两个组操作:

Closes the two group operations we're currently still inside of:

))

后跟一个或多个不是斜杠或 & 的字符:

Followed by one or more characters that are not a slash or &:

[^\/&]+

[^\/&]+

关闭正则表达式:

/

这篇关于请翻译这个 JavaScript 胡言乱语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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