|
1 | | -import { GlobalBlackList, MsgType } from "../scripts/helpers/constants.js"; |
| 1 | +import { |
| 2 | + Events, |
| 3 | + GlobalBlackList, |
| 4 | + MsgType, |
| 5 | + ScriptType, |
| 6 | +} from "../scripts/helpers/constants.js"; |
2 | 7 | import { |
3 | 8 | checkBlackWhiteList, |
| 9 | + getActiveScript, |
4 | 10 | getCurrentTab, |
5 | 11 | isFunction, |
6 | 12 | removeAccents, |
7 | | - runScriptInCurrentTab, |
8 | 13 | sendEventToTab, |
| 14 | + toggleActiveScript, |
9 | 15 | } from "../scripts/helpers/utils.js"; |
10 | 16 | import { allScripts } from "../scripts/index.js"; |
11 | 17 | import { checkForUpdate } from "./helpers/checkForUpdate.js"; |
@@ -146,12 +152,14 @@ function createScriptButton(script, isFavorite = false) { |
146 | 152 | buttonContainer.className = "buttonContainer"; |
147 | 153 |
|
148 | 154 | // button checker |
149 | | - if (isFunction(script.getActive)) { |
| 155 | + if ( |
| 156 | + ScriptType.contentScript in script || |
| 157 | + ScriptType.backgroundScript in script |
| 158 | + ) { |
150 | 159 | const checkmark = document.createElement("button"); |
151 | 160 | checkmark.className = "checkmark tooltip"; |
152 | 161 | checkmark.onclick = async (e) => { |
153 | | - let newValue = !(await script.getActive()); |
154 | | - await script.setActive(newValue); |
| 162 | + let newValue = await toggleActiveScript(script.id); |
155 | 163 | updateButtonChecker(script, buttonContainer, newValue); |
156 | 164 | }; |
157 | 165 |
|
@@ -264,7 +272,7 @@ function createScriptButton(script, isFavorite = false) { |
264 | 272 | async function updateButtonChecker(script, button, val) { |
265 | 273 | let checkmark = button.querySelector(".checkmark"); |
266 | 274 | if (!checkmark) return; |
267 | | - if (val ?? (await script.getActive?.())) { |
| 275 | + if (val ?? (await getActiveScript(script.id))) { |
268 | 276 | checkmark.classList.add("active"); |
269 | 277 | checkmark.title = t({ |
270 | 278 | vi: "Tắt tự động chạy", |
|
0 commit comments