()
| 117 | // ======================================================== |
| 118 | // #region tabs |
| 119 | async 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 | |
| 164 | async function openTab(tab) { |
| 165 | activeTabIdSaver.set(tab.id); |
no test coverage detected