fix: don't encode url for copy, support route param with regex (#1017)

* fix: don't encode url for copy

* fix: always rendering

* fix: support route with regex
This commit is contained in:
Stephen Zhou
2024-06-13 23:07:26 +08:00
committed by GitHub
parent 096589db99
commit 97d7470201
2 changed files with 10 additions and 2 deletions
+7
View File
@@ -17,6 +17,13 @@ function ruleHandler(rule: Rule, params, url, html, success, fail) {
resultWithParams = rule.target
}
// clean params with regex requirements
// /npm/package/:name{(@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*} -> /npm/package/:name
resultWithParams = resultWithParams.replace(
/\/:\w+\{[^}]*\}(?=\/|$)/g,
(match) => match.replace(/\{[^}]*\}/, ""),
)
if (resultWithParams) {
// if no :param in resultWithParams, requiredParams will be null
// in that case, just skip the following steps and return resultWithParams
+3 -2
View File
@@ -19,7 +19,9 @@ function RSSItem({
hidePreview?: boolean
}) {
const [config, setConfig] = useState(defaultConfig)
getConfig().then(setConfig)
useEffect(() => {
getConfig().then(setConfig)
}, [])
const [_, copy] = useCopyToClipboard()
const [copied, setCopied] = useState(false)
useEffect(() => {
@@ -43,7 +45,6 @@ function RSSItem({
chrome.i18n.getMessage("current"),
)
}
url = encodeURI(url)
const encodedUrl = encodeURIComponent(url)
return (