a demonstration replicated social networking web app built with anproto
wiredove.net/
social
ed25519
protocols
1const HLJS_SCRIPT_URL = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js'
2const HLJS_STYLE_URL = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/nord.min.css'
3const QRIOUS_SCRIPT_URL = 'https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.min.js'
4
5let hljsPromise = null
6let qriousPromise = null
7let hljsStylePromise = null
8
9const loadScript = (src) => new Promise((resolve, reject) => {
10 const existing = document.querySelector(`script[data-src="${src}"]`)
11 if (existing) {
12 if (existing.dataset.loaded === 'true') {
13 resolve()
14 } else {
15 existing.addEventListener('load', () => resolve(), { once: true })
16 existing.addEventListener('error', () => reject(new Error('Failed to load script: ' + src)), { once: true })
17 }
18 return
19 }
20 const script = document.createElement('script')
21 script.src = src
22 script.async = true
23 script.dataset.src = src
24 script.addEventListener('load', () => {
25 script.dataset.loaded = 'true'
26 resolve()
27 }, { once: true })
28 script.addEventListener('error', () => reject(new Error('Failed to load script: ' + src)), { once: true })
29 document.head.appendChild(script)
30})
31
32const loadStylesheet = (href) => new Promise((resolve, reject) => {
33 const existing = document.querySelector(`link[rel="stylesheet"][href="${href}"]`)
34 if (existing) {
35 resolve()
36 return
37 }
38 const link = document.createElement('link')
39 link.rel = 'stylesheet'
40 link.href = href
41 link.addEventListener('load', () => resolve(), { once: true })
42 link.addEventListener('error', () => reject(new Error('Failed to load stylesheet: ' + href)), { once: true })
43 document.head.appendChild(link)
44})
45
46export const ensureHighlight = async () => {
47 if (!hljsStylePromise) {
48 hljsStylePromise = loadStylesheet(HLJS_STYLE_URL).catch((err) => {
49 hljsStylePromise = null
50 throw err
51 })
52 }
53 if (!hljsPromise) {
54 hljsPromise = loadScript(HLJS_SCRIPT_URL).then(() => window.hljs).catch((err) => {
55 hljsPromise = null
56 throw err
57 })
58 }
59 await hljsStylePromise
60 const hljs = await hljsPromise
61 return hljs
62}
63
64export const ensureQRious = async () => {
65 if (!qriousPromise) {
66 qriousPromise = loadScript(QRIOUS_SCRIPT_URL).then(() => window.QRious).catch((err) => {
67 qriousPromise = null
68 throw err
69 })
70 }
71 const QRious = await qriousPromise
72 return QRious
73}