mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 23:16:49 +00:00
30 lines
633 B
JavaScript
30 lines
633 B
JavaScript
'use client'
|
|
|
|
import { isBrowser } from '@/lib/utils'
|
|
|
|
/**
|
|
* 自定义外部 script
|
|
* 传入参数将转为 <script>标签。
|
|
* @returns
|
|
*/
|
|
const ExternalScript = props => {
|
|
const { src } = props
|
|
if (!isBrowser || !src) {
|
|
return null
|
|
}
|
|
|
|
const element = document.querySelector(`script[src="${src}"]`)
|
|
if (element) {
|
|
return null
|
|
}
|
|
const script = document.createElement('script')
|
|
Object.entries(props).forEach(([key, value]) => {
|
|
script.setAttribute(key, value)
|
|
})
|
|
document.head.appendChild(script)
|
|
// console.log('加载外部脚本', props, script)
|
|
return null
|
|
}
|
|
|
|
export default ExternalScript
|