fix: inline script to file

This commit is contained in:
Pasha8914 2022-06-08 15:24:59 +10:00
parent 28aaf17d87
commit 06214fc23a
4 changed files with 39 additions and 32 deletions

@ -1,36 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html {{ HTML_ATTRS }}> <html {{ HTML_ATTRS }}>
<head {{ HEAD_ATTRS }}> <head {{ HEAD_ATTRS }}>
<script>
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)
console.log('Loading', source.pathname)
const newSource = window.location.origin + ipfsPathPrefix + source.pathname
addScript(newSource)
}
}
console.log('Finished')
}
})
</script>
{{ HEAD }} {{ HEAD }}
</head> </head>
<body {{ BODY_ATTRS }}> <body {{ BODY_ATTRS }}>

@ -454,7 +454,7 @@
}, },
"withdrawalQueueIsOverloaded": "Withdrawal queue is overloaded", "withdrawalQueueIsOverloaded": "Withdrawal queue is overloaded",
"trustBanner": { "trustBanner": {
"trustLess": "You are using an public IPFS gateway. Tornado Cash dApp can not use all security features of your browser. Check out {link} for alternatives", "trustLess": "You are using a public IPFS gateway. Tornado Cash dApp can not use all security features of your browser. Check out {link} for alternatives",
"link": "landing page" "link": "landing page"
} }
} }

@ -45,11 +45,13 @@ export default {
}, },
head: { head: {
title: 'Tornado.cash', title: 'Tornado.cash',
script: [{ src: 'headerScript.js', async: false, defer: true }],
meta: [ meta: [
{ charset: 'utf-8' }, { charset: 'utf-8' },
{ {
'http-equiv': 'Content-Security-Policy', 'http-equiv': 'Content-Security-Policy',
content: '' content:
"img-src 'self' data:;font-src data:;style-src 'self' 'unsafe-inline';connect-src *;script-src 'self' 'unsafe-eval' 'unsafe-inline';default-src 'self';object-src 'none';base-uri 'none';upgrade-insecure-requests"
}, },
{ {
name: 'Referer-Policy', name: 'Referer-Policy',

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()