Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]我这重定向的自定义函数写对了吗? #262

Closed
daiaji opened this issue Mar 11, 2024 · 1 comment
Closed

[Question]我这重定向的自定义函数写对了吗? #262

daiaji opened this issue Mar 11, 2024 · 1 comment

Comments

@daiaji
Copy link

daiaji commented Mar 11, 2024

匹配^http(?:s?)://www\.google\.com/url\?q=.*

const regex = /url\?q=(https?:\/\/.*?)&.*/;
const match = val.match(regex);
if (match) {
  const capturedURL = match[1];
  return decodeURIComponent(capturedURL);
}

函数是这样。

{
	"request": [
		{
			"enable": true,
			"name": "去除Google重定向",
			"ruleType": "redirect",
			"matchType": "regexp",
			"pattern": "^http(?:s?)://www\\.google\\.com/url\\?q=.*",
			"exclude": "",
			"group": "未分组",
			"isFunction": true,
			"action": "redirect",
			"to": "https://gstatic.loli.net/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxK.woff2",
			"code": "const regex = /url\\?q=(https?:\\/\\/.*?)&.*/;\nconst match = val.match(regex);\nif (match) {\n  const capturedURL = match[1];\n  console.log(\"Captured URL:\", capturedURL); // 添加控制台打印\n  return decodeURIComponent(capturedURL);\n}"
		}
	],
	"sendHeader": [],
	"receiveHeader": [],
	"receiveBody": []
}
@daiaji
Copy link
Author

daiaji commented Mar 11, 2024

{
	"request": [
		{
			"enable": true,
			"name": "去除Google重定向",
			"ruleType": "redirect",
			"matchType": "regexp",
			"pattern": "^http(?:s?)://www\\.google\\.com/url\\?q=.*",
			"exclude": "",
			"group": "CingList-Redirect",
			"isFunction": true,
			"action": "redirect",
			"to": "https://gstatic.loli.net/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxK.woff2",
			"code": "function extractURL(url) {\n  const regex = /url\\?q=(https?:\\/\\/.*?)&/;\n  const decodedVal = decodeURIComponent(url);\n  const match = decodedVal.match(regex);\n  return match ? match[1] : null;\n}\n\nreturn extractURL(val);"
		}
	],
	"sendHeader": [],
	"receiveHeader": [],
	"receiveBody": []
}

这才是正确写法。

@daiaji daiaji closed this as completed Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant