app.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!DOCTYPE html>
  2. <html {{ HTML_ATTRS }}>
  3. <head {{ HEAD_ATTRS }}>
  4. <script>
  5. if (window.location.search) {
  6. console.log('redirect')
  7. window.location = window.location.origin + window.location.pathname
  8. }
  9. function addScript(src) {
  10. const s = document.createElement('script')
  11. s.setAttribute('src', src)
  12. document.body.appendChild(s)
  13. }
  14. document.addEventListener('DOMContentLoaded', () => {
  15. const ipfsPathRegExp = /^(\/(?:ipfs|ipns)\/[^/]+)/
  16. const ipfsPathPrefix = (window.location.pathname.match(ipfsPathRegExp) || [])[1] || ''
  17. if (ipfsPathPrefix) {
  18. const scripts = [...document.getElementsByTagName('script')]
  19. for (let i = 0; i < scripts.length; i++) {
  20. if (scripts[i].src) {
  21. const source = new URL(scripts[i].src)
  22. console.log('Loading', source.pathname)
  23. const newSource = window.location.origin + ipfsPathPrefix + source.pathname
  24. addScript(newSource)
  25. }
  26. }
  27. console.log('Finished')
  28. }
  29. })
  30. </script>
  31. {{ HEAD }}
  32. </head>
  33. <body {{ BODY_ATTRS }}>
  34. {{ APP }}
  35. </body>
  36. </html>