|
22 | 22 | // @match *://developer.mozilla.org/*/docs/*
|
23 | 23 | // @run-at document-idle
|
24 | 24 | // @grant GM_getResourceText
|
25 |
| -// @grant GM_addStyle |
26 | 25 | // @require https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.min.js
|
27 |
| -// @resource TOCBOT_STYLE https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.css |
28 | 26 | // @homepageURL https://github.com/hikerpig/toc-bar-userscript
|
29 | 27 | // @downloadURL https://raw.githubusercontent.com/hikerpig/toc-bar-userscript/master/toc-bar.user.js
|
30 | 28 | // ==/UserScript==
|
|
126 | 124 | }
|
127 | 125 |
|
128 | 126 | function loadStyles() {
|
129 |
| - const tocbotCss = GM_getResourceText('TOCBOT_STYLE') |
130 |
| - if (tocbotCss) { |
131 |
| - GM_addStyle(tocbotCss) |
132 |
| - } |
133 | 127 | }
|
134 | 128 |
|
135 | 129 | /**
|
|
234 | 228 | display: flex;
|
235 | 229 | }
|
236 | 230 |
|
237 |
| -/* override tocbot */ |
238 |
| -.toc-bar .toc { |
| 231 | +/* tocbot related */ |
| 232 | +.toc-bar__toc { |
239 | 233 | max-height: 80vh;
|
240 | 234 | }
|
241 | 235 |
|
242 |
| -.toc>.toc-list li { |
| 236 | +.toc-list-item > a:hover { |
| 237 | + text-decoration: underline; |
| 238 | +} |
| 239 | +
|
| 240 | +.toc-bar__toc > .toc-list { |
| 241 | + margin: 0; |
| 242 | + overflow: hidden; |
| 243 | + position: relative |
| 244 | +} |
| 245 | +
|
| 246 | +.toc-bar__toc>.toc-list li { |
| 247 | + list-style: none; |
243 | 248 | padding-left: 8px;
|
244 | 249 | position: static;
|
245 | 250 | }
|
246 | 251 |
|
247 |
| -.toc-list-item > a:hover { |
248 |
| - text-decoration: underline; |
| 252 | +a.toc-link { |
| 253 | + color: currentColor; |
| 254 | + height: 100% |
| 255 | +} |
| 256 | +
|
| 257 | +.is-collapsible { |
| 258 | + max-height: 1000px; |
| 259 | + overflow: hidden; |
| 260 | + transition: all 300ms ease-in-out |
| 261 | +} |
| 262 | +
|
| 263 | +.is-collapsed { |
| 264 | + max-height: 0 |
| 265 | +} |
| 266 | +
|
| 267 | +.is-position-fixed { |
| 268 | + position: fixed !important; |
| 269 | + top: 0 |
| 270 | +} |
| 271 | +
|
| 272 | +.is-active-link { |
| 273 | + font-weight: 700 |
| 274 | +} |
| 275 | +
|
| 276 | +.toc-link::before { |
| 277 | + background-color: #EEE; |
| 278 | + content: ' '; |
| 279 | + display: inline-block; |
| 280 | + height: inherit; |
| 281 | + left: 0; |
| 282 | + margin-top: -1px; |
| 283 | + position: absolute; |
| 284 | + width: 2px |
249 | 285 | }
|
250 |
| -/* end override tocbot */ |
| 286 | +
|
| 287 | +.is-active-link::before { |
| 288 | + background-color: #54BC4B |
| 289 | +} |
| 290 | +/* end tocbot related */ |
251 | 291 | `
|
252 | 292 |
|
| 293 | + const TOCBOT_CONTAINTER_CLASS = 'toc-bar__toc' |
| 294 | + |
253 | 295 | /**
|
254 | 296 | * @class
|
255 | 297 | */
|
|
270 | 312 | // create a container tocbot
|
271 | 313 | const tocElement = document.createElement('div')
|
272 | 314 | this.tocElement = tocElement
|
273 |
| - tocElement.classList.add('toc') |
| 315 | + tocElement.classList.add(TOCBOT_CONTAINTER_CLASS) |
274 | 316 | this.element.appendChild(tocElement)
|
275 | 317 | }
|
276 | 318 |
|
|
362 | 404 | const tocbotOptions = Object.assign(
|
363 | 405 | {},
|
364 | 406 | {
|
365 |
| - tocSelector: '.toc', |
| 407 | + tocSelector: `.${TOCBOT_CONTAINTER_CLASS}`, |
366 | 408 | scrollSmoothOffset: options.scrollSmoothOffset || 0,
|
367 | 409 | // hasInnerContainers: true,
|
368 | 410 | headingObjectCallback(obj, ele) {
|
|
0 commit comments