From c66d89e317ba55c7c604d41df78f3a9eb61e666b Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Thu, 21 Oct 2021 15:23:20 +0800 Subject: [PATCH] make it more suitable for personal use --- src/App.svelte | 34 ++++++++++++++++++++-------------- src/Message.svelte | 7 ++++--- src/Name.svelte | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index eb67d3f..0233b64 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -5,6 +5,7 @@ import { sleep } from './util.js' const LUOXU_URL = 'https://lab.lilydjwg.me/luoxu' + const islocal = LUOXU_URL.indexOf('http://localhost') === 0 let groups = [] let group let query @@ -20,12 +21,7 @@ function parse_hash() { const hash = location.hash if(hash) { - const info = new Map() - for(const pair of hash.substring(1).split('&')){ - const [key, value] = pair.split('=') - info.set(key, decodeURIComponent(value)) - } - return info + return new URLSearchParams(hash.substring(1)) } } @@ -81,7 +77,10 @@ if(info.has('q')) { query = info.get('q') } - if(group && query) { + if(info.has('sender')) { + sender = info.get('sender') + } + if((group || islocal) && query) { result = null do_search() } @@ -89,28 +88,35 @@ } async function do_search(more) { - if(!group) { + if(!group && !islocal) { error = '请选择要搜索的群组' return } - if(!query) { + if(!query && !islocal) { error = '请输入搜索关键字' return } error = '' console.log(`searching ${query} for group ${group}, older than ${more}, from ${sender}`) - let q = `g=${group}&q=${encodeURIComponent(query)}` + const q = new URLSearchParams() + if(group) { + q.append('g', group) + } + if(query) { + q.append('q', query) + } if(sender) { - q += `&sender=${sender}` + q.append('sender', sender) } let url + const qstr = q.toString() if(!more) { - location.hash = `#${q}` + location.hash = `#${qstr}` need_update_title = true if(result) { result.messages = [] } - url = `${LUOXU_URL}/search?${q}` + url = `${LUOXU_URL}/search?${qstr}` }else{ url = `${LUOXU_URL}/search?${q}&end=${more}` } @@ -173,7 +179,7 @@ {#if result} {#each result.messages as message} - + {/each} {/if} diff --git a/src/Message.svelte b/src/Message.svelte index d1888de..6ec6c9b 100644 --- a/src/Message.svelte +++ b/src/Message.svelte @@ -2,7 +2,7 @@ import { onMount, getContext } from 'svelte' export let msg - export let group + export let groupinfo export let now const formatter = new Intl.DateTimeFormat(undefined, { @@ -16,6 +16,7 @@ let title = format_dt(dt) + (edited ? `\n最后编辑于:${format_dt(edited)}` : '') let relative_dt = format_relative_time(dt, now) let iso_date = dt.toISOString() + let msgurl = groupinfo[msg.group_id][0] ? `tg://resolve?domain=${groupinfo[msg.group_id][0]}&post=${msg.id}` : `tg://privatepost?channel=${msg.group_id}&post=${msg.id}` function format_relative_time(d1, d2) { // in miliseconds @@ -51,7 +52,7 @@
{msg.from_name || ' '}
{@html msg.html}
- +
{groupinfo[msg.group_id][1]}
@@ -83,7 +84,7 @@ font-size: 0.75em; float: right; } - .time > a { + .time, .time > a { color: gray; } diff --git a/src/Name.svelte b/src/Name.svelte index 2d0fac8..68c3a1d 100644 --- a/src/Name.svelte +++ b/src/Name.svelte @@ -37,7 +37,7 @@ } async function complete_it() { - if(!group || !input.value) { + if(!input.value) { return } abort.abort()