Skip to content

Commit 61b0eab

Browse files
committed
optimize: should ignore empty cachedPosition
1 parent c33e258 commit 61b0eab

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

toc-bar.user.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
}
140140
}
141141

142-
143142
function guessThemeColor() {
144143
const meta = document.head.querySelector('meta[name="theme-color"]')
145144
if (meta) {
@@ -176,6 +175,13 @@
176175
},
177176
}
178177

178+
function isEmpty(input) {
179+
if (input) {
180+
return Object.keys(input).length > 0
181+
}
182+
return true
183+
}
184+
179185
// ---------------- TocBar ----------------------
180186
const TOC_BAR_STYLE = `
181187
.toc-bar {
@@ -365,7 +371,7 @@ a.toc-link {
365371
this.element.appendChild(tocElement)
366372

367373
const cachedPosition = POSITION_STORAGE.get(options.siteName)
368-
if (cachedPosition) {
374+
if (!isEmpty(cachedPosition)) {
369375
this.element.style.top = `${cachedPosition.top}px`
370376
this.element.style.right = `${cachedPosition.right}px`
371377
} else if (options.hasOwnProperty('initialTop')) {

0 commit comments

Comments
 (0)