From 50e401426fa4a7fd9e3c340e3671d7dc433b7dda Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih Date: Sun, 9 Apr 2023 19:00:16 +0900 Subject: [PATCH] (fix) lint issues --- .../frontend/src/components/global/MkA.vue | 2 +- packages/frontend/src/embed/init.ts | 17 +++-- packages/frontend/src/embed/pages/notes.ts | 4 +- .../frontend/src/embed/scripts/embed-i18n.ts | 20 ++++-- .../frontend/src/embed/scripts/link-anime.ts | 2 +- .../frontend/src/embed/scripts/parse-emoji.ts | 10 +-- .../frontend/src/embed/scripts/parse-mfm.ts | 66 +++++++++---------- .../src/embed/scripts/render-not-found.ts | 9 ++- packages/frontend/src/embed/scripts/theme.ts | 1 - 9 files changed, 69 insertions(+), 62 deletions(-) diff --git a/packages/frontend/src/components/global/MkA.vue b/packages/frontend/src/components/global/MkA.vue index e3039008f9..40d134dffb 100644 --- a/packages/frontend/src/components/global/MkA.vue +++ b/packages/frontend/src/components/global/MkA.vue @@ -98,4 +98,4 @@ function nav(ev: MouseEvent) { router.push(props.to, ev.ctrlKey ? 'forcePage' : null); } - \ No newline at end of file + diff --git a/packages/frontend/src/embed/init.ts b/packages/frontend/src/embed/init.ts index 2217de1741..62d2339921 100644 --- a/packages/frontend/src/embed/init.ts +++ b/packages/frontend/src/embed/init.ts @@ -1,4 +1,7 @@ -import JSON5 from 'json5'; +/** + * Client (Embed) entry point + */ +import 'vite/modulepreload-polyfill'; import { miLocalStorage } from '@/local-storage'; import { version, lang, updateLocale, url } from '@/config'; import { embedInitI18n } from './scripts/embed-i18n'; @@ -14,7 +17,7 @@ import lightTheme from '@/themes/_light.json5'; import darkTheme from '@/themes/_dark.json5'; import { isDeviceDarkmode } from '@/scripts/is-device-darkmode'; -console.info(`Misskey (Embed Sandbox) v${version}`); +console.info(`Misskey (Embed) v${version}`); const supportedEmbedEntity: string[] = [ 'notes' @@ -77,7 +80,7 @@ if (!path.includes('/embed')) { location.href = url; throw new Error('Embed script was loaded on non-embed page. Force redirect to the top page.'); } -const pageMetaValues:string[] = path.split('/').filter((e) => e != '' && e != 'embed'); +const pageMetaValues:string[] = path.split('/').filter((dir) => dir !== '' && dir !== 'embed'); const pageMeta: { entityName: string; id: string; } = { entityName: pageMetaValues[0], id: pageMetaValues[1], @@ -131,8 +134,8 @@ function afterPageInitialization() { embedInitI18n(); //@ts-ignore - document.querySelectorAll(".mfm").forEach((e: HTMLElement) => { - e.innerHTML = parseMfm(e.innerText, enableAnimatedMfm).outerHTML; + document.querySelectorAll(".mfm").forEach((el: HTMLElement) => { + el.innerHTML = parseMfm(el.innerText, enableAnimatedMfm).outerHTML; }); parseEmoji(); @@ -150,5 +153,5 @@ function afterPageInitialization() { } //#endregion - embedInitLinkAnime(); -} \ No newline at end of file + embedInitLinkAnime(); +} diff --git a/packages/frontend/src/embed/pages/notes.ts b/packages/frontend/src/embed/pages/notes.ts index 19f73b964b..c7c1db7a69 100644 --- a/packages/frontend/src/embed/pages/notes.ts +++ b/packages/frontend/src/embed/pages/notes.ts @@ -23,7 +23,7 @@ document.querySelectorAll("time.locale-string").forEach((el) => { const invalid = Number.isNaN(_time); const absolute:string = !invalid ? dateTimeFormat.format(_time) : i18n.ts._ago.invalid; - let now = new Date().getTime(); + const now = new Date().getTime(); const relative = () => { if (invalid) return i18n.ts._ago.invalid; @@ -57,4 +57,4 @@ document.querySelectorAll("time.locale-string").forEach((el) => { } }); -export { }; \ No newline at end of file +export { }; diff --git a/packages/frontend/src/embed/scripts/embed-i18n.ts b/packages/frontend/src/embed/scripts/embed-i18n.ts index b88cddc96f..246859bb93 100644 --- a/packages/frontend/src/embed/scripts/embed-i18n.ts +++ b/packages/frontend/src/embed/scripts/embed-i18n.ts @@ -1,22 +1,28 @@ import { locale } from "@/config"; import { I18n } from "@/scripts/i18n"; +const i18n = new I18n(locale); + +export const embedI18n = i18n; + /** * 非vueページ向け翻訳適用関数 * * キー指定例: * ```html - * + * + * + * ... + * + * ... + * + * * ``` */ -const i18n = new I18n(locale); - -export const embedI18n = i18n; - export function embedInitI18n() { const els: NodeListOf = document.querySelectorAll("[data-mi-i18n]"); els.forEach((tag: HTMLElement) => { - const key: string[] | null = tag.dataset.miI18n?.split('.') || null; + const key: string[] | null = tag.dataset.miI18n?.split('.') ?? null; const translationContext: Record | null = JSON.parse(tag.dataset.miI18nCtx ?? 'null'); if (!key) { console.warn("[i18n] Key doesn't exist!", tag); @@ -48,4 +54,4 @@ export function embedInitI18n() { tag.innerText = key.reduce((o, i) => o[i], i18n.ts); } }); -} \ No newline at end of file +} diff --git a/packages/frontend/src/embed/scripts/link-anime.ts b/packages/frontend/src/embed/scripts/link-anime.ts index f1afd56ea6..20d49f8bf3 100644 --- a/packages/frontend/src/embed/scripts/link-anime.ts +++ b/packages/frontend/src/embed/scripts/link-anime.ts @@ -30,4 +30,4 @@ export function embedInitLinkAnime() { }); }); } -} \ No newline at end of file +} diff --git a/packages/frontend/src/embed/scripts/parse-emoji.ts b/packages/frontend/src/embed/scripts/parse-emoji.ts index 17fe6ab5d1..cf0816c87c 100644 --- a/packages/frontend/src/embed/scripts/parse-emoji.ts +++ b/packages/frontend/src/embed/scripts/parse-emoji.ts @@ -3,17 +3,17 @@ import { char2twemojiFilePath } from '@/scripts/emoji-base'; const char2path = char2twemojiFilePath; const remoteCustomEmojiEl = document.getElementById("remote_custom_emojis"); -let remoteCustomEmoji: { name: string; url: string; host?: string; }[] = []; +let remoteCustomEmojis: { name: string; url: string; host?: string; }[] = []; if (remoteCustomEmojiEl) { - remoteCustomEmoji = JSON.parse(remoteCustomEmojiEl.innerHTML); + remoteCustomEmojis = JSON.parse(remoteCustomEmojiEl.innerHTML); } function getCustomEmojiName(ceNameRaw: string) { - return (ceNameRaw.startsWith(":") ? ceNameRaw.substr(1, ceNameRaw.length - 2) : ceNameRaw).replace('@.', '') + return (ceNameRaw.startsWith(":") ? ceNameRaw.substr(1, ceNameRaw.length - 2) : ceNameRaw).replace('@.', ''); } function getCustomEmojiUrl(ceName: string) { - const remote = remoteCustomEmoji.find((e) => e.name === ceName); + const remote = remoteCustomEmojis.find((emoji) => emoji.name === ceName); if (remote) { return remote.url; } @@ -36,4 +36,4 @@ export function parseEmoji() { el.innerHTML = emojiEl.outerHTML; } }); -} \ No newline at end of file +} diff --git a/packages/frontend/src/embed/scripts/parse-mfm.ts b/packages/frontend/src/embed/scripts/parse-mfm.ts index 82165fb13f..14460d31dc 100644 --- a/packages/frontend/src/embed/scripts/parse-mfm.ts +++ b/packages/frontend/src/embed/scripts/parse-mfm.ts @@ -50,16 +50,16 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement case 'bold': { const el = document.createElement("b"); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); return [el]; } case 'strike': { const el = document.createElement("del"); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); return [el]; } @@ -67,8 +67,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement case 'italic': { const el = document.createElement("i"); el.style.fontStyle = 'oblique'; - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); return [el]; } @@ -131,25 +131,25 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement case 'x2': { const el = document.createElement("span"); el.classList.add('mfm-x2'); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); - }) + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); + }); return [el]; } case 'x3': { const el = document.createElement("span"); el.classList.add('mfm-x3'); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); - }) + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); + }); return [el]; } case 'x4': { const el = document.createElement("span"); el.classList.add('mfm-x4'); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); - }) + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); + }); return [el]; } case 'font': { @@ -168,9 +168,9 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement case 'blur': { const el = document.createElement("span"); el.classList.add('_mfm_blur_'); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); - }) + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); + }); return [el]; } case 'rainbow': { @@ -214,15 +214,15 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement } if (style == null) { const el = document.createElement("span"); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); el.innerHTML = `$[${token.props.name} ${el.innerHTML}]`; return [el]; } else { const el = document.createElement("span"); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); el.setAttribute('style', `display: inline-block; ${style}`); return [el]; @@ -232,8 +232,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement case 'small': { const el = document.createElement("small"); el.style.opacity = '.7'; - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); return [el]; } @@ -241,8 +241,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement case 'center': { const el = document.createElement("div"); el.style.textAlign = "center"; - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); return [el]; } @@ -262,8 +262,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement el.href = token.props.url; el.target = '_blank'; el.rel = 'nofollow noopener'; - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); return [el]; } @@ -319,8 +319,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement case 'quote': { const el = document.createElement('div'); el.setAttribute('style', QUOTE_STYLE); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); return [el]; } @@ -370,8 +370,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement case 'plain': { const el = document.createElement('span'); - genEl(token.children).forEach((e) => { - el.appendChild(e as HTMLElement); + genEl(token.children).forEach((child) => { + el.appendChild(child as HTMLElement); }); return [el]; } @@ -397,4 +397,4 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement }); return el; -} \ No newline at end of file +} diff --git a/packages/frontend/src/embed/scripts/render-not-found.ts b/packages/frontend/src/embed/scripts/render-not-found.ts index 7bd34a31a6..ea0bfd7b0c 100644 --- a/packages/frontend/src/embed/scripts/render-not-found.ts +++ b/packages/frontend/src/embed/scripts/render-not-found.ts @@ -9,14 +9,13 @@ export function renderNotFound() { -

${i18n.ts.notFound}

-

${i18n.ts.notFoundDescription}

+

${ i18n.ts.notFound }

+

${ i18n.ts.notFoundDescription }

`; - } -} \ No newline at end of file +} diff --git a/packages/frontend/src/embed/scripts/theme.ts b/packages/frontend/src/embed/scripts/theme.ts index 9920257d78..3adac761af 100644 --- a/packages/frontend/src/embed/scripts/theme.ts +++ b/packages/frontend/src/embed/scripts/theme.ts @@ -81,7 +81,6 @@ export function applyTheme(theme: Theme, persist = true) { miLocalStorage.setItem('theme', JSON.stringify(props)); miLocalStorage.setItem('colorSchema', colorSchema); } - } function compile(theme: Theme): Record {