From 0d2be4b30caae47aae1a61547d5e0350f3e20ae6 Mon Sep 17 00:00:00 2001
From: Hakadao
Date: Mon, 13 Mar 2023 01:39:35 +0800
Subject: [PATCH] feat: add emoji support for comments section in video page *
i18n: remove `ago` key
---
src/_locales/cmn-CN.yml | 15 ++-
src/_locales/cmn-TW.yml | 15 ++-
src/_locales/en.yml | 15 ++-
src/_locales/jyut.yml | 15 ++-
src/components/Topbar/TopbarMomentsPop.vue | 4 -
src/components/VideoCard/VideoCard.vue | 7 +-
src/contentScripts/views/Video/Video.vue | 105 +++++++++++++++++----
src/styles/variables.scss | 2 +-
src/utils/dataFormatter.ts | 2 +-
src/utils/i18n.ts | 1 +
10 files changed, 119 insertions(+), 62 deletions(-)
diff --git a/src/_locales/cmn-CN.yml b/src/_locales/cmn-CN.yml
index 072d84b7..73b0f50e 100644
--- a/src/_locales/cmn-CN.yml
+++ b/src/_locales/cmn-CN.yml
@@ -3,14 +3,13 @@ common:
loading: 加载中...
undo: 还原
view: 次
- ago: 前
- year: 年
- month: 个月
- week: 个星期
- day: 天
- hour: 小时
- minute: 分钟
- second: 秒
+ year: 年前
+ month: 个月前
+ week: 个星期前
+ day: 天前
+ hour: 小时前
+ minute: 分钟前
+ second: 秒前
settings:
title: 设置
select_language: 界面语文
diff --git a/src/_locales/cmn-TW.yml b/src/_locales/cmn-TW.yml
index 2f0aceb2..2bd809db 100644
--- a/src/_locales/cmn-TW.yml
+++ b/src/_locales/cmn-TW.yml
@@ -3,14 +3,13 @@ common:
loading: 載入中...
undo: 復原
view: 次
- ago: 前
- year: 年
- month: 個月
- week: 個禮拜
- day: 天
- hour: 小時
- minute: 分鐘
- second: 秒
+ year: 年前
+ month: 個月前
+ week: 個禮拜前
+ day: 天前
+ hour: 小時前
+ minute: 分鐘前
+ second: 秒前
settings:
title: 設定
select_language: 介面語文
diff --git a/src/_locales/en.yml b/src/_locales/en.yml
index affb0974..85845d9f 100644
--- a/src/_locales/en.yml
+++ b/src/_locales/en.yml
@@ -3,14 +3,13 @@ common:
loading: Loading...
undo: UNDO
view: no view | view | views
- ago: ago
- year: year | years
- month: month | momths
- week: week | weeks
- day: day | days
- hour: hour | hours
- minute: minute | minutes
- second: second | seconds
+ year: year ago | years ago
+ month: month ago | months ago
+ week: week ago | weeks ago
+ day: day ago | days ago
+ hour: hour ago | hours ago
+ minute: minute ago | minutes ago
+ second: second ago | seconds ago
settings:
title: Settings
select_language: Language
diff --git a/src/_locales/jyut.yml b/src/_locales/jyut.yml
index 4f480fd8..bba2e195 100644
--- a/src/_locales/jyut.yml
+++ b/src/_locales/jyut.yml
@@ -3,14 +3,13 @@ common:
loading: 撈緊...
undo: 整返
view: 次
- ago: 前
- year: 年
- month: 個月
- week: 個禮拜
- day: 日
- hour: 個鐘頭
- minute: 分鐘
- second: 秒
+ year: 年前
+ month: 個月前
+ week: 個禮拜前
+ day: 日前
+ hour: 個鐘頭前
+ minute: 分鐘前
+ second: 秒前
settings:
title: 校做
select_language: 介面語文
diff --git a/src/components/Topbar/TopbarMomentsPop.vue b/src/components/Topbar/TopbarMomentsPop.vue
index 364ba84b..66570d4f 100644
--- a/src/components/Topbar/TopbarMomentsPop.vue
+++ b/src/components/Topbar/TopbarMomentsPop.vue
@@ -394,10 +394,6 @@ function scrollToTop(element: HTMLElement, duration: number) {
moment.ctime
? calcTimeSince(new Date(moment.ctime * 1000))
: moment.ctime
- }}{{
- language === LanguageType.English
- ? ` ${$t('common.ago')}`
- : $t('common.ago')
}}
diff --git a/src/components/VideoCard/VideoCard.vue b/src/components/VideoCard/VideoCard.vue
index 9bfbd262..a0c1443e 100644
--- a/src/components/VideoCard/VideoCard.vue
+++ b/src/components/VideoCard/VideoCard.vue
@@ -309,12 +309,7 @@ function gotoChannel(mid: number) {
: $t('common.view', videoData.stat.view)
}}
•
- {{ calcTimeSince(videoData.pubdate * 1000)
- }}{{
- language === LanguageType.English
- ? ` ${$t('common.ago')}`
- : $t('common.ago')
- }}
+ {{ calcTimeSince(videoData.pubdate * 1000) }}
diff --git a/src/contentScripts/views/Video/Video.vue b/src/contentScripts/views/Video/Video.vue
index 60116640..8015bbfa 100644
--- a/src/contentScripts/views/Video/Video.vue
+++ b/src/contentScripts/views/Video/Video.vue
@@ -2,7 +2,7 @@
import type { Ref, UnwrapNestedRefs } from 'vue'
import { useDateFormat } from '@vueuse/core'
import type { Comment, VideoInfo } from './types'
-import { getCSRF, removeHttpFromUrl } from '~/utils'
+import { calcTimeSince, getCSRF, removeHttpFromUrl } from '~/utils'
const videoContent = ref() as Ref
// const commentContent = ref() as Ref
@@ -124,6 +124,7 @@ function getVideoComments() {
csrf: getCSRF(),
oid: videoInfo.aid,
pn: 1,
+ sort: 1,
}).then((res) => {
if (res.code === 0) {
Object.assign(commentList, res.data.replies)
@@ -131,6 +132,31 @@ function getVideoComments() {
}
})
}
+
+function setupCommentEmote(content: string, emote: any) {
+ let result = `${content}`
+
+ if (!emote || Object.keys(emote).length === 0)
+ return content
+
+ Object.keys(emote).forEach((key) => {
+ if (emote[key].meta.size === 1) {
+ result = result.replaceAll(key, `
+
`)
+ }
+ else {
+ result = result.replaceAll(key, `
+
`)
+ }
+ })
+ return result
+}
@@ -143,8 +169,19 @@ function getVideoComments() {
-
-
+
+
+
![]()
+
{{ commentPageInfo.acount }} Comments
- -
+
-
-
-
- {{ comment.member.uname }}
-
+
+
+
+
+ {{ comment.member.uname }}
+
+
+
+
+
+
+
+
+
-
{{ comment.content.message }}
-
{{ useDateFormat(comment.ctime * 1000, 'YYYY-MM-DD HH:mm:ss') }}
- -
+
-
-
- {{ reply.member.uname }}
-
-
{{ reply.content.message }}
+
+
+
+ {{ reply.member.uname }}
+
+
+
+
+
+
+
+
diff --git a/src/styles/variables.scss b/src/styles/variables.scss
index 68e27808..8380b420 100644
--- a/src/styles/variables.scss
+++ b/src/styles/variables.scss
@@ -76,7 +76,7 @@
// #region text colors
--bew-text-1: hsl(217, 33%, 17%);
--bew-text-2: hsl(215, 19%, 35%);
- --bew-text-3: hsl(215, 19%, 55%);
+ --bew-text-3: hsl(215, 19%, 58%);
--bew-text-4: hsl(215, 19%, 72%);
// #endregion
diff --git a/src/utils/dataFormatter.ts b/src/utils/dataFormatter.ts
index 5b5f26f4..11e32102 100644
--- a/src/utils/dataFormatter.ts
+++ b/src/utils/dataFormatter.ts
@@ -36,7 +36,7 @@ export const numFormatter = (num: number) => {
return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + item.symbol : '0'
}
-export const calcTimeSince = (date: number | string) => {
+export const calcTimeSince = (date: number | string | Date) => {
const seconds = Math.floor(((Number(new Date())) - Number(date)) / 1000)
let interval = seconds / 31536000
if (interval > 1)
diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts
index 4da87573..f9c6511a 100644
--- a/src/utils/i18n.ts
+++ b/src/utils/i18n.ts
@@ -4,6 +4,7 @@ import messages from '@intlify/unplugin-vue-i18n/messages'
export const i18n = createI18n({
legacy: false,
locale: 'en',
+ fallbackLocale: 'en',
globalInjection: true,
messages,
})