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

Function createTabs

popup/index.js:119–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

117// ========================================================
118// #region tabs
119async function createTabs() {
120 // prepare tabs
121 await refreshSpecialTabs();
122
123 // clear UI
124 tabDiv.innerHTML = "";
125 contentDiv.innerHTML = "";
126
127 // make new UI
128 const allTabs = getAllTabs();
129 for (let tab of allTabs) {
130 // create tab button
131 const tabBtn = document.createElement("button");
132 tabBtn.className = "tablinks";
133 tabBtn.innerHTML = t(tab.name);
134 tabBtn.type = "button";
135 tabBtn.setAttribute("content-id", tab.id);
136
137 // show scripts count
138 if (tab.customCount || tab.showCount) {
139 let avaiCount =
140 tab.customCount ||
141 tab.scripts.filter((script) => !isTitle(script)).length;
142 if (avaiCount) tabBtn.innerHTML += ` (${avaiCount})`;
143 }
144
145 // custom style
146 if (tab.style && typeof tab.style === "object")
147 Object.entries(tab.style).forEach(([key, value]) => {
148 tabBtn.style[key] = value;
149 });
150
151 tabBtn.onclick = () => {
152 trackEvent("OPEN-TAB-" + tab.id);
153 openTab(tab);
154 };
155
156 tabDiv.appendChild(tabBtn);
157 }
158
159 // open tab
160 let activeTabId = activeTabIdSaver.get();
161 activeTabId && openTab(allTabs.find((tab) => tab.id === activeTabId));
162}
163
164async function openTab(tab) {
165 activeTabIdSaver.set(tab.id);

Callers 2

initSettingsFunction · 0.85
index.jsFile · 0.85

Calls 8

refreshSpecialTabsFunction · 0.90
getAllTabsFunction · 0.90
tFunction · 0.90
isTitleFunction · 0.90
trackEventFunction · 0.90
openTabFunction · 0.85
filterMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected