Home > Net >  In chrome extension manifest v3, how to change only params key name but still use the origin value w
In chrome extension manifest v3, how to change only params key name but still use the origin value w

Time:11-05

I'm using addOrReplaceParams in rules.json, but it seems that it can only add or replace key-value pairs, but i just want modify the key name,is there any way to do this? For example, i want to modify the param name postID to po. https://www.blogger.com/comment/frame/5235590154125226279?postID=9028051665011570908&hl=zh-CN&blogspotRpcToken=942236&parentID=7864247129676677521# And this is my rules.json, it redirect well, but i dont know how to gain the origin url postID's value 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"]
  }
}]

I have read the doc below, but i cant find any solutions 3-72-0-dot-chrome-apps-doc.appspot.com developer.chrome.com

CodePudding user response:

There's no such action, so you can suggest implementing it on https://crbug.com.

The workaround is to use regexFilter regexSubstitution.

It's generally slower, but for simple expressions like this one not by much, especially if we specify requestDomains to limit the rule.

[{
  "id": 1,
  "action": {
    "type": "redirect",
    "redirect": {
      "regexSubstitution": "\\1po="
    }
  },
  "condition": {
    "requestDomains": ["blogger.com"],
    "regexFilter": "(/comment/frame[^#]*?[?&])postID=",
    "resourceTypes": ["main_frame"]
  }
}]

To test the expression you can use devtools console:

"https://www.blogger.com/comment/frame?postID=123"
  .replace(RegExp("(/comment/frame[^#]*?[?&])postID="),
     "\\1po=".replace(/\\(?=\d)/g, '$'))
  • Related