on dcbbc5f help sign in
webring/scripts/hallway.js
51 lines 1.1 kB history raw
1'use strict'
3function Hallway (sites) {
4 const feeds = {}
5 this.sites = sites
6 this.el = document.createElement('div')
8 this.install = function (host) {
9 host.appendChild(this.el)
10 // Find feeds
11 this.findFeeds()
12 }
14 this.start = function () {
15 this.el.innerHTML = 'hello'
16 this.fetchFeeds()
17 // this.fetch('https://wiki.xxiivv.com/twtxt.txt')
18 }
20 this.refresh = function () {
21 console.log('!!')
22 }
24 //
26 this.findFeeds = function () {
27 console.log('Finding feeds..')
28 for (const id in sites) {
29 const site = sites[id]
30 if (site.feed && site.author) {
31 feeds[site.author] = { path: site.feed }
32 }
33 }
34 console.log(`Found ${Object.keys(feeds).length} feeds.`)
35 }
37 this.fetchFeeds = function () {
38 console.log(`Fetching ${Object.keys(feeds).length} feeds..`)
39 for (const id in feeds) {
40 this.fetchFeed(id, feeds[id])
41 }
42 }
44 this.fetchFeed = function (id, feed) {
45 console.log(`Fetching ${id}(${feed.path})..`)
46 Promise.all([ fetch(feed.path).then(x => x.text()) ]).then(([content]) => {
47 feeds[id].content = content
48 this.refresh()
49 })
50 }