Skip to content

Commit 97f16eb

Browse files
committed
docs: 📝 更新文档
1 parent 3379a32 commit 97f16eb

9 files changed

Lines changed: 95 additions & 2 deletions

File tree

.oxlintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"**/public/**",
2727
"**/dev-dist/**",
2828
"**/assets/**",
29-
"**/**.js"
29+
"**/**.js",
30+
"ComicReader.umd.d.ts"
3031
],
3132
"rules": {
3233
// 目前不支持跳过 return new Promise 的,只能暂时关掉

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
**/*.json5
55
**/public/*
66
*.user.js
7+
*.umd.js
8+
*.umd.d.ts

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
3434
> 如果喜欢这种阅读模式,也想用来看**本地漫画**的话,欢迎使用「[ComicRead PWA](https://comic-read.pages.dev/)」,只要打开网页拖入本地漫画即可获得完全一致的体验
3535
36+
> 想要在自己的网站或项目上使用脚本的阅读模式的话,可参看[相关文档](https://github.com/hymbz/ComicReadScript/blob/master/docs/NPM%20模块.md)
37+
3638
<blockquote>
3739
<p>
3840
对你有帮助的话就点个⭐Star吧

docs/.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default defineConfig({
3434
},
3535

3636
{ text: '最简单的本地部署翻译服务流程', link: '/本地部署翻译' },
37+
{ text: 'NPM 模块', link: '/NPM 模块' },
3738
{ text: '无法解决的问题', link: '/无法解决的问题' },
3839
],
3940

docs/NPM 模块.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## 导入
2+
3+
### NPM
4+
5+
```js
6+
import { initComicReader } from '@hymbz/comic-read-script/dist/umd.js'
7+
8+
const ComicReader = initComicReader();
9+
ComicReader.open(['/1.png', '/2.png', '/3.png']);
10+
```
11+
12+
### CDN
13+
14+
```html
15+
<script src="https://cdn.jsdelivr.net/npm/@hymbz/comic-read-script/ComicReader.umd.js"></script>
16+
<script>
17+
const { initComicReader } = window.ComicReadScript;
18+
const ComicReader = initComicReader();
19+
ComicReader.open(['/1.png', '/2.png', '/3.png']);
20+
</script>
21+
```
22+
23+
## 配置
24+
25+
正常无需任何配置,就已经可以使用阅读模式的大部分功能了,但仍有一些功能需要提供油猴 API 才能使用。
26+
27+
### GM.getValue / GM.setValue
28+
29+
脚本会用这俩 API 来保存:显示语言设置、3.3M 的图片无损放大模型(模型只在用到时才会下载缓存)。另外也能顺便用这俩 API 来存储脚本的阅读配置和快捷键。
30+
31+
### GM_xmlhttpRequest
32+
33+
不提供这个 API 的话就只能使用 fetch 来发起请求了,如果没有 CORS 之类的限制的话,那除了无法使用 Cotrans 翻译外好像也没什么影响。
34+
35+
### 使用默认配置
36+
37+
```js
38+
import { initComicReader, defaultConfig } from '@hymbz/comic-read-script'
39+
40+
const ComicReader = initComicReader(defaultConfig());
41+
```
42+
43+
默认配置并不会默认启用,需要手动传入。
44+
45+
使用 localStorage 来实现 GM.getValue 和 GM.setValue,同时配置好了阅读配置和快捷键设置的存储,并会在版本更新时自动删掉旧的配置,详见[代码](https://github.com/hymbz/ComicReadScript/blob/master/src/umd.tsx#L177-L205)
46+
47+
### 自定义配置
48+
49+
```js
50+
import { initComicReader } from '@hymbz/comic-read-script/dist/umd.js'
51+
52+
const getValue = (name, defaultValue) => { /* xxx */ };
53+
const setValue = (name, value) => { /* xxx */ };
54+
const GM_xmlhttpRequest = (details) => { /* xxx */ };
55+
56+
const ComicReader = initComicReader({
57+
polyfill: {
58+
GM: { getValue, setValue },
59+
GM_xmlhttpRequest,
60+
},
61+
props: {
62+
option: getValue('@Option'),
63+
onOptionChange: (option) => setValue('@Option', option),
64+
hotkeys: getValue('@Hotkeys'),
65+
onHotkeysChange: (hotkeys) => setValue('@Hotkeys', hotkeys),
66+
},
67+
});
68+
```
69+
70+
props 的具体定义详见 [ComicReader.umd.d.ts](https://github.com/hymbz/ComicReadScript/blob/master/ComicReader.umd.d.ts#L306-L329) 里的 MangaProps 类型。
71+
72+
## 方法
73+
74+
```js
75+
const ComicReader = initComicReader();
76+
77+
// 加载显示指定的图片列表。标题用于打包下载时命名压缩包,没有标题时会使用网页标题
78+
ComicReader.open(['/1.png', '/2.png', '/3.png'], '标题');
79+
// 关闭阅读模式
80+
ComicReader.setProps('show', false);
81+
// 跳到指定页数(注意在双页模式下,页数不等于图片在列表里的序列数)
82+
ComicReader.goto(1);
83+
```

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
3434
> 如果喜欢这种阅读模式,也想用来看**本地漫画**的话,欢迎使用「[ComicRead PWA](https://comic-read.pages.dev/)」,只要打开网页拖入本地漫画即可获得完全一致的体验
3535
36+
> 想要在自己的网站或项目上使用脚本的阅读模式的话,可参看[相关文档](https://github.com/hymbz/ComicReadScript/blob/master/docs/NPM%20模块.md)
37+
3638
<blockquote>
3739
<p>
3840
对你有帮助的话就点个⭐Star吧

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default antfu(
3030
'**/dev-dist/**',
3131
'**/assets/**',
3232
'**/**.js',
33+
'ComicReader.umd.d.ts',
3334
],
3435
},
3536
{

release.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ const exec = (...commands) => {
6969
}
7070

7171
// 测试
72-
exec('pnpm test run');
7372
exec('pnpm check');
73+
exec('pnpm test run');
7474

7575
// 使用 release-it 更新版本,并获得更新日志
7676
const { changelog } = await release({

src/rollup-plugin/ehRules.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { OutputPluginOption } from 'rollup';
2+
23
import { codeEdit } from './codeEdit';
34

45
/** 调整 ehRules 结构以减少代码量 */

0 commit comments

Comments
 (0)