Skip to content

Commit f88ff02

Browse files
committed
fix popup
1 parent b512032 commit f88ff02

File tree

9 files changed

+56
-22
lines changed

9 files changed

+56
-22
lines changed

md/README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,91 @@ Danh sách tất cả tài liệu trong folder này.
55
## 📚 Main Documentation
66

77
### [CLAUDE.md](./CLAUDE.md)
8+
89
Hướng dẫn cho Claude Code khi làm việc với repository này. Chứa thông tin về:
10+
911
- Kiến trúc extension
1012
- Cách thêm script mới
1113
- Development workflow
1214
- Performance optimization
1315

1416
### [CONTRIBUTE.md](./CONTRIBUTE.md)
17+
1518
Hướng dẫn đóng góp cho project (Vietnamese + English). Bao gồm:
19+
1620
- Cấu trúc repository
1721
- Cách thêm script
1822
- Cách fix/improve scripts
1923
- Testing guide
2024

2125
## 🚀 Performance Optimization Docs
2226

23-
### [IMPLEMENTATION_SUMMARY.md](./IMPLEMENTATION_SUMMARY.md)
27+
### [IMPLEMENTATION_SUMMARY.md](./claude-fix/IMPLEMENTATION_SUMMARY.md)
28+
2429
**Đọc đầu tiên!** Tổng kết về optimization đã implement:
30+
2531
- Kết quả đạt được (10-20x faster)
2632
- Cách hoạt động
2733
- Development workflow mới
2834
- Testing steps
2935

30-
### [OPTIMIZATION_DONE.md](./OPTIMIZATION_DONE.md)
36+
### [OPTIMIZATION_DONE.md](./claude-fix/OPTIMIZATION_DONE.md)
37+
3138
Chi tiết về implementation:
39+
3240
- Các thay đổi đã thực hiện
3341
- Verification checklist
3442
- Troubleshooting guide
3543
- Next steps
3644

37-
### [OPTIMIZATION_PLAN.md](./OPTIMIZATION_PLAN.md)
45+
### [OPTIMIZATION_PLAN.md](./claude-fix/OPTIMIZATION_PLAN.md)
46+
3847
Kế hoạch kỹ thuật chi tiết:
48+
3949
- Vấn đề ban đầu
4050
- Giải pháp lazy loading
4151
- Architecture design
4252
- Migration guide
4353

44-
### [QUICK_START_OPTIMIZATION.md](./QUICK_START_OPTIMIZATION.md)
54+
### [QUICK_START_OPTIMIZATION.md](./claude-fix/QUICK_START_OPTIMIZATION.md)
55+
4556
Hướng dẫn nhanh 30 phút về optimization:
57+
4658
- 5 bước implementation
4759
- Kết quả mong đợi
4860
- Development workflow
4961
- Checklist
5062

51-
### [FIX_APPLIED.md](./FIX_APPLIED.md)
63+
### [FIX_APPLIED.md](./claude-fix/FIX_APPLIED.md)
64+
5265
Fix cho issue "scripts not showing":
66+
5367
- Root cause analysis
5468
- Solution applied
5569
- Testing steps
5670

5771
## 📝 Project Documentation
5872

5973
### [CHANGELOGS.md](./CHANGELOGS.md)
74+
6075
Lịch sử cập nhật các phiên bản extension
6176

6277
### [working_note.md](./working_note.md)
78+
6379
Ghi chú phát triển, TODO list, ý tưởng
6480

6581
### [facebook-post-hay.md](./facebook-post-hay.md)
82+
6683
Facebook posts collection
6784

6885
## 🔧 Scripts & Tools
6986

7087
### [exportScriptsToMd.js](./exportScriptsToMd.js)
88+
7189
Tool để export danh sách scripts ra markdown
7290

7391
### [flow.pu](./flow.pu)
92+
7493
PlantUML flow diagram
7594

7695
---
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

popup/index.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { BADGES_CONFIG } from "../scripts/helpers/badge.js";
44
import { checkForUpdate } from "./helpers/checkForUpdate.js";
55
import { UfsGlobal } from "../scripts/content-scripts/ufs_global.js";
66
import { THEME, THEME_KEY, getTheme, setTheme } from "./helpers/theme.js";
7-
import { enableSmoothScroll } from "../scripts/smoothScroll.js";
87
import {
98
isActiveScript,
109
getCurrentTab,
@@ -39,8 +38,8 @@ import {
3938
isTitle,
4039
viewScriptSource,
4140
} from "./helpers/utils.js";
42-
import { checkPass } from "../scripts/auto_lockWebsite.js";
43-
import allScripts from "../scripts/@allScripts.js";
41+
// import { checkPass } from "../scripts/auto_lockWebsite.js";
42+
// import allScripts from "../scripts/@allScripts.js";
4443
// import _ from "../md/exportScriptsToMd.js";
4544

4645
// ============================================================================
@@ -83,21 +82,23 @@ async function loadFullScript(scriptId) {
8382
*/
8483
function preloadPopularScripts() {
8584
const popular = [
86-
'fb_toggleLight',
87-
'youtube_downloadVideo',
88-
'simpleAllowCopy',
89-
'darkModePDF',
85+
// "ggdrive_downloadPdf",
9086
];
9187

9288
setTimeout(() => {
93-
popular.forEach(id => {
89+
popular.forEach((id) => {
9490
loadFullScript(id).catch(() => {
9591
// Silently fail - not critical
9692
});
9793
});
9894
}, 100);
9995
}
10096

97+
async function lazyEnableSmoothScroll() {
98+
const { enableSmoothScroll } = await import("../scripts/smoothScroll.js");
99+
return enableSmoothScroll();
100+
}
101+
101102
// ============================================================================
102103

103104
const settingsBtn = document.querySelector(".settings");
@@ -374,13 +375,21 @@ function createScriptButton(script, isFavorite = false) {
374375
const fullScriptBtnIndex = hasInfoLink ? btnIndex - 1 : btnIndex;
375376
const fullBtnConfig = fullScript.buttons?.[fullScriptBtnIndex];
376377

377-
if (fullBtnConfig?.onClick && typeof fullBtnConfig.onClick === 'function') {
378+
if (
379+
fullBtnConfig?.onClick &&
380+
typeof fullBtnConfig.onClick === "function"
381+
) {
378382
await fullBtnConfig.onClick();
379383
} else {
380-
console.error(`Button onClick not found in script ${script.id} at index ${fullScriptBtnIndex}`);
384+
console.error(
385+
`Button onClick not found in script ${script.id} at index ${fullScriptBtnIndex}`
386+
);
381387
}
382388
} catch (error) {
383-
console.error(`Failed to execute button onClick for ${script.id}:`, error);
389+
console.error(
390+
`Failed to execute button onClick for ${script.id}:`,
391+
error
392+
);
384393
}
385394
};
386395
more.appendChild(btn);
@@ -582,13 +591,14 @@ async function runScript(scriptMetadata) {
582591

583592
let tab = await getCurrentTab();
584593
let willRun = checkBlackWhiteList(scriptMetadata, tab.url);
594+
595+
// ⚡ LAZY LOAD: Load full script on-demand
596+
const script = await loadFullScript(scriptMetadata.id);
597+
585598
if (willRun) {
586599
recentScriptsSaver.add(scriptMetadata);
587600
trackEvent(scriptMetadata.id);
588601

589-
// ⚡ LAZY LOAD: Load full script on-demand
590-
const script = await loadFullScript(scriptMetadata.id);
591-
592602
try {
593603
if (isFunction(script.popupScript?.onClick)) {
594604
await script.popupScript.onClick();
@@ -822,15 +832,15 @@ function initSettings() {
822832
"active",
823833
!(disableSmoothScrollSaver.get() ?? false)
824834
);
825-
checkbox.onclick = () => {
835+
checkbox.onclick = async () => {
826836
let curVal = disableSmoothScrollSaver.get();
827837
let newVal = !curVal;
828838
disableSmoothScrollSaver.set(newVal);
829839

830840
let enabled = !newVal;
831841
trackEvent("CHANGE-SMOOTH-SCROLL-" + (enabled ? "ON" : "OFF"));
832842
checkbox.classList.toggle("active", enabled);
833-
if (enabled) disableSmoothScroll = enableSmoothScroll();
843+
if (enabled) disableSmoothScroll = await lazyEnableSmoothScroll();
834844
else if (typeof disableSmoothScroll == "function") disableSmoothScroll();
835845
};
836846
body.appendChild(smoothScrollRow);
@@ -942,6 +952,8 @@ async function backup() {
942952
}
943953

944954
async function restore() {
955+
const { checkPass } = await import("../scripts/auto_lockWebsite.js");
956+
945957
if (
946958
!(await checkPass(
947959
t({
@@ -1035,6 +1047,7 @@ async function restore() {
10351047
}
10361048

10371049
async function reset() {
1050+
const { checkPass } = await import("../scripts/auto_lockWebsite.js");
10381051
if (
10391052
!(await checkPass(
10401053
t({
@@ -1184,7 +1197,9 @@ window.addEventListener("scroll", onScrollEnd);
11841197
trackEvent("OPEN-POPUP");
11851198

11861199
if (!disableSmoothScrollSaver.get())
1187-
disableSmoothScroll = enableSmoothScroll();
1200+
lazyEnableSmoothScroll().then((_) => {
1201+
disableSmoothScroll = _;
1202+
});
11881203
initTracking();
11891204
initSearch();
11901205
initTooltip();

0 commit comments

Comments
 (0)