Skip to content

Commit ba90dac

Browse files
committed
feat: Add logo, and adjust some styles
1 parent 35e0c54 commit ba90dac

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

toc-bar.user.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// @match *://zhuanlan.zhihu.com/p/*
1212
// @match *://mp.weixin.qq.com/s*
1313
// @match *://cnodejs.org/topic/*
14-
// @match *://www.zcfy.cc/article/*
14+
// @match *://*zcfy.cc/article/*
1515
// @match *://dev.to/*
1616
// @match *://web.dev/*
1717
// @match *://medium.com/*
@@ -49,6 +49,9 @@
4949
qq: {
5050
contentSelector: '.rich_media_content',
5151
},
52+
'juejin.im': {
53+
contentSelector: '.entry-public-main',
54+
},
5255
'dev.to': {
5356
contentSelector: 'article',
5457
scrollSmoothOffset: -56,
@@ -153,7 +156,7 @@
153156
width: 340px;
154157
font-size: 14px;
155158
box-sizing: border-box;
156-
padding: 10px 10px 10px 0;
159+
padding: 0 10px 10px 0;
157160
box-shadow: 0 1px 3px #DDD;
158161
border-radius: 4px;
159162
transition: width 0.2s ease;
@@ -163,17 +166,15 @@
163166
164167
.toc-bar.toc-bar--collapsed {
165168
width: 30px;
169+
height: 30px;
166170
padding: 0;
171+
overflow: hidden;
167172
}
168173
169174
.toc-bar--collapsed .toc {
170175
display: none;
171176
}
172177
173-
.toc-bar--collapsed .toc-bar__toggle {
174-
transform: rotate(90deg);
175-
}
176-
177178
.toc-bar--collapsed .hidden-when-collapsed {
178179
display: none;
179180
}
@@ -206,6 +207,7 @@
206207
.toc-bar__icon-btn svg {
207208
max-width: 100%;
208209
max-height: 100%;
210+
vertical-align: top;
209211
}
210212
211213
.toc-bar__header-left {
@@ -214,9 +216,8 @@
214216
215217
.toc-bar__toggle {
216218
cursor: pointer;
217-
padding: 2px 6px;
219+
padding: 8px 8px;
218220
box-sizing: content-box;
219-
transform: rotate(0);
220221
transition: transform 0.2s ease;
221222
}
222223
@@ -245,6 +246,10 @@
245246
text-decoration: underline;
246247
}
247248
249+
.toc-list {
250+
padding-inline-start: 0;
251+
}
252+
248253
.toc-bar__toc > .toc-list {
249254
margin: 0;
250255
overflow: hidden;
@@ -325,9 +330,23 @@ a.toc-link {
325330
this.element.appendChild(tocElement)
326331
}
327332

328-
const TOC_ICON = `<svg t="1593614506959" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6049" width="200" height="200"><path d="M128 384h597.333333v-85.333333H128v85.333333z m0 170.666667h597.333333v-85.333334H128v85.333334z m0 170.666666h597.333333v-85.333333H128v85.333333z m682.666667 0h85.333333v-85.333333h-85.333333v85.333333z m0-426.666666v85.333333h85.333333v-85.333333h-85.333333z m0 256h85.333333v-85.333334h-85.333333v85.333334z" p-id="6050"></path></svg>`
329333
const REFRESH_ICON = `<svg t="1593614403764" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5002" width="200" height="200"><path d="M918 702.8 918 702.8c45.6-98.8 52-206 26-303.6-30-112.4-104-212.8-211.6-273.6L780 23.2l-270.8 70.8 121.2 252.4 50-107.6c72.8 44.4 122.8 114.4 144 192.8 18.8 70.8 14.4 147.6-18.8 219.6-42 91.2-120.8 153.6-210.8 177.6-13.2 3.6-26.4 6-39.6 8l56 115.6c5.2-1.2 10.4-2.4 16-4C750.8 915.2 860 828.8 918 702.8L918 702.8M343.2 793.2c-74-44.4-124.8-114.8-146-194-18.8-70.8-14.4-147.6 18.8-219.6 42-91.2 120.8-153.6 210.8-177.6 14.8-4 30-6.8 45.6-8.8l-55.6-116c-7.2 1.6-14.8 3.2-22 5.2-124 33.2-233.6 119.6-291.2 245.6-45.6 98.8-52 206-26 303.2l0 0.4c30.4 113.2 105.2 214 213.6 274.8l-45.2 98 270.4-72-122-252L343.2 793.2 343.2 793.2M343.2 793.2 343.2 793.2z" p-id="5003"></path></svg>`
330334

335+
const TOC_ICON = `
336+
<?xml version="1.0" encoding="utf-8"?>
337+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
338+
viewBox="0 0 1024 1024" style="enable-background:new 0 0 1024 1024;" xml:space="preserve">
339+
<g>
340+
<g>
341+
<path d="M835.2,45.9H105.2v166.8l93.2,61.5h115.8H356h30.6v-82.8H134.2v-24.9h286.2v107.6h32.2V141.6H134.2V118h672.1v23.6H486.4
342+
v132.5h32V166.5h287.8v24.9H553.8v82.8h114.1H693h225.6V114.5L835.2,45.9z M806.2,93.2H134.2V67.2h672.1v26.1H806.2z"/>
343+
<polygon points="449.3,1008.2 668,1008.2 668,268.9 553.8,268.9 553.8,925.4 518.4,925.4 518.4,268.9 486.4,268.9 486.4,925.4
344+
452.6,925.4 452.6,268.9 420.4,268.9 420.4,925.4 386.6,925.4 386.6,268.9 356,268.9 356,946.7 "/>
345+
</g>
346+
</g>
347+
</svg>
348+
`
349+
331350
TocBar.prototype = {
332351
/**
333352
* @method TocBar
@@ -352,6 +371,7 @@ a.toc-link {
352371
toggleElement.addEventListener('click', () => {
353372
this.toggle()
354373
})
374+
this.logoSvg = toggleElement.querySelector('svg')
355375

356376
const refreshElement = header.querySelector('.toc-bar__refresh')
357377
refreshElement.addEventListener('click', () => {
@@ -441,10 +461,13 @@ a.toc-link {
441461
*/
442462
toggle(shouldShow = !this.visible) {
443463
const HIDDEN_CLASS = 'toc-bar--collapsed'
464+
const LOGO_HIDDEN_CLASS = 'toc-logo--collapsed'
444465
if (shouldShow) {
445466
this.element.classList.remove(HIDDEN_CLASS)
467+
this.logoSvg && this.logoSvg.classList.remove(LOGO_HIDDEN_CLASS)
446468
} else {
447469
this.element.classList.add(HIDDEN_CLASS)
470+
this.logoSvg && this.logoSvg.classList.add(LOGO_HIDDEN_CLASS)
448471
}
449472
this.visible = shouldShow
450473
},

toc-logo.svg

Lines changed: 12 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)