(fix) lint issues

This commit is contained in:
kakkokari-gtyih 2023-04-09 19:00:16 +09:00
parent 8c976ee855
commit 50e401426f
9 changed files with 69 additions and 62 deletions

View File

@ -98,4 +98,4 @@ function nav(ev: MouseEvent) {
router.push(props.to, ev.ctrlKey ? 'forcePage' : null); router.push(props.to, ev.ctrlKey ? 'forcePage' : null);
} }
</script> </script>

View File

@ -1,4 +1,7 @@
import JSON5 from 'json5'; /**
* Client (Embed) entry point
*/
import 'vite/modulepreload-polyfill';
import { miLocalStorage } from '@/local-storage'; import { miLocalStorage } from '@/local-storage';
import { version, lang, updateLocale, url } from '@/config'; import { version, lang, updateLocale, url } from '@/config';
import { embedInitI18n } from './scripts/embed-i18n'; import { embedInitI18n } from './scripts/embed-i18n';
@ -14,7 +17,7 @@ import lightTheme from '@/themes/_light.json5';
import darkTheme from '@/themes/_dark.json5'; import darkTheme from '@/themes/_dark.json5';
import { isDeviceDarkmode } from '@/scripts/is-device-darkmode'; import { isDeviceDarkmode } from '@/scripts/is-device-darkmode';
console.info(`Misskey (Embed Sandbox) v${version}`); console.info(`Misskey (Embed) v${version}`);
const supportedEmbedEntity: string[] = [ const supportedEmbedEntity: string[] = [
'notes' 'notes'
@ -77,7 +80,7 @@ if (!path.includes('/embed')) {
location.href = url; location.href = url;
throw new Error('Embed script was loaded on non-embed page. Force redirect to the top page.'); 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; } = { const pageMeta: { entityName: string; id: string; } = {
entityName: pageMetaValues[0], entityName: pageMetaValues[0],
id: pageMetaValues[1], id: pageMetaValues[1],
@ -131,8 +134,8 @@ function afterPageInitialization() {
embedInitI18n(); embedInitI18n();
//@ts-ignore //@ts-ignore
document.querySelectorAll(".mfm").forEach((e: HTMLElement) => { document.querySelectorAll(".mfm").forEach((el: HTMLElement) => {
e.innerHTML = parseMfm(e.innerText, enableAnimatedMfm).outerHTML; el.innerHTML = parseMfm(el.innerText, enableAnimatedMfm).outerHTML;
}); });
parseEmoji(); parseEmoji();
@ -150,5 +153,5 @@ function afterPageInitialization() {
} }
//#endregion //#endregion
embedInitLinkAnime(); embedInitLinkAnime();
} }

View File

@ -23,7 +23,7 @@ document.querySelectorAll("time.locale-string").forEach((el) => {
const invalid = Number.isNaN(_time); const invalid = Number.isNaN(_time);
const absolute:string = !invalid ? dateTimeFormat.format(_time) : i18n.ts._ago.invalid; const absolute:string = !invalid ? dateTimeFormat.format(_time) : i18n.ts._ago.invalid;
let now = new Date().getTime(); const now = new Date().getTime();
const relative = () => { const relative = () => {
if (invalid) return i18n.ts._ago.invalid; if (invalid) return i18n.ts._ago.invalid;
@ -57,4 +57,4 @@ document.querySelectorAll("time.locale-string").forEach((el) => {
} }
}); });
export { }; export { };

View File

@ -1,22 +1,28 @@
import { locale } from "@/config"; import { locale } from "@/config";
import { I18n } from "@/scripts/i18n"; import { I18n } from "@/scripts/i18n";
const i18n = new I18n(locale);
export const embedI18n = i18n;
/** /**
* vueページ向け翻訳適用関数 * vueページ向け翻訳適用関数
* *
* : * :
* ```html * ```html
* <span data-mi-i18n="翻訳key必須" data-mi-i18n-ctx=" *JSON Objectで動的な値を指定任意* "></span> * <span data-mi-i18n="翻訳key必須" data-mi-i18n-ctx=" *JSON Objectで動的な値を指定任意* ">
* <element>
* ...
* <element data-mi-i18n-target=" *動的な値を入れたい要素にkeyを指定* "></element>
* ...
* </element>
* </span>
* ``` * ```
*/ */
const i18n = new I18n(locale);
export const embedI18n = i18n;
export function embedInitI18n() { export function embedInitI18n() {
const els: NodeListOf<HTMLElement> = document.querySelectorAll("[data-mi-i18n]"); const els: NodeListOf<HTMLElement> = document.querySelectorAll("[data-mi-i18n]");
els.forEach((tag: HTMLElement) => { 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<string, string | number> | null = JSON.parse(tag.dataset.miI18nCtx ?? 'null'); const translationContext: Record<string, string | number> | null = JSON.parse(tag.dataset.miI18nCtx ?? 'null');
if (!key) { if (!key) {
console.warn("[i18n] Key doesn't exist!", tag); 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); tag.innerText = key.reduce((o, i) => o[i], i18n.ts);
} }
}); });
} }

View File

@ -30,4 +30,4 @@ export function embedInitLinkAnime() {
}); });
}); });
} }
} }

View File

@ -3,17 +3,17 @@ import { char2twemojiFilePath } from '@/scripts/emoji-base';
const char2path = char2twemojiFilePath; const char2path = char2twemojiFilePath;
const remoteCustomEmojiEl = document.getElementById("remote_custom_emojis"); 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) { if (remoteCustomEmojiEl) {
remoteCustomEmoji = JSON.parse(remoteCustomEmojiEl.innerHTML); remoteCustomEmojis = JSON.parse(remoteCustomEmojiEl.innerHTML);
} }
function getCustomEmojiName(ceNameRaw: string) { 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) { function getCustomEmojiUrl(ceName: string) {
const remote = remoteCustomEmoji.find((e) => e.name === ceName); const remote = remoteCustomEmojis.find((emoji) => emoji.name === ceName);
if (remote) { if (remote) {
return remote.url; return remote.url;
} }
@ -36,4 +36,4 @@ export function parseEmoji() {
el.innerHTML = emojiEl.outerHTML; el.innerHTML = emojiEl.outerHTML;
} }
}); });
} }

View File

@ -50,16 +50,16 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
case 'bold': { case 'bold': {
const el = document.createElement("b"); const el = document.createElement("b");
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
return [el]; return [el];
} }
case 'strike': { case 'strike': {
const el = document.createElement("del"); const el = document.createElement("del");
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
return [el]; return [el];
} }
@ -67,8 +67,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
case 'italic': { case 'italic': {
const el = document.createElement("i"); const el = document.createElement("i");
el.style.fontStyle = 'oblique'; el.style.fontStyle = 'oblique';
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
return [el]; return [el];
} }
@ -131,25 +131,25 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
case 'x2': { case 'x2': {
const el = document.createElement("span"); const el = document.createElement("span");
el.classList.add('mfm-x2'); el.classList.add('mfm-x2');
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}) });
return [el]; return [el];
} }
case 'x3': { case 'x3': {
const el = document.createElement("span"); const el = document.createElement("span");
el.classList.add('mfm-x3'); el.classList.add('mfm-x3');
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}) });
return [el]; return [el];
} }
case 'x4': { case 'x4': {
const el = document.createElement("span"); const el = document.createElement("span");
el.classList.add('mfm-x4'); el.classList.add('mfm-x4');
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}) });
return [el]; return [el];
} }
case 'font': { case 'font': {
@ -168,9 +168,9 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
case 'blur': { case 'blur': {
const el = document.createElement("span"); const el = document.createElement("span");
el.classList.add('_mfm_blur_'); el.classList.add('_mfm_blur_');
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}) });
return [el]; return [el];
} }
case 'rainbow': { case 'rainbow': {
@ -214,15 +214,15 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
} }
if (style == null) { if (style == null) {
const el = document.createElement("span"); const el = document.createElement("span");
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
el.innerHTML = `$[${token.props.name} ${el.innerHTML}]`; el.innerHTML = `$[${token.props.name} ${el.innerHTML}]`;
return [el]; return [el];
} else { } else {
const el = document.createElement("span"); const el = document.createElement("span");
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
el.setAttribute('style', `display: inline-block; ${style}`); el.setAttribute('style', `display: inline-block; ${style}`);
return [el]; return [el];
@ -232,8 +232,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
case 'small': { case 'small': {
const el = document.createElement("small"); const el = document.createElement("small");
el.style.opacity = '.7'; el.style.opacity = '.7';
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
return [el]; return [el];
} }
@ -241,8 +241,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
case 'center': { case 'center': {
const el = document.createElement("div"); const el = document.createElement("div");
el.style.textAlign = "center"; el.style.textAlign = "center";
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
return [el]; return [el];
} }
@ -262,8 +262,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
el.href = token.props.url; el.href = token.props.url;
el.target = '_blank'; el.target = '_blank';
el.rel = 'nofollow noopener'; el.rel = 'nofollow noopener';
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
return [el]; return [el];
} }
@ -319,8 +319,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
case 'quote': { case 'quote': {
const el = document.createElement('div'); const el = document.createElement('div');
el.setAttribute('style', QUOTE_STYLE); el.setAttribute('style', QUOTE_STYLE);
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
return [el]; return [el];
} }
@ -370,8 +370,8 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
case 'plain': { case 'plain': {
const el = document.createElement('span'); const el = document.createElement('span');
genEl(token.children).forEach((e) => { genEl(token.children).forEach((child) => {
el.appendChild(e as HTMLElement); el.appendChild(child as HTMLElement);
}); });
return [el]; return [el];
} }
@ -397,4 +397,4 @@ export function parseMfm(text: string, useAnim: boolean = false): HTMLDivElement
}); });
return el; return el;
} }

View File

@ -9,14 +9,13 @@ export function renderNotFound() {
<div id="instance-info"> <div id="instance-info">
<a class="click-anime" href="http://localhost:3000" target="_blank"> <a class="click-anime" href="http://localhost:3000" target="_blank">
<img src="/static-assets/splash.png" class="_anime_bounce_standBy"> <img src="/static-assets/splash.png" class="_anime_bounce_standBy">
<span class="sr-only">${i18n.t('aboutX', {x: instanceName || 'Misskey'})}</span> <span class="sr-only">${ i18n.t('aboutX', { x: instanceName || 'Misskey' }) }</span>
</a> </a>
</div> </div>
<img class="main" src="https://xn--931a.moe/assets/not-found.jpg"> <img class="main" src="https://xn--931a.moe/assets/not-found.jpg">
<h2>${i18n.ts.notFound}</h2> <h2>${ i18n.ts.notFound }</h2>
<p>${i18n.ts.notFoundDescription}</p> <p>${ i18n.ts.notFoundDescription }</p>
</div> </div>
</div>`; </div>`;
} }
} }

View File

@ -81,7 +81,6 @@ export function applyTheme(theme: Theme, persist = true) {
miLocalStorage.setItem('theme', JSON.stringify(props)); miLocalStorage.setItem('theme', JSON.stringify(props));
miLocalStorage.setItem('colorSchema', colorSchema); miLocalStorage.setItem('colorSchema', colorSchema);
} }
} }
function compile(theme: Theme): Record<string, string> { function compile(theme: Theme): Record<string, string> {