fix: slice check

This commit is contained in:
Gabe
2025-09-25 01:50:22 +08:00
parent 7665f8c260
commit 1dabbfc4de
2 changed files with 10 additions and 3 deletions

View File

@@ -430,9 +430,14 @@ export class Translator {
}
#getDocDescription() {
const meta = document.querySelector('meta[name="description"]');
const description = meta ? meta.getAttribute("content") : "";
return description.slice(0, 200);
try {
const meta = document.querySelector('meta[name="description"]');
const description = meta ? meta.getAttribute("content") : "";
return description.slice(0, 200);
} catch (err) {
kissLog("get description", err);
}
return "";
}
// 监控翻译单元的可见性

View File

@@ -198,6 +198,8 @@ export const isSameSet = (a, b) => {
* @returns
*/
export const removeEndchar = (s, c, count = 1) => {
if (!s) return "";
let i = s.length;
while (i > s.length - count && s[i - 1] === c) {
i--;