fix: inline script to file
This commit is contained in:
parent
28aaf17d87
commit
06214fc23a
4 changed files with 39 additions and 32 deletions
35
static/headerScript.js
Normal file
35
static/headerScript.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const main = () => {
|
||||
if (window.location.search) {
|
||||
console.log('redirect')
|
||||
window.location = window.location.origin + window.location.pathname
|
||||
}
|
||||
|
||||
function addScript(src) {
|
||||
const s = document.createElement('script')
|
||||
s.setAttribute('src', src)
|
||||
document.body.appendChild(s)
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const ipfsPathRegExp = /^(\/(?:ipfs|ipns)\/[^/]+)/
|
||||
const ipfsPathPrefix = (window.location.pathname.match(ipfsPathRegExp) || [])[1] || ''
|
||||
if (ipfsPathPrefix) {
|
||||
const scripts = [...document.getElementsByTagName('script')]
|
||||
|
||||
for (let i = 0; i < scripts.length; i++) {
|
||||
if (scripts[i].src) {
|
||||
const source = new URL(scripts[i].src)
|
||||
if (!source.pathname.includes(ipfsPathPrefix)) {
|
||||
console.log('Loading', source.pathname)
|
||||
|
||||
const newSource = window.location.origin + ipfsPathPrefix + source.pathname
|
||||
addScript(newSource)
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('Finished')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue