enhance(frontend): 外部サイトへのリンクは移動の前に警告を表示するように (MisskeyIO#558)
This commit is contained in:
parent
722f01c4e7
commit
01ec286f3f
15 changed files with 141 additions and 7 deletions
33
packages/frontend/src/scripts/warning-external-website.ts
Normal file
33
packages/frontend/src/scripts/warning-external-website.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { url as local } from '@/config.js';
|
||||
import { instance } from '@/instance.js';
|
||||
import { i18n } from '@/i18n.js';
|
||||
import * as os from '@/os.js';
|
||||
|
||||
const isRegExp = /^\/(.+)\/(.*)$/;
|
||||
|
||||
export async function warningExternalWebsite(ev: MouseEvent, url: string) {
|
||||
const self = 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));
|
||||
});
|
||||
|
||||
if (!self && !isWellKnownWebsite) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
const confirm = await os.confirm({
|
||||
type: 'warning',
|
||||
title: i18n.ts.warningRedirectingExternalWebsiteTitle,
|
||||
text: i18n.tsx.warningRedirectingExternalWebsiteDescription({ url }),
|
||||
});
|
||||
|
||||
if (confirm.canceled) return false;
|
||||
|
||||
window.open(url, '_blank', 'noopener');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue