(script, isFavorite = false)
| 213 | } |
| 214 | |
| 215 | function createScriptButton(script, isFavorite = false) { |
| 216 | // Section title |
| 217 | if (isTitle(script)) { |
| 218 | const title = document.createElement("h3"); |
| 219 | title.innerHTML = t(script.name); |
| 220 | title.classList.add("section-title"); |
| 221 | |
| 222 | return title; |
| 223 | } |
| 224 | |
| 225 | // Button Container |
| 226 | const buttonContainer = document.createElement("div"); |
| 227 | buttonContainer.className = "buttonContainer"; |
| 228 | |
| 229 | // button checker |
| 230 | if (canAutoRun(script)) { |
| 231 | const checkmarkContainer = document.createElement("div"); |
| 232 | checkmarkContainer.setAttribute("data-flow", "right"); |
| 233 | |
| 234 | const checkmark = document.createElement("button"); |
| 235 | checkmark.className = "checkmark"; |
| 236 | checkmark.onclick = async (e) => { |
| 237 | if (checkIsPreview(script)) return; |
| 238 | |
| 239 | let oldVal = await isActiveScript(script.id); |
| 240 | let newVal = !oldVal; |
| 241 | |
| 242 | // ⚡ LAZY LOAD: Load full script for onEnable/onDisable |
| 243 | const fullScript = await loadFullScript(script.id); |
| 244 | |
| 245 | if ( |
| 246 | (newVal && (await fullScript.popupScript?.onEnable?.()) === false) || |
| 247 | (!newVal && (await fullScript.popupScript?.onDisable?.()) === false) |
| 248 | ) |
| 249 | return; |
| 250 | |
| 251 | setActiveScript(script.id, newVal); |
| 252 | trackEvent(script.id + (newVal ? "-ON" : "-OFF")); |
| 253 | updateButtonChecker(script, checkmarkContainer, newVal); |
| 254 | }; |
| 255 | |
| 256 | checkmarkContainer.appendChild(checkmark); |
| 257 | buttonContainer.appendChild(checkmarkContainer); |
| 258 | updateButtonChecker(script, checkmarkContainer); |
| 259 | } |
| 260 | |
| 261 | // button |
| 262 | const button = document.createElement("button"); |
| 263 | button.className = "tooltip"; |
| 264 | if (canClick(script)) { |
| 265 | button.onclick = () => { |
| 266 | if (checkIsPreview(script)) return; |
| 267 | runScript(script); |
| 268 | }; |
| 269 | } else if (canAutoRun(script)) { |
| 270 | button.onclick = () => { |
| 271 | if (checkIsPreview(script)) return; |
| 272 | openModal( |
no test coverage detected