enhance(frontend): ブラウザの互換性向上 (MisskeyIO#257)
This commit is contained in:
parent
6157c35f9c
commit
84a7f12e7f
@ -3,14 +3,32 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
const enRegex1 = /(?<=n)a/gi;
|
||||
const enRegex2 = /(?<=morn)ing/gi;
|
||||
const enRegex3 = /(?<=every)one/gi;
|
||||
const koRegex1 = /[나-낳]/g;
|
||||
const koRegex2 = /(다$)|(다(?=\.))|(다(?= ))|(다(?=!))|(다(?=\?))/gm;
|
||||
const koRegex3 = /(야(?=\?))|(야$)|(야(?= ))/gm;
|
||||
let enRegex1: RegExp;
|
||||
let enRegex2: RegExp;
|
||||
let enRegex3: RegExp;
|
||||
let koRegex1: RegExp;
|
||||
let koRegex2: RegExp;
|
||||
let koRegex3: RegExp;
|
||||
let fallback: boolean = true;
|
||||
|
||||
export function nyaize(text: string): string {
|
||||
try {
|
||||
enRegex1 = new RegExp('(?<=n)a', 'gi');
|
||||
enRegex2 = new RegExp('(?<=morn)ing', 'gi');
|
||||
enRegex3 = new RegExp('(?<=every)one', 'gi');
|
||||
koRegex1 = new RegExp('[나-낳]', 'g');
|
||||
koRegex2 = new RegExp('(다$)|(다(?= ))|(다(?=!))|(다(?=\\?))|(다(?=\\.))', 'gm');
|
||||
koRegex3 = new RegExp('(야$)|(야(?= ))|(야(?=!))|(야(?=\\?))|(야(?=\\.))', 'gm');
|
||||
fallback = false;
|
||||
} catch {
|
||||
enRegex1 = new RegExp('na', 'gi');
|
||||
enRegex2 = new RegExp('morning', 'gi');
|
||||
enRegex3 = new RegExp('everyone', 'gi');
|
||||
koRegex1 = new RegExp('[나-낳]', 'g');
|
||||
koRegex2 = new RegExp('다$', 'gm');
|
||||
koRegex3 = new RegExp('야$', 'gm');
|
||||
}
|
||||
|
||||
function convertNormal(text: string): string {
|
||||
return text
|
||||
// ja-JP
|
||||
.replaceAll('な', 'にゃ').replaceAll('ナ', 'ニャ').replaceAll('ナ', 'ニャ')
|
||||
@ -25,3 +43,23 @@ export function nyaize(text: string): string {
|
||||
.replace(koRegex2, '다냥')
|
||||
.replace(koRegex3, '냥');
|
||||
}
|
||||
|
||||
function convertFallback(text: string): string {
|
||||
return text
|
||||
// ja-JP
|
||||
.replaceAll('な', 'にゃ').replaceAll('ナ', 'ニャ').replaceAll('ナ', 'ニャ')
|
||||
// en-US
|
||||
.replace(enRegex1, x => x === 'NA' ? 'NYA' : 'nya')
|
||||
.replace(enRegex2, x => x === 'MORNING' ? 'MORNYAN' : 'mornyan')
|
||||
.replace(enRegex3, x => x === 'EVERYONE' ? 'EVERYNYAN' : 'everynyan')
|
||||
// ko-KR
|
||||
.replace(koRegex1, match => String.fromCharCode(
|
||||
match.charCodeAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0),
|
||||
))
|
||||
.replace(koRegex2, '다냥').replaceAll('다 ', '다냥 ').replaceAll('다!', '다냥!').replaceAll('다?', '다냥?').replaceAll('다.', '다냥.')
|
||||
.replace(koRegex3, '냥').replaceAll('야 ', '냥 ').replaceAll('야!', '냥!').replaceAll('야?', '냥?').replaceAll('야.', '냥.');
|
||||
}
|
||||
|
||||
export function nyaize(text: string): string {
|
||||
return !fallback ? convertNormal(text) : convertFallback(text);
|
||||
}
|
||||
|
@ -3,9 +3,9 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
const canvas = globalThis.OffscreenCanvas && new OffscreenCanvas(1, 1);
|
||||
// 環境によってはOffscreenCanvasが存在しないため
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const canvas = typeof OffscreenCanvas !== 'undefined'
|
||||
? new OffscreenCanvas(1, 1)
|
||||
: undefined;
|
||||
const gl = canvas?.getContext('webgl2');
|
||||
if (gl) {
|
||||
postMessage({ result: true });
|
||||
|
Loading…
Reference in New Issue
Block a user