Skip to content

Commit

Permalink
feat: add fixADBlock function for ad blocking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
IronKinoko committed Jun 29, 2024
1 parent 1e294ae commit 105ebe2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-carrots-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'linovelib': patch
---

fix: adblock
19 changes: 18 additions & 1 deletion packages/linovelib/src/h5/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isMobile, keybind, router } from 'shared'
import { isMobile, keybind, router, waitDOM } from 'shared'

export default async function main() {
if (!window.ReadTools) return
Expand All @@ -8,6 +8,23 @@ export default async function main() {
else injectShortcuts()
}

export async function fixADBlock() {
const res = await fetch(window.location.href)
const text = await res.text()
const html = new DOMParser().parseFromString(text, 'text/html')
const volumes = html.querySelector('#volumes')
if (!volumes) return

document.querySelector('#volumes')?.replaceWith(volumes)

try {
document.getElementById(
'bookmarkX'
// @ts-ignore
)!.innerHTML = `<div class="chapter-bar">阅读进度</div><span class="historyChapter"><a href="/novel/${targetRecord.articleid}/${targetRecord.chapterid}_${targetRecord.page}.html" class="chapter-li-a "><span class="chapter-index blue">${targetRecord.chaptername}</span></a></span>`
} catch (error) {}
}

function resetPageEvent() {
const $body = document.body
$body.onclick = (e) => {
Expand Down
10 changes: 8 additions & 2 deletions packages/linovelib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import h5 from './h5'
import h5, { fixADBlock } from './h5'
import pc from './pc'
import './index.scss'
import { router } from 'shared'
Expand All @@ -8,5 +8,11 @@ document.body.classList.add('k-wrapper')
router({ domain: ['//www.linovelib.com'], routes: [{ run: pc }] })
router({
domain: ['//w.linovelib.com', '//www.bilinovel.com'],
routes: [{ run: h5 }],
routes: [
{ run: h5 },
{
pathname: /(\/novel\/.*\/catalog)|(\/download\/.*\.html)/,
run: fixADBlock,
},
],
})

0 comments on commit 105ebe2

Please sign in to comment.