enhance(frontend): ユーザーの信頼する外部サイトへのリンクは警告しないように (MisskeyIO#612)

This commit is contained in:
まっちゃとーにゅ 2024-04-14 12:39:42 +09:00 committed by GitHub
parent 1f38f58117
commit 32802d15b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 21 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import { url as local } from '@/config.js';
import { defaultStore } from '@/store.js';
import { instance } from '@/instance.js';
import { i18n } from '@/i18n.js';
import * as os from '@/os.js';
@ -16,8 +17,9 @@ export async function warningExternalWebsite(ev: MouseEvent, url: string) {
} else if (expression.includes(' ')) return expression.split(' ').every(keyword => url.includes(keyword));
else return domain.endsWith(expression);
});
const isTrusted = defaultStore.reactiveState.trustedExternalWebsites.value.includes(domain);
if (!self && !isWellKnownWebsite) {
if (!self && !isWellKnownWebsite && !isTrusted) {
ev.preventDefault();
ev.stopPropagation();
@ -25,10 +27,15 @@ export async function warningExternalWebsite(ev: MouseEvent, url: string) {
type: 'warning',
title: i18n.ts.warningRedirectingExternalWebsiteTitle,
text: i18n.tsx.warningRedirectingExternalWebsiteDescription({ url: `\`\`\`\n${url}\n\`\`\`` }),
switchLabel: i18n.ts.warningRedirectingExternalWebsiteTrustThisSite,
});
if (confirm.canceled) return false;
if (confirm.toggle) {
await defaultStore.set('trustedExternalWebsites', [...defaultStore.reactiveState.trustedExternalWebsites.value, domain]);
}
window.open(url, '_blank', 'noopener');
}