MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / createScriptButton

Function createScriptButton

popup/index.js:215–484  ·  view source on GitHub ↗
(script, isFavorite = false)

Source from the content-addressed store, hash-verified

213}
214
215function 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(

Callers 1

createTabContentFunction · 0.85

Calls 15

isTitleFunction · 0.90
tFunction · 0.90
canAutoRunFunction · 0.90
isActiveScriptFunction · 0.90
setActiveScriptFunction · 0.90
trackEventFunction · 0.90
canClickFunction · 0.90
openModalFunction · 0.90
viewScriptSourceFunction · 0.90
refreshSpecialTabsFunction · 0.90
checkIsPreviewFunction · 0.85
loadFullScriptFunction · 0.85

Tested by

no test coverage detected