diff --git a/frontend/lib/dom/comment.ts b/frontend/lib/dom/comment.ts index 1dd8d4a5..dbc01ce7 100644 --- a/frontend/lib/dom/comment.ts +++ b/frontend/lib/dom/comment.ts @@ -6,7 +6,7 @@ import iconInfoOutlineRounded from "iconify/info-outline-rounded"; import { Comment } from "../types"; import { getJWT, decodeJWT, logout, fetchGitHubMeta } from "../auth"; import { apiEndpoint } from "../const"; -import { groupBy, dateTimeFormatter } from "../util"; +import { groupBy, dateTimeFormatter, isReallyMobile } from "../util"; let selectedOffset: HTMLElement | null = null; @@ -123,7 +123,7 @@ export const selectOffsetParagraph = async ({ selectedOffset = el; } - if (selectedOffset?.dataset.reviewHasComments || forceOpenCommentsPanel) { + if ((!isReallyMobile() && selectedOffset?.dataset.reviewHasComments) || forceOpenCommentsPanel) { delete selectedOffset.dataset.reviewFocused; selectedOffset.dataset.reviewSelected = "true"; // 只有在点击评论按钮时才会 focus 到评论框,这里 forceOpenCommentsPanel === true 就等价于点击评论按钮 diff --git a/frontend/lib/util.ts b/frontend/lib/util.ts index 462a5a4e..b9dfd48e 100644 --- a/frontend/lib/util.ts +++ b/frontend/lib/util.ts @@ -1,6 +1,6 @@ export const groupBy = function ( arr: T[], - func: (el: T) => K, + func: (el: T) => K ) { return arr.reduce( (acc, x) => { @@ -9,7 +9,7 @@ export const groupBy = function ( }, {} as { [key: string]: T[]; - }, + } ); }; @@ -17,3 +17,9 @@ export const dateTimeFormatter = new Intl.DateTimeFormat("zh-CN", { dateStyle: "short", timeStyle: "short", }); + +export function isReallyMobile() { + return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent + ); +}