Skip to content

Commit

Permalink
feat: support bilinovel
Browse files Browse the repository at this point in the history
  • Loading branch information
IronKinoko committed Jan 3, 2024
1 parent 4cf8587 commit e737fb4
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-games-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'novel-speech-synthesis': patch
---

feat: support bilinovel
2 changes: 2 additions & 0 deletions packages/novel-speech-synthesis/meta.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// @author IronKinoko
// @match https://hans.bilixs.com/*
// @match https://www.bilixs.com/*
// @match https://www.bilinovel.com/*
// @match https://www.linovelib.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=
// @grant none
// @noframes
Expand Down
34 changes: 34 additions & 0 deletions packages/novel-speech-synthesis/src/adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,38 @@ export const adapter: Record<string, SpeechOptions> = {
dom?.click()
},
},
linovelib: {
container: 'body',
lang: 'zh-CN',
getParagraph: () => {
const content = document.querySelector('.read-content')
if (!content) throw new Error('content not found')

// 这个站点会插入一些脏数据防盗,需要过滤掉
return Array.from(content.querySelectorAll('p')).filter(
(o) => o.clientHeight
)
},
nextChapter() {
const dom = document.querySelectorAll<HTMLAnchorElement>('.mlfy_page a')
Array.from(dom)
.find((d) => d.innerText.match(/下一[章页]/))
?.click()
},
},
bilinovel: {
container: 'body',
lang: 'zh-CN',
getParagraph: () => {
const content = document.querySelector('#acontentz')
if (!content) throw new Error('content not found')

return Array.from(content.querySelectorAll('p'))
},
nextChapter() {
document
.querySelector<HTMLAnchorElement>('#footlink > a:last-child')
?.click()
},
},
}
24 changes: 24 additions & 0 deletions packages/novel-speech-synthesis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,27 @@ router({
},
],
})

router({
domain: ['linovelib.com'],
routes: [
{
path: /novel\/.*\/.*\.html/,
run: () => {
new Speech(adapter.linovelib)
},
},
],
})

router({
domain: ['bilinovel.com'],
routes: [
{
path: /novel\/.*\/.*\.html/,
run: () => {
new Speech(adapter.bilinovel)
},
},
],
})
14 changes: 10 additions & 4 deletions packages/novel-speech-synthesis/src/speech/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.speech-controls-buttons {
display: flex;
flex-direction: row;
align-items: center;
align-items: stretch;
justify-content: center;
font-size: 16px;
}
Expand All @@ -24,15 +24,21 @@
width: 35px;
text-align: center;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
.speech-controls-button + .speech-controls-button {
border-left: 1px solid #ddd;
}

.speech-controls-voice,
.speech-controls-rate {
width: 100%;
select {
text-align: center;
appearance: none;
border: none;
background: transparent;
outline: none;
color: inherit;
}

.speech-controls-play {
Expand Down
96 changes: 45 additions & 51 deletions packages/novel-speech-synthesis/src/speech/ui.template.html
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
<div id="speech">
<div class="speech-controls">
<div class="speech-controls-buttons">
<div class="speech-controls-button">
<label class="speech-controls-play">
<input type="checkbox" hidden />
<svg
viewBox="0 0 1024 1024"
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
>
<path
d="M817.088 484.96l-512-323.744c-9.856-6.24-22.336-6.624-32.512-.992A31.993 31.993 0 0 0 256 188.256v647.328c0 11.648 6.336 22.4 16.576 28.032A31.82 31.82 0 0 0 288 867.584a32.107 32.107 0 0 0 17.088-4.928l512-323.616A31.976 31.976 0 0 0 832 512a31.976 31.976 0 0 0-14.912-27.04z"
fill="currentColor"
/>
</svg>
<svg
viewBox="0 0 1024 1024"
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
>
<path
d="M597.333 816.64H768V219.307H597.333M256 816.64h170.667V219.307H256V816.64z"
fill="currentColor"
/>
</svg>
</label>
</div>
<div class="speech-controls-button">
<select class="speech-controls-voice"></select>
</div>
<div class="speech-controls-button">
<select class="speech-controls-rate">
<option value="1">1x</option>
<option value="1.25">1.25x</option>
<option value="1.5">1.5x</option>
<option value="1.75">1.75x</option>
<option value="2">2x</option>
<option value="2.25">2.25x</option>
<option value="2.5">2.5x</option>
<option value="3">3x</option>
<option value="3.5">3.5x</option>
<option value="4">4x</option>
<option value="4.5">4.5x</option>
<option value="5">5x</option>
<option value="6">6x</option>
<option value="7">7x</option>
<option value="8">8x</option>
<option value="9">9x</option>
<option value="10">10x</option>
</select>
</div>
<label class="speech-controls-button speech-controls-play">
<input type="checkbox" hidden />
<svg
viewBox="0 0 1024 1024"
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
>
<path
d="M817.088 484.96l-512-323.744c-9.856-6.24-22.336-6.624-32.512-.992A31.993 31.993 0 0 0 256 188.256v647.328c0 11.648 6.336 22.4 16.576 28.032A31.82 31.82 0 0 0 288 867.584a32.107 32.107 0 0 0 17.088-4.928l512-323.616A31.976 31.976 0 0 0 832 512a31.976 31.976 0 0 0-14.912-27.04z"
fill="currentColor"
/>
</svg>
<svg
viewBox="0 0 1024 1024"
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
>
<path
d="M597.333 816.64H768V219.307H597.333M256 816.64h170.667V219.307H256V816.64z"
fill="currentColor"
/>
</svg>
</label>
<select class="speech-controls-button speech-controls-voice"></select>
<select class="speech-controls-button speech-controls-rate">
<option value="1">1x</option>
<option value="1.25">1.25x</option>
<option value="1.5">1.5x</option>
<option value="1.75">1.75x</option>
<option value="2">2x</option>
<option value="2.25">2.25x</option>
<option value="2.5">2.5x</option>
<option value="3">3x</option>
<option value="3.5">3.5x</option>
<option value="4">4x</option>
<option value="4.5">4.5x</option>
<option value="5">5x</option>
<option value="6">6x</option>
<option value="7">7x</option>
<option value="8">8x</option>
<option value="9">9x</option>
<option value="10">10x</option>
</select>
<label class="speech-controls-button speech-controls-continuous">
<input type="checkbox" hidden />
<span>C</span>
Expand Down

0 comments on commit e737fb4

Please sign in to comment.