Skip to content

Commit 44f0af7

Browse files
committed
auto cleanup when disable
1 parent 889efbb commit 44f0af7

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

scripts/smoothScroll.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default {
3838
}),
3939
html: t({
4040
vi:
41-
`Đã tự bật cho ${tabs.length} tab đang mở<br/><br/>` +
41+
`Đã tự BẬT cho ${tabs.length} tab đang mở<br/><br/>` +
4242
"Bạn có thể dùng ngay không cần tải lại trang.",
4343
en:
4444
`Enabled smooth scroll for ${tabs.length} tabs<br/><br/>` +
@@ -47,6 +47,39 @@ export default {
4747
});
4848
});
4949
},
50+
onDisable: async () => {
51+
const { t } = await import("../popup/helpers/lang.js");
52+
const { runScriptInTab } = await import("./helpers/utils.js");
53+
chrome.tabs.query({}, async (tabs) => {
54+
for (let tab of tabs) {
55+
await runScriptInTab({
56+
target: {
57+
tabId: tab.id,
58+
allFrames: true,
59+
},
60+
func: () => {
61+
window.ufs_smoothScroll_disable?.();
62+
},
63+
world: "ISOLATED",
64+
});
65+
}
66+
Swal.fire({
67+
icon: "success",
68+
title: t({
69+
vi: "Đã tắt Cuộn chuột Siêu mượt",
70+
en: "Super smooth scroll disabled",
71+
}),
72+
html: t({
73+
vi:
74+
`Đã tự TẮT cho ${tabs.length} tab đang mở<br/><br/>` +
75+
"Không cần tải lại trang.",
76+
en:
77+
`Disabled smooth scroll for ${tabs.length} tabs<br/><br/>` +
78+
"Dont need to reload websites.",
79+
}),
80+
});
81+
});
82+
},
5083
},
5184

5285
contentScript: {
@@ -760,7 +793,7 @@ export function run() {
760793
/**
761794
* A module for middle mouse scrolling.
762795
*/
763-
(function (window) {
796+
const cleanupMiddlemouse = (function (window) {
764797
var defaultOptions = {
765798
middleMouse: false,
766799
frameRate: 200,
@@ -905,5 +938,12 @@ export function run() {
905938
})();
906939
addEvent("mousedown", mousedown);
907940
addEvent("DOMContentLoaded", init);
941+
942+
return cleanup;
908943
})(window);
944+
945+
window.ufs_smoothScroll_disable = () => {
946+
cleanup();
947+
cleanupMiddlemouse();
948+
};
909949
}

0 commit comments

Comments
 (0)