Skip to content

Commit 6d6c26b

Browse files
committed
feat: adjust detection on github issues and wiki, close #2
1 parent 4d670a9 commit 6d6c26b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

toc-bar.user.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// @match *://www.smashingmagazine.com/*/*
2727
// @match *://distill.pub/*
2828
// @match *://github.com/*/*
29+
// @match *://github.com/*/issues/*
2930
// @match *://developer.mozilla.org/*/docs/*
3031
// @match *://learning.oreilly.com/library/view/*
3132
// @match *://developer.chrome.com/extensions/*
@@ -102,15 +103,21 @@
102103
'github.com': {
103104
contentSelector() {
104105
const README_SEL = '#readme'
105-
const WIKI_CONTENT_SEL = '.repository-content'
106-
const matchedSel = [README_SEL, WIKI_CONTENT_SEL].find((sel) => {
107-
return !!document.querySelector(README_SEL)
106+
const WIKI_CONTENT_SEL = '#wiki-body'
107+
const ISSUE_CONTENT_SEL = '.comment'
108+
const matchedSel = [README_SEL, ISSUE_CONTENT_SEL, WIKI_CONTENT_SEL].find((sel) => {
109+
return !!document.querySelector(sel)
108110
})
109111

110112
if (matchedSel) return matchedSel
111113

112114
return false
113115
},
116+
scrollSmoothOffset() {
117+
const isIssueDetail = /\/issues\//.test(location.pathname)
118+
if (isIssueDetail) return -60
119+
return 0
120+
},
114121
initialTop: 500,
115122
},
116123
'developer.mozilla.org': {
@@ -161,6 +168,9 @@
161168
if (!contentSelector) return
162169
siteSetting = {...siteSetting, contentSelector}
163170
}
171+
if (typeof siteSetting.scrollSmoothOffset === 'function') {
172+
siteSetting.scrollSmoothOffset = {...siteSetting, scrollSmoothOffset: siteSetting.scrollSmoothOffset()}
173+
}
164174
console.log('[toc-bar] found site info for', siteInfo.siteName)
165175
return siteSetting
166176
}

0 commit comments

Comments
 (0)