my eye

Lazy load remaining scripts

Committed 6bdf4e

--- a/canopy/static/enliven.js
+++ b/canopy/static/enliven.js

 import { _, go, upgradeLink } from '/static/web.js'  // eslint-disable-line
 
+const injectScript = src => {
+  const tag = document.createElement('script')
+  tag.src = src
+  document.getElementsByTagName('head')[0].appendChild(tag)
+}
+const injectStylesheet = href => {
+  const tag = document.createElement('link')
+  tag.rel = 'stylesheet'
+  tag.media = 'screen'
+  tag.href = href
+  document.getElementsByTagName('head')[0].appendChild(tag)
+}
+
 let mode = 'site'
 const konamiCode = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13]
 const konamiCodeJSON = JSON.stringify(konamiCode)
 let konamiCodeFIFO = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 
+let btclient
+
+injectScript('/assets/js-cookie-3.0.5.js')
+
 // TODO $.load(...)
 document.addEventListener('DOMContentLoaded', ev => {
   let currentColorMode = Cookies.get('colormode')
   history.pushState({ scroll: 0 }, 'title', window.location)
   window.go = go
 
-  const client = new WebTorrent()
   DragDrop('body', (files, pos, fileList, directories) => {
     console.log(files[0])
-    client.seed(files, torrent => {
+    btclient.seed(files, torrent => {
       console.log(`Client is seeding at:\n${torrent.magnetURI}`)
     })
   })
       }
     }
   }, false)
+
+  injectScript('/assets/webtorrent-2.1.30.js')
+  injectScript('/assets/drag-drop-7.2.0.js')
+
+  btclient = new WebTorrent()
 })
 
 const em = parseFloat(getComputedStyle(document.documentElement).fontSize)
   listen.innerHTML = icon
   document.querySelectorAll('#listen path').forEach(el => { el.style.stroke = `#${color}` })
 }
-
-const injectScript = src => {
-  const tag = document.createElement('script')
-  tag.src = src
-  document.getElementsByTagName('head')[0].appendChild(tag)
-}
-const injectStylesheet = href => {
-  const tag = document.createElement('link')
-  tag.rel = 'stylesheet'
-  tag.media = 'screen'
-  tag.href = href
-  document.getElementsByTagName('head')[0].appendChild(tag)
-}

--- a/canopy/templates/template.html
+++ b/canopy/templates/template.html

         height: 2.6em;
         width: 2.6em; }
     </style>
-<script src=/assets/webtorrent-2.1.30.js></script>
-<script src=/assets/drag-drop-7.2.0.js></script>
-<script src=/assets/js-cookie-3.0.5.js></script>
 <script>
 $if "session" in tx.user and tx.user.session.get("uid", None):
     $ username = tx.user.session["name"][0]
 let userName = '$username'
 let ownerGivenName = '$owner["name"][0].split()[0]'
 </script>
-<script type=module src=/static/enliven.js></script>
 </head>
 
+<script type=module src=/static/enliven.js></script>
+
 <body
 $if "body_classes" in resource:
      class="$' '.join(resource.body_classes)"\