diff options
Diffstat (limited to 'web/src')
| -rw-r--r-- | web/src/index.js | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/web/src/index.js b/web/src/index.js index 82a3e25..a215c46 100644 --- a/web/src/index.js +++ b/web/src/index.js @@ -22,6 +22,12 @@ import * as frequent from "./frequently-used.js" // The base URL for fetching packs. The app will first fetch ${PACK_BASE_URL}/index.json, // then ${PACK_BASE_URL}/${packFile} for each packFile in the packs object of the index.json file. const PACKS_BASE_URL = "packs" + +let INDEX = `${PACKS_BASE_URL}/index.json` +const params = new URLSearchParams(document.location.search) +if (params.has('config')) { + INDEX = params.get("config") +} // This is updated from packs/index.json let HOMESERVER_URL = "https://matrix-client.matrix.org" @@ -31,11 +37,6 @@ const makeThumbnailURL = mxc => `${HOMESERVER_URL}/_matrix/media/r0/thumbnail/${ // This is also used to fix scrolling to sections on Element iOS const isMobileSafari = navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/) -export const parseQuery = str => Object.fromEntries( - str.split("&") - .map(part => part.split("=")) - .map(([key, value = ""]) => [key, value])) - const supportedThemes = ["light", "dark", "black"] const defaultState = { @@ -49,7 +50,7 @@ const defaultState = { class App extends Component { constructor(props) { super(props) - this.defaultTheme = parseQuery(location.search.substr(1)).theme + this.defaultTheme = params.get("theme") this.state = { packs: defaultState.packs, loading: true, @@ -153,7 +154,7 @@ class App extends Component { _loadPacks(disableCache = false) { const cache = disableCache ? "no-cache" : undefined - fetch(`${PACKS_BASE_URL}/index.json`, { cache }).then(async indexRes => { + fetch(INDEX, { cache }).then(async indexRes => { if (indexRes.status >= 400) { this.setState({ loading: false, @@ -165,7 +166,12 @@ class App extends Component { HOMESERVER_URL = indexData.homeserver_url || HOMESERVER_URL // TODO only load pack metadata when scrolled into view? for (const packFile of indexData.packs) { - const packRes = await fetch(`${PACKS_BASE_URL}/${packFile}`, { cache }) + let packRes + if (packFile.startsWith("https://") || packFile.startsWith("http://")) { + packRes = await fetch(packFile, { cache }) + } else { + packRes = await fetch(`${PACKS_BASE_URL}/${packFile}`, { cache }) + } const packData = await packRes.json() for (const sticker of packData.stickers) { this.stickersByID.set(sticker.id, sticker) @@ -256,7 +262,7 @@ class App extends Component { } navScroll(evt) { - this.navRef.scrollLeft += evt.deltaY * 12 + this.navRef.scrollLeft += evt.deltaY } render() { @@ -350,7 +356,7 @@ const Pack = ({ pack, send }) => html` const Sticker = ({ content, send }) => html` <div class="sticker" onClick=${send} data-sticker-id=${content.id}> - <img data-src=${makeThumbnailURL(content.url)} alt=${content.body} /> + <img data-src=${makeThumbnailURL(content.url)} alt=${content.body} title=${content.body} /> </div> ` |
