Skip to content

Commit

Permalink
feat: adjust detection on github issues and wiki, close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
hikerpig committed Feb 1, 2021
1 parent 4d670a9 commit 6d6c26b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions toc-bar.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// @match *://www.smashingmagazine.com/*/*
// @match *://distill.pub/*
// @match *://github.com/*/*
// @match *://github.com/*/issues/*
// @match *://developer.mozilla.org/*/docs/*
// @match *://learning.oreilly.com/library/view/*
// @match *://developer.chrome.com/extensions/*
Expand Down Expand Up @@ -102,15 +103,21 @@
'github.com': {
contentSelector() {
const README_SEL = '#readme'
const WIKI_CONTENT_SEL = '.repository-content'
const matchedSel = [README_SEL, WIKI_CONTENT_SEL].find((sel) => {
return !!document.querySelector(README_SEL)
const WIKI_CONTENT_SEL = '#wiki-body'
const ISSUE_CONTENT_SEL = '.comment'
const matchedSel = [README_SEL, ISSUE_CONTENT_SEL, WIKI_CONTENT_SEL].find((sel) => {
return !!document.querySelector(sel)
})

if (matchedSel) return matchedSel

return false
},
scrollSmoothOffset() {
const isIssueDetail = /\/issues\//.test(location.pathname)
if (isIssueDetail) return -60
return 0
},
initialTop: 500,
},
'developer.mozilla.org': {
Expand Down Expand Up @@ -161,6 +168,9 @@
if (!contentSelector) return
siteSetting = {...siteSetting, contentSelector}
}
if (typeof siteSetting.scrollSmoothOffset === 'function') {
siteSetting.scrollSmoothOffset = {...siteSetting, scrollSmoothOffset: siteSetting.scrollSmoothOffset()}
}
console.log('[toc-bar] found site info for', siteInfo.siteName)
return siteSetting
}
Expand Down

0 comments on commit 6d6c26b

Please sign in to comment.