Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.
Jiacai Liu edited this page Mar 16, 2023 · 3 revisions

Welcome to the gooreplacer wiki!

默认规则测试

在浏览器地址栏中输入以下链接,如果能转到 lug.ustc.edu.cncdn.rawgit.com 相应的资源即说明替换成功。

支持的协议

The webRequest API only exposes requests that the extension has permission to see, given its host permissions. Moreover, only the following schemes are accessible: http://, https://, ftp://, file://, ws:// (since Chrome 58), wss:// (since Chrome 58), or chrome-extension://.

定义规则

Currently gooreplacer support 4 functions. Take one exported rules as example:

{
  "createBy": "https://github.com/jiacai2050/gooreplacer",
  "version": "2.0",
  "createAt": "Sun Oct 29 2017 19:55:32 GMT+0800 (CST)",
  "redirect-rules": [
    {
      "src": "ajax.googleapis.com",
      "dst": "ajax.proxy.ustclug.org",
      "kind": "wildcard",
      "enable": true
    }
  ],
  "cancel-rules": [
    {
      "src": "facebook.com",
      "kind": "wildcard",
      "enable": true
    }
  ],
  "request-headers": [
    {
      "src": "google.com",
      "kind": "wildcard",
      "name": "user-agent",
      "value": "gooreplacer",
      "op": "modify",
      "enable": true
    }
  ],
  "response-headers": [
    {
      "src": "google.com",
      "kind": "wildcard",
      "name": "Cookie",
      "op": "cancel",
      "enable": true
    }
  ]
}
  • redirect-rules used for redirects
  • cancel-rules used for blocks
  • request-headers used for modify/cancel http request headers
  • response-headers used for modify/cancel http response headers

In each rule,

  • src limit which request it will work on, and it has two types: wildcard and regexp, which is defined in kind key.
  • dst only required in redirects, means destination
  • enable turn on/off
  • op required in request-headers response-headers, has two enum value: cancel or modify
  • name, value required in request-headers response-headers, means header name(case-insensitive), header value

In redirects, you can use $1 $2 ... to backreference captured groups in case of regexp kind. For example:

{
  "src": "https://search.yahoo.com/search\?p=([a-z]+)",
  "dst": "https://www.google.com/search?q=$1",
  "kind": "regexp",
  "enable": true
}

Then https://search.yahoo.com/search?p=gooreplacer will redirect to https://www.google.com/search?q=gooreplacer

If your rules don't work as expected, use sandbox to test, it can tell what's missing.

NOTE

  • In order to be compatiable with old versions, redirect-rules key in JSON-rules file can be just rules and have following format:

    "rules": {
      "ajax.googleapis.com": {
        "dstURL": "ajax.proxy.ustclug.org",
        "enable": true,
        "kind": "wildcard"
      }
    }
    
  • According to Google Extension document,headers below can't be modified:

    • Authorization
    • Cache-Control
    • Connection
    • Content-Length
    • Host
    • If-Modified-Since
    • If-None-Match
    • If-Range
    • Partial-Data
    • Pragma
    • Proxy-Authorization
    • Proxy-Connection
    • Transfer-Encoding
Clone this wiki locally