Skip to content

Commit

Permalink
增强链接匹配,支持URL Scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
ipuppet committed Jan 20, 2024
1 parent 15d3038 commit 9857458
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"info": {
"name": "CAIO",
"version": "2.2.4",
"version": "2.2.5",
"author": "ipuppet",
"module": false
},
Expand Down
15 changes: 13 additions & 2 deletions scripts/action/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,20 @@ class Action {
}

getUrls() {
const regex = /(https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})([:0-9])*([\/\w\#\.\-\?\=\&])*\s?/gi
const text = this.text ?? ""
return text.match(regex) ?? []

const httpRegex = /https?:\/\/[\w-]+(\.[\w-]+)*([\p{Script=Han}\w.,@?^=%&:/~+#()\-]*[\w@?^=%&/~+#()\-])?/giu
// 正则表达式用于匹配iOS URL Scheme(假设scheme后面是://),包括中文字符和括号
const iosSchemeRegex = /\b\w+:\/\/[\w-]+(\.[\w-]+)*([\p{Script=Han}\w.,@?^=%&:/~+#()\-]*[\w@?^=%&/~+#()\-])?/giu

// 使用正则表达式查找匹配项
const httpUrls = text.match(httpRegex) || []
const iosUrls = text.match(iosSchemeRegex) || []

// 合并两个数组并去重
const allUrls = [...new Set([...httpUrls, ...iosUrls])]

return allUrls
}

addinRun(name) {
Expand Down

0 comments on commit 9857458

Please sign in to comment.