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