This commit is contained in:
NAME
2026-05-16 16:15:01 +00:00
parent e506996855
commit 1608122288
4 changed files with 49 additions and 36 deletions
+12 -13
View File
@@ -70,14 +70,16 @@
const sel = window.getSelection().toString().trim();
if (sel) lastSelectedText = sel;
// Lưu tweet text
// Lưu tweet text — CHỈ khi click đúng vào article
const article = e.target.closest('article');
if (!article) { lastTweetText = ''; return; }
const textEl =
article.querySelector('[data-testid="tweetText"]') ||
article.querySelector('div[lang]') ||
article.querySelector('div[dir="auto"]');
lastTweetText = textEl ? textEl.innerText.trim() : article.innerText.trim().slice(0, 600);
if (article) {
const textEl =
article.querySelector('[data-testid="tweetText"]') ||
article.querySelector('div[lang]') ||
article.querySelector('div[dir="auto"]');
lastTweetText = textEl ? textEl.innerText.trim() : article.innerText.trim().slice(0, 600);
}
// ⚠️ KHÔNG xóa lastTweetText nếu không có article (tránh lỗi click vào padding/lề)
});
// ===== B. LISTENER =====
@@ -188,7 +190,6 @@
function openSidebar(tweetText) {
if (sidebarHost) {
// Nếu sidebar đã mở, chỉ cần mở drawer
const drawer = sidebarHost.shadowRoot.querySelector('.drawer');
if (drawer) drawer.classList.add('open');
return;
@@ -435,7 +436,6 @@
);
});
// Comment buttons
copyBtn.addEventListener('click', async () => {
const text = statusEl.textContent;
if (!text || text.startsWith('⏳') || text.startsWith('Lỗi') || text.startsWith('⚠️')) {
@@ -556,12 +556,11 @@
const url = urlIn.value.trim(), key = keyIn.value.trim();
if (!url || !key) { showCfgStatus('❌ Comment URL và Key không được để trống!', true); return; }
try { new URL(url); } catch { showCfgStatus('❌ URL không hợp lệ', true); return; }
const tUrl = transUrlIn.value.trim() || url;
const tKey = transKeyIn.value.trim() || key;
const tUrl = transUrlIn.value.trim();
const tKey = transKeyIn.value.trim();
chrome.storage.local.set({
apiUrl: url, apiKey: key,
translateUrl: tUrl === url ? '' : tUrl,
translateKey: transKeyIn.value.trim()
translateUrl: tUrl, translateKey: tKey
}, () => {
showCfgStatus('✅ Đã lưu!', false);
cfgBadge.style.display = 'none';