-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
72 lines (63 loc) · 2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
;(() => {
window.$docsify = {
name: 'Rod',
loadNavbar: true,
loadSidebar: true,
auto2top: true,
subMaxLevel: 3,
search: {
namespace: location.pathname,
placeholder: l('search-placeholder'),
noData: l('search-noData'),
},
plugins: [pluginChapterNav, zoomImg, analytics]
}
function pluginChapterNav(hook, vm) {
const chapterNav = document.querySelector('#chapter-nav')
hook.doneEach(() => {
gtag('set', 'page_path', vm.route.path)
gtag('event', 'page_view')
const list = Array.from(document.querySelectorAll(`.sidebar-nav a:not(.section-link)`))
const i = list.findIndex(e => e.getAttribute('href') === '#' + vm.route.path)
const article = document.querySelector('article')
article.appendChild(chapterNav)
const btnPrev = chapterNav.querySelector('.prev')
const btnNext = chapterNav.querySelector('.next')
if (i > 0) {
btnPrev.href = list[i - 1].getAttribute('href')
btnPrev.querySelector('.title').textContent = list[i - 1].textContent
btnPrev.style.display = 'block'
} else {
btnPrev.style.display = 'none'
}
if (i < list.length - 1) {
btnNext.href = list[i + 1].getAttribute('href')
btnNext.querySelector('.title').textContent = list[i + 1].textContent
btnNext.style.display = 'block'
} else {
btnNext.style.display = 'none'
}
chapterNav.style.display = 'flex'
})
}
function zoomImg(hook, vm) {
hook.doneEach(() => {
new Zooming({
bgColor: 'rgba(28, 35, 37, 0.9)',
}).listen('article img')
})
}
function l(key) {
return document.querySelector(`#strings [${key}]`).textContent
}
function analytics(hook, vm) {
// If stay on any page for more than 30s, we count it as a conversion
let id
hook.doneEach(() => {
clearTimeout(id)
id = setTimeout(() => {
gtag('event', 'conversion', { path: vm.route.path })
}, 30*1000);
})
}
})()