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

Function refreshSpecialTabs

popup/tabs.js:405–470  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

403].flat();
404
405async function refreshSpecialTabs() {
406 // add data to special tabs
407 let recentTab = specialTabs.find((tab) => tab.id === CATEGORY.recently.id);
408 if (recentTab)
409 recentTab.scripts = recentScriptsSaver.get().map(enrichMetadata);
410
411 let favoriteTab = specialTabs.find((tab) => tab.id === CATEGORY.favorite.id);
412 if (favoriteTab)
413 favoriteTab.scripts = favoriteScriptsSaver.get().map(enrichMetadata);
414
415 let allTab = specialTabs.find((tab) => tab.id === CATEGORY.all.id);
416 if (allTab) allTab.scripts = sortScriptsByTab(allScriptInTabs, tabs);
417
418 let autoTab = specialTabs.find((tab) => tab.id === CATEGORY.autorun.id);
419 if (autoTab)
420 autoTab.scripts = sortScriptsByTab(
421 allScriptInTabs.filter((_) => canAutoRun(_)),
422 tabs
423 );
424
425 // update sticky favorites
426 tabs.forEach((tab) => {
427 // remove old sticky
428 tab.scripts = tab.scripts.filter((_) => !_.isStickyFavorite);
429
430 // add new sticky
431 let favoriteInTab = tab.scripts.filter(
432 (_) => favoriteScriptsSaver.has(_) && !_.isStickyFavorite
433 );
434 if (favoriteInTab.length) {
435 // add sticky flag
436 favoriteInTab = favoriteInTab.map((script) => {
437 return {
438 ...script,
439 isStickyFavorite: true,
440 };
441 });
442
443 // add block favorite sticky
444 let title = createTitle("--- Your Favorites ---", "--- Bạn đã thích ---");
445 title.isStickyFavorite = true;
446 tab.scripts = [title, ...favoriteInTab, ...tab.scripts];
447 }
448 });
449
450 // add auto runned scripts
451 let currentTab = await getCurrentTab();
452 if (!currentTab) return;
453 let bgCached = await chrome.runtime.sendMessage({
454 action: "ufs-runInBackground",
455 data: { fnPath: "getCache", params: ["badges"] },
456 });
457 let runnedScriptIds = bgCached?.[currentTab.id];
458 console.log(bgCached, currentTab.id, runnedScriptIds);
459 if (runnedScriptIds?.length) {
460 let scripts = allScriptInTabs.filter((_) => runnedScriptIds.includes(_.id));
461 let hostname = new URL(currentTab.url).hostname;
462 let title = createTitle(

Callers 2

createTabsFunction · 0.90
createScriptButtonFunction · 0.90

Calls 6

canAutoRunFunction · 0.90
getCurrentTabFunction · 0.90
sortScriptsByTabFunction · 0.85
createTitleFunction · 0.85
getMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected