event.ts
798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import renderApp from "@src/App";
import {
getElement,
pendingFetch,
warningEmptyId,
fetchByURL,
} from "./functions";
import { randomTransition } from "./page";
export function linkEvent(e: Event) {
e.preventDefault();
const pathname: string = (e.target as HTMLAnchorElement).pathname.split(
"/"
)[1];
setTimeout(() => {
renderApp(pathname);
}, 1200);
randomTransition();
}
export async function handleFetchById(url: string, cssSelector: string) {
const insta_id = (getElement(cssSelector) as HTMLInputElement).value;
pendingFetch();
if (!insta_id) {
warningEmptyId();
return;
}
await fetchByURL(url + insta_id);
}
export const addEventWithElementByType = (element, eventType, handler) => {
element.addEventListener(eventType, handler);
};