mirror of
https://github.com/PaiGramTeam/luoxu-api-pub.git
synced 2024-11-22 07:08:05 +00:00
complete type
This commit is contained in:
parent
7b5350f719
commit
55a3fe8edc
@ -1,16 +1,16 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
import { onMount, getContext } from "svelte";
|
import { onMount, getContext } from "svelte";
|
||||||
|
|
||||||
export let msg;
|
export let msg: any;
|
||||||
export let groupinfo;
|
export let groupinfo: any;
|
||||||
export let now;
|
export let now: any;
|
||||||
|
|
||||||
const formatter = new Intl.DateTimeFormat(undefined, {
|
const formatter = new Intl.DateTimeFormat(undefined, {
|
||||||
timeStyle: "full",
|
timeStyle: "full",
|
||||||
dateStyle: "full",
|
dateStyle: "full",
|
||||||
hour12: false,
|
hour12: false,
|
||||||
});
|
});
|
||||||
|
const format_dt = formatter.format;
|
||||||
let dt = new Date(msg.t * 1000);
|
let dt = new Date(msg.t * 1000);
|
||||||
let edited = msg.edited ? new Date(msg.edited * 1000) : null;
|
let edited = msg.edited ? new Date(msg.edited * 1000) : null;
|
||||||
let title =
|
let title =
|
||||||
@ -21,7 +21,7 @@
|
|||||||
? `tg://resolve?domain=${groupinfo[msg.group_id][0]}&post=${msg.id}`
|
? `tg://resolve?domain=${groupinfo[msg.group_id][0]}&post=${msg.id}`
|
||||||
: `tg://privatepost?channel=${msg.group_id}&post=${msg.id}`;
|
: `tg://privatepost?channel=${msg.group_id}&post=${msg.id}`;
|
||||||
|
|
||||||
function format_relative_time(d1, d2) {
|
function format_relative_time(d1: Date, d2: Date) {
|
||||||
// in miliseconds
|
// in miliseconds
|
||||||
const units = {
|
const units = {
|
||||||
year: 24 * 60 * 60 * 1000 * 365,
|
year: 24 * 60 * 60 * 1000 * 365,
|
||||||
@ -33,19 +33,16 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const rtf = new Intl.RelativeTimeFormat();
|
const rtf = new Intl.RelativeTimeFormat();
|
||||||
|
//@ts-ignore
|
||||||
|
const elapsed = d1 - d2; //https://stackoverflow.com/a/4944782/13040423
|
||||||
|
|
||||||
const elapsed = d1 - d2;
|
for (const [u, period] of Object.entries(units)) {
|
||||||
|
if (Math.abs(elapsed) > period || u === "second") {
|
||||||
for (const u in units) {
|
//@ts-ignore
|
||||||
if (Math.abs(elapsed) > units[u] || u === "second") {
|
return rtf.format(Math.round(elapsed / period), u);
|
||||||
return rtf.format(Math.round(elapsed / units[u]), u);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function format_dt(t) {
|
|
||||||
return formatter.format(t);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="message">
|
<div class="message">
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
import { onMount, getContext } from "svelte";
|
import { onMount, getContext } from "svelte";
|
||||||
|
|
||||||
export let group;
|
export let group: any;
|
||||||
|
|
||||||
export let selected;
|
export let selected: any;
|
||||||
export let selected_init;
|
export let selected_init: any;
|
||||||
let selected_name = "";
|
let selected_name = "";
|
||||||
let selected_idx;
|
let selected_idx: number;
|
||||||
|
|
||||||
let to;
|
let to: string | number | NodeJS.Timeout;
|
||||||
let names = [];
|
let names = [];
|
||||||
let url = getContext("LUOXU_URL");
|
let url = getContext("LUOXU_URL");
|
||||||
let input;
|
let input: HTMLInputElement;
|
||||||
let ul;
|
let ul: HTMLUListElement;
|
||||||
let should_hide = false;
|
let should_hide = false;
|
||||||
|
|
||||||
let abort = new AbortController();
|
let abort = new AbortController();
|
||||||
@ -49,7 +49,7 @@
|
|||||||
signal: abort.signal,
|
signal: abort.signal,
|
||||||
});
|
});
|
||||||
const j = await res.json();
|
const j = await res.json();
|
||||||
if (!abort.aborted) {
|
if (!abort.signal.aborted) {
|
||||||
// only update if we're current
|
// only update if we're current
|
||||||
names = j.names;
|
names = j.names;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_by_click(e) {
|
function select_by_click(e: any) {
|
||||||
let el = e.target;
|
let el = e.target;
|
||||||
if (el.tagName === "IMG") {
|
if (el.tagName === "IMG") {
|
||||||
el = el.parentNode;
|
el = el.parentNode;
|
||||||
@ -94,7 +94,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_by_key(e) {
|
function select_by_key(e: KeyboardEvent) {
|
||||||
if (e.key === "ArrowDown" || (e.key === "n" && e.altKey)) {
|
if (e.key === "ArrowDown" || (e.key === "n" && e.altKey)) {
|
||||||
select_next(1);
|
select_next(1);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -107,7 +107,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_next(dir) {
|
function select_next(dir: number) {
|
||||||
if (typeof selected_idx === "number") {
|
if (typeof selected_idx === "number") {
|
||||||
if (dir > 0) {
|
if (dir > 0) {
|
||||||
selected_idx = (selected_idx + 1) % names.length;
|
selected_idx = (selected_idx + 1) % names.length;
|
||||||
|
Loading…
Reference in New Issue
Block a user