FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
FluentRead/userscript/settingsPage.ts at main · FluentRead/FluentRead · GitHub
FluentRead
/
FluentRead
Public
Notifications
You must be signed in to change notification settings
Fork
424
Star
8.2k
Code
Issues
12
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
FluentRead
/
userscript
/
settingsPage.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (28 loc) · 1.14 KB
Breadcrumbs
FluentRead
/
userscript
/
settingsPage.ts
Copy path
File metadata and controls
31 lines (28 loc) · 1.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* userscript 设置页的轻量路由标记。
*
* userscript 不能创建 chrome-extension://.../options.html,因此借用匹配网页的
* URL 打开一个独立标签页;hash 只由 FluentRead 识别,不会改变服务端请求。
*/
export
const
USERSCRIPT_SETTINGS_HASH
=
'#fluentread-userscript-settings'
;
export
function
buildUserscriptSettingsHash
(
section
?:
string
)
:
string
{
const
normalizedSection
=
typeof
section
===
'string'
?
section
.
replace
(
/
^
#
/
u
,
''
)
.
trim
(
)
:
''
;
return
normalizedSection
?
`
${
USERSCRIPT_SETTINGS_HASH
}
/
${
normalizedSection
}
`
:
USERSCRIPT_SETTINGS_HASH
;
}
export
function
buildUserscriptSettingsUrl
(
currentUrl
:
string
,
section
?:
string
)
:
string
{
try
{
const
url
=
new
URL
(
currentUrl
)
;
url
.
hash
=
buildUserscriptSettingsHash
(
section
)
;
return
url
.
toString
(
)
;
}
catch
{
return
currentUrl
;
}
}
export
function
isUserscriptSettingsUrl
(
currentUrl
:
string
)
:
boolean
{
try
{
const
hash
=
new
URL
(
currentUrl
)
.
hash
;
return
hash
===
USERSCRIPT_SETTINGS_HASH
||
hash
.
startsWith
(
`
${
USERSCRIPT_SETTINGS_HASH
}
/`
)
;
}
catch
{
return
false
;
}
}
Back
|
FazBrowse Home
|
New Git URL