Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IPC-footer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Allen Bai
IPC-footer
Commits
03c05558
Commit
03c05558
authored
Feb 01, 2021
by
Allen Bai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 字符串调整
parent
ee97b824
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
3 deletions
+49
-3
index.ts
src/index.ts
+49
-3
No files found.
src/index.ts
View file @
03c05558
/** @format */
type
Optional
<
T
>
=
{
[
P
in
keyof
T
]?:
T
[
P
]
}
function
request
(
option
)
{
if
(
String
(
option
)
!==
'[object Object]'
)
return
undefined
option
.
method
=
option
.
method
?
option
.
method
.
toUpperCase
()
:
'GET'
option
.
data
=
option
.
data
||
{}
var
formData
=
[]
for
(
var
key
in
option
.
data
)
{
formData
.
push
(
''
.
concat
(
key
,
'='
,
option
.
data
[
key
]))
}
option
.
data
=
formData
.
join
(
'&'
)
if
(
option
.
method
===
'GET'
)
{
option
.
url
+=
location
.
search
.
length
===
0
?
''
.
concat
(
'?'
,
option
.
data
)
:
''
.
concat
(
'&'
,
option
.
data
)
}
var
xhr
=
new
XMLHttpRequest
()
xhr
.
responseType
=
option
.
responseType
||
'json'
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
)
{
if
(
xhr
.
status
===
200
)
{
if
(
option
.
success
&&
typeof
option
.
success
===
'function'
)
{
option
.
success
(
xhr
.
response
)
}
}
else
{
if
(
option
.
error
&&
typeof
option
.
error
===
'function'
)
{
option
.
error
()
}
}
}
}
xhr
.
open
(
option
.
method
,
option
.
url
,
true
)
if
(
option
.
method
===
'POST'
)
{
xhr
.
setRequestHeader
(
'Content-Type'
,
'application/x-www-form-urlencoded'
)
}
xhr
.
send
(
option
.
method
===
'POST'
?
option
.
data
:
null
)
}
function
getIPCByDomain
(
domain
:
string
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
resolve
(
'1231232123'
)
request
({
url
:
`http://activity.tuiatest.cn/land/getIcpInfo?domain=
${
encodeURIComponent
(
domain
)}
`
,
method
:
'GET'
,
success
(
res
)
{
console
.
log
(
'当前域名的IPC备案为'
,
res
)
resolve
(
res
)
},
error
(
err
)
{
reject
(
err
)
}
})
})
}
...
...
@@ -44,7 +90,7 @@ const defaultBoardStyles: Optional<CSSStyleDeclaration> = {
}
async
function
mountIPCFooter
(
opts
:
IPCFooterOptions
=
{})
{
const
icpNumber
=
await
getIPCByDomain
(
opts
.
domain
||
location
.
host
)
const
IPCNumberString
=
await
getIPCByDomain
(
opts
.
domain
||
location
.
host
)
const
IPCFooter
=
document
.
createElement
(
'div'
)
const
IPCBoard
=
document
.
createElement
(
'a'
)
const
targetDom
=
opts
.
dom
||
document
.
querySelector
(
'body'
)
...
...
@@ -52,7 +98,7 @@ async function mountIPCFooter(opts: IPCFooterOptions = {}) {
IPCBoard
.
id
=
'__IPC_board__'
addStyles
(
IPCFooter
,
{
...
defaultFooterStyles
,
...(
opts
.
footerStyles
||
{})
})
addStyles
(
IPCBoard
,
{
...
defaultBoardStyles
,
...(
opts
.
footerStyles
||
{})
})
IPCBoard
.
innerText
=
`浙ICP备
${
icpNumber
}
号`
IPCBoard
.
innerText
=
(
IPCNumberString
as
string
)
||
''
IPCFooter
.
appendChild
(
IPCBoard
)
targetDom
.
appendChild
(
IPCFooter
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment