|
154 | 154 | }); |
155 | 155 | } |
156 | 156 |
|
| 157 | + function ensureStyle() { |
| 158 | + /* Re-inject the hiding style if Material's instant navigation removed it. */ |
| 159 | + if (!document.getElementById('utplsql-topbar-style')) { |
| 160 | + var s = document.createElement('style'); |
| 161 | + s.id = 'utplsql-topbar-style'; |
| 162 | + s.textContent = |
| 163 | + '.md-header__button:not([for="__search"]) { display: none !important; }' + |
| 164 | + '.md-header__option { position: absolute !important; left: -9999px !important; }' + |
| 165 | + '.md-top { top: 4.4rem !important; z-index: 11; }'; |
| 166 | + document.head.appendChild(s); |
| 167 | + } |
| 168 | + } |
| 169 | + |
157 | 170 | function inject() { |
| 171 | + ensureStyle(); |
| 172 | + |
158 | 173 | /* Topbar already in DOM — just sync state. */ |
159 | 174 | if (document.getElementById('utplsql-topbar')) { |
160 | 175 | updateActiveLink(); |
|
243 | 258 | }); |
244 | 259 | } |
245 | 260 |
|
246 | | - /* Hide Material's built-in header controls immediately — same pattern as |
247 | | - applyScheme — to prevent a flash where logo/palette appear before the |
248 | | - topbar is painted. A fallback timeout removes the style if the topbar |
249 | | - never gets built (e.g. script error), restoring Material's navigation. */ |
250 | | - if (!document.getElementById('utplsql-topbar-style')) { |
251 | | - var _style = document.createElement('style'); |
252 | | - _style.id = 'utplsql-topbar-style'; |
253 | | - _style.textContent = |
254 | | - '.md-header__button:not([for="__search"]) { display: none !important; }' + |
255 | | - '.md-header__option { position: absolute !important; left: -9999px !important; }' + |
256 | | - '.md-top { top: 4.4rem !important; z-index: 11; }'; |
257 | | - document.head.appendChild(_style); |
258 | | - /* Fallback: if topbar not in DOM after 4 s, restore Material's navigation */ |
259 | | - setTimeout(function () { |
260 | | - if (!document.getElementById('utplsql-topbar')) { |
261 | | - var s = document.getElementById('utplsql-topbar-style'); |
262 | | - if (s) s.parentNode.removeChild(s); |
263 | | - } |
264 | | - }, 4000); |
265 | | - } |
| 261 | + /* Hide Material's built-in header controls immediately to prevent a flash |
| 262 | + where logo/palette appear before the topbar is painted. */ |
| 263 | + ensureStyle(); |
| 264 | + /* Fallback: if topbar not in DOM after 4 s, restore Material's navigation. */ |
| 265 | + setTimeout(function () { |
| 266 | + if (!document.getElementById('utplsql-topbar')) { |
| 267 | + var s = document.getElementById('utplsql-topbar-style'); |
| 268 | + if (s) s.parentNode.removeChild(s); |
| 269 | + } |
| 270 | + }, 4000); |
266 | 271 |
|
267 | 272 | /* Apply initial scheme as early as possible to avoid flash. */ |
268 | 273 | applyScheme(effectiveScheme(getPreference())); |
|
0 commit comments