-
Notifications
You must be signed in to change notification settings - Fork 0
/
interceptor.js
40 lines (37 loc) · 1.1 KB
/
interceptor.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
document.title = 'useEffect - 搜索'
const customIconHref = document.querySelector('#__customIconHref').dataset.value
function changeIcon() {
const icon = document.querySelector('[rel~=shortcut]')
if (!icon) {
setTimeout(changeIcon, 0)
} else {
icon.href = customIconHref
}
}
changeIcon()
async function getContent() {
const contentNodes = [...document.querySelectorAll('.content-text')]
if (contentNodes.length > 0) {
return contentNodes.map(dom => dom.innerText)
} else {
return new Promise(resolve => {
setTimeout(() => resolve(getContent()), 0)
})
}
}
getContent().then(content => {
const contentDom = document.createElement('div')
contentDom.className = '-qidian-content'
contentDom.innerHTML =
`
${content.map(p => `<span>${p}</span><br>`).join('')}
`
contentDom.addEventListener('wheel', e => {
e.preventDefault()
contentDom.scrollBy({
behavior: 'smooth',
top: 20 * (e.deltaY > 0 ? 1 : -1)
})
})
document.documentElement.appendChild(contentDom)
})