我在rules.json中使用的是rules.json,但是它似乎只能添加或替换键值对,但是我只想修改键名,有什么方法可以做到吗?例如,我希望将param名称postID修改为po。https://www.blogger.com/comment/frame/5235590154125226279?postID=9028051665011570908&hl=zh-CN&blogspotRpcToken=942236&parentID=7864247129676677521#
,这是我的rules.json,它可以很好地重定向,但是我不知道如何获得原始url的值9028051665011570908
[{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"transform": {
"queryTransform": {
"removeParams": ["postID"],
"addOrReplaceParams": [
{
"key": "po",
"value": how to gain postID's value
}
]
}
}
}
},
"condition": {
"urlFilter": "blogger.com/comment/frame",
"resourceTypes": ["main_frame"]
}
}]
我读过下面的文档,但找不到3-72-0-dot-chrome-apps-doc.appspot.com developer.chrome.com的任何解决方案。
发布于 2022-11-04 11:08:02
没有这样的操作,所以您可以建议在https://crbug.com上实现它。
解决办法是使用regexFilter + regexSubstitution。
它通常要慢一些,但是对于这种简单的表达式,特别是如果我们指定requestDomains
来限制规则的话,它的速度不会太大。
[{
"id": 1,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "\\1po="
}
},
"condition": {
"requestDomains": ["blogger.com"],
"regexFilter": "(/comment/frame[^#]*?[?&])postID=",
"resourceTypes": ["main_frame"]
}
}]
要测试表达式,可以使用devtools控制台:
"https://www.blogger.com/comment/frame?postID=123"
.replace(RegExp("(/comment/frame[^#]*?[?&])postID="),
"\\1po=".replace(/\\(?=\d)/g, '$'))
发布于 2022-11-05 23:25:34
这是我的rules.json
[{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"transform": {
"queryTransform": {
"removeParams": ["postID"],
"addOrReplaceParams": [
{
"key": "po",
"value": how to gain postID's value 9028051665011570908
}
]
}
}
}
},
"condition": {
"urlFilter": "blogger.com/comment/frame",
"resourceTypes": ["main_frame"]
}
}]
https://stackoverflow.com/questions/74311890
复制相似问题