Skip to content

Commit 5ebdde0

Browse files
committed
feat: remove tocbot style resource, add a modified version to tocbar style
1 parent b1334c6 commit 5ebdde0

File tree

1 file changed

+56
-14
lines changed

1 file changed

+56
-14
lines changed

toc-bar.user.js

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
// @match *://developer.mozilla.org/*/docs/*
2323
// @run-at document-idle
2424
// @grant GM_getResourceText
25-
// @grant GM_addStyle
2625
// @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
2826
// @homepageURL https://github.com/hikerpig/toc-bar-userscript
2927
// @downloadURL https://raw.githubusercontent.com/hikerpig/toc-bar-userscript/master/toc-bar.user.js
3028
// ==/UserScript==
@@ -126,10 +124,6 @@
126124
}
127125

128126
function loadStyles() {
129-
const tocbotCss = GM_getResourceText('TOCBOT_STYLE')
130-
if (tocbotCss) {
131-
GM_addStyle(tocbotCss)
132-
}
133127
}
134128

135129
/**
@@ -234,22 +228,70 @@
234228
display: flex;
235229
}
236230
237-
/* override tocbot */
238-
.toc-bar .toc {
231+
/* tocbot related */
232+
.toc-bar__toc {
239233
max-height: 80vh;
240234
}
241235
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;
243248
padding-left: 8px;
244249
position: static;
245250
}
246251
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
249285
}
250-
/* end override tocbot */
286+
287+
.is-active-link::before {
288+
background-color: #54BC4B
289+
}
290+
/* end tocbot related */
251291
`
252292

293+
const TOCBOT_CONTAINTER_CLASS = 'toc-bar__toc'
294+
253295
/**
254296
* @class
255297
*/
@@ -270,7 +312,7 @@
270312
// create a container tocbot
271313
const tocElement = document.createElement('div')
272314
this.tocElement = tocElement
273-
tocElement.classList.add('toc')
315+
tocElement.classList.add(TOCBOT_CONTAINTER_CLASS)
274316
this.element.appendChild(tocElement)
275317
}
276318

@@ -362,7 +404,7 @@
362404
const tocbotOptions = Object.assign(
363405
{},
364406
{
365-
tocSelector: '.toc',
407+
tocSelector: `.${TOCBOT_CONTAINTER_CLASS}`,
366408
scrollSmoothOffset: options.scrollSmoothOffset || 0,
367409
// hasInnerContainers: true,
368410
headingObjectCallback(obj, ele) {

0 commit comments

Comments
 (0)