Skip to content

Commit

Permalink
enhance(frontend): 外部サイトへのリンクは移動の警告の条件の調整 (MisskeyIO#564)
Browse files Browse the repository at this point in the history
(cherry picked from commit 65978cb)
  • Loading branch information
u1-liquid authored and kakkokari-gtyih committed Mar 22, 2024
1 parent a4cc888 commit e010342
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ signupPendingError: "メールアドレスの確認中に問題が発生しま
cwNotationRequired: "「内容を隠す」がオンの場合は注釈の記述が必要です。"
doReaction: "リアクションする"
wellKnownWebsites: "よく知られたウェブサイト"
wellKnownWebsitesDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。一致した場合、外部サイトへのリダイレクトの警告を省略させることができます。"
wellKnownWebsitesDescription: "スペースで区切るとAND指定になり、改行で区切るとOR指定になります。スラッシュで囲むと正規表現になります。ドメイン名だけ書くと後方一致になります。一致した場合、外部サイトへのリダイレクトの警告を省略させることができます。"
code: "コード"
reloadRequiredToApplySettings: "設定の反映にはリロードが必要です。"
remainingN: "残り: {n}"
Expand Down
11 changes: 6 additions & 5 deletions packages/frontend/src/scripts/warning-external-website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import { defaultStore } from '@/store.js';
import * as os from '@/os.js';
import MkUrlWarningDialog from '@/components/MkUrlWarningDialog.vue';

const extractDomain = /^(https?:\/\/|\/\/)?([^@/\s]+@)?(www\.)?([^:/\s]+)/i;
const isRegExp = /^\/(.+)\/(.*)$/;

export async function warningExternalWebsite(ev: MouseEvent, url: string) {
const _url = new URL(url);

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);
});
const isTrustedByUser = defaultStore.reactiveState.trustedDomains.value.includes(_url.hostname);
const isTrustedByUser = defaultStore.reactiveState.trustedDomains.value.includes(domain);

if (!self && !isWellKnownWebsite && !isTrustedByUser) {
ev.preventDefault();
Expand Down

0 comments on commit e010342

Please sign in to comment.