File size: 965 Bytes
30e9731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function watchFile(path, type){
  var lastStr = ''

  console.log(path)
  function check(){
    d3.text(path + '?' + Math.random(), (err, nextStr) => {
      if (err){
        console.log(err)
        return check()
      }

      if (nextStr == lastStr) return
      lastStr = nextStr

      if (path.includes('.js')){
        console.clear()
        console.log('js', new Date())

        Function(nextStr.replace('\n', ';').replace('\n', ';'))()
      }

      if (path.includes('.css')){
        console.log('css', new Date())

        Array.from(document.querySelectorAll('link'))
          .filter(d => d.href.includes(path))
          .forEach(d => d.href = d.href.split('?')[0] + '?' + Math.random())
      }
    })

    setTimeout(check, window.timeoutMS || 9999999999)
  }
  check()
}


watchFile('https://roadtolarissa.com/colab/gender-over-time-colab/style.css', 'js')
watchFile('https://roadtolarissa.com/colab/gender-over-time-colab/script.js', 'js')