enhance(frontend): 外部サイトへのリンクは移動の警告の条件の調整 (MisskeyIO#564)
This commit is contained in:
parent
7187c04b2e
commit
65978cbe61
4 changed files with 9 additions and 6 deletions
|
@ -3,15 +3,18 @@ import { instance } from '@/instance.js';
|
|||
import { i18n } from '@/i18n.js';
|
||||
import * as os from '@/os.js';
|
||||
|
||||
const extractDomain = /^(https?:\/\/|\/\/)?([^@/\s]+@)?(www\.)?([^:/\s]+)/i;
|
||||
const isRegExp = /^\/(.+)\/(.*)$/;
|
||||
|
||||
export async function warningExternalWebsite(ev: MouseEvent, url: string) {
|
||||
const self = url.startsWith(local);
|
||||
const domain = extractDomain.exec(url)?.[4];
|
||||
const self = !domain || url.startsWith(local);
|
||||
const isWellKnownWebsite = self || instance.wellKnownWebsites.some(expression => {
|
||||
const r = isRegExp.exec(expression);
|
||||
if (r) {
|
||||
return new RegExp(r[1], r[2]).test(url);
|
||||
} else return expression.split(' ').every(keyword => url.includes(keyword));
|
||||
} else if (expression.includes(' ')) return expression.split(' ').every(keyword => url.includes(keyword));
|
||||
else return domain.endsWith(expression);
|
||||
});
|
||||
|
||||
if (!self && !isWellKnownWebsite) {
|
||||
|
@ -21,7 +24,7 @@ export async function warningExternalWebsite(ev: MouseEvent, url: string) {
|
|||
const confirm = await os.confirm({
|
||||
type: 'warning',
|
||||
title: i18n.ts.warningRedirectingExternalWebsiteTitle,
|
||||
text: i18n.tsx.warningRedirectingExternalWebsiteDescription({ url }),
|
||||
text: i18n.tsx.warningRedirectingExternalWebsiteDescription({ url: `\`\`\`\n${url}\n\`\`\`` }),
|
||||
});
|
||||
|
||||
if (confirm.canceled) return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue