Skip to content

Commit 5d0bc14

Browse files
committed
feat: ✨ ehentai 上使用左右方向键在列表页和详情页翻页功能,改为使用设置中的「向左/右滚动」快捷键
1 parent 5298a71 commit 5d0bc14

10 files changed

Lines changed: 53 additions & 39 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Cotrans 也有自己的油猴脚本 —— 「[Cotrans 漫画/图片翻译器](h
169169
- [动漫之家](https://manhua.idmzj.com)
170170
- 解锁隐藏漫画
171171
- [E-Hentai](https://e-hentai.org)
172-
- [关联 nhentai](#关联-nhentai)
172+
- [关联外站](#关联外站)
173173
- [快捷收藏](#快捷收藏)
174174
- [标签染色](#标签染色)
175175
- [悬浮标签列表](#悬浮标签列表)
@@ -348,9 +348,9 @@ Cotrans 也有自己的油猴脚本 —— 「[Cotrans 漫画/图片翻译器](h
348348

349349
在详情页内嵌查看标签定义。
350350

351-
### 快捷键
351+
### 增加快捷键操作
352352

353-
- 使用`左右方向键`在列表页和详情页翻页
353+
- 使用设置中的`向左/右滚动`快捷键在列表页和详情页翻页
354354
- 使用`上下方向键`进行标签投票
355355
- 使用`ESC`取消选中当前标签
356356

docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Cotrans 也有自己的油猴脚本 —— 「[Cotrans 漫画/图片翻译器](h
169169
- [动漫之家](https://manhua.idmzj.com)
170170
- 解锁隐藏漫画
171171
- [E-Hentai](https://e-hentai.org)
172-
- [关联 nhentai](#关联-nhentai)
172+
- [关联外站](#关联外站)
173173
- [快捷收藏](#快捷收藏)
174174
- [标签染色](#标签染色)
175175
- [悬浮标签列表](#悬浮标签列表)
@@ -348,9 +348,9 @@ Cotrans 也有自己的油猴脚本 —— 「[Cotrans 漫画/图片翻译器](h
348348

349349
在详情页内嵌查看标签定义。
350350

351-
### 快捷键
351+
### 增加快捷键操作
352352

353-
- 使用`左右方向键`在列表页和详情页翻页
353+
- 使用设置中的`向左/右滚动`快捷键在列表页和详情页翻页
354354
- 使用`上下方向键`进行标签投票
355355
- 使用`ESC`取消选中当前标签
356356

locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
},
202202
"site": {
203203
"add_feature": {
204+
"add_hotkeys_actions": "Add hotkeys actions",
204205
"auto_adjust_option": "Auto adjust reading option",
205206
"auto_page_turn": "Infinite scroll",
206207
"auto_show": "Auto enter reading mode",

locales/hu.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
},
202202
"site": {
203203
"add_feature": {
204+
"add_hotkeys_actions": "Gyorsbillentyű-műveletek hozzáadása",
204205
"auto_adjust_option": "自动调整阅读配置",
205206
"auto_page_turn": "无限滚动",
206207
"auto_show": "自动进入阅读模式",

locales/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
},
202202
"site": {
203203
"add_feature": {
204+
"add_hotkeys_actions": "Добавить операции с горячими клавишами",
204205
"auto_adjust_option": "Автоматическая настройка параметра чтения",
205206
"auto_page_turn": "Автопереворот страниц",
206207
"auto_show": "Автоматически включать режим чтения",

locales/ta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
},
202202
"site": {
203203
"add_feature": {
204+
"add_hotkeys_actions": "குறுக்குவழி விசை செயல்பாடுகளைச் சேர்க்கவும்",
204205
"auto_adjust_option": "தானியங்கி சரிசெய்தல் வாசிப்பு உள்ளமைவு",
205206
"auto_page_turn": "எல்லையற்ற உருட்டல்",
206207
"auto_show": "தானாகவே வாசிப்பு பயன்முறையை உள்ளிடவும்",

locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
},
202202
"site": {
203203
"add_feature": {
204+
"add_hotkeys_actions": "增加快捷键操作",
204205
"auto_adjust_option": "自动调整阅读配置",
205206
"auto_page_turn": "无限滚动",
206207
"auto_show": "自动进入阅读模式",

src/site/ehentai/hotkeys.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
1-
import { linstenKeydown, querySelector } from 'helper';
1+
import { hotkeysMap } from 'components/Manga';
2+
import { getKeyboardCode, linstenKeydown, querySelector } from 'helper';
23

34
import { setEscHandler, type EhContext } from './helper';
45

5-
/** 快捷键翻页 */
6-
export const hotkeysPageTurn = (context: EhContext) => {
7-
if (!context.options.hotkeys) return;
6+
export const addHotkeysActions = (context: EhContext) => {
7+
if (!context.options.add_hotkeys_actions) return;
88

99
if (context.type === 'gallery') {
1010
setEscHandler(0, () =>
1111
unsafeWindow.selected_tagname ? unsafeWindow.toggle_tagmenu() : true,
1212
);
1313

1414
linstenKeydown((e) => {
15-
switch (e.key) {
16-
case 'ArrowRight':
17-
case 'd':
18-
e.preventDefault();
19-
return querySelector('.ptt td:last-child:not(.ptdd)')?.click();
20-
21-
case 'ArrowLeft':
22-
case 'a':
23-
e.preventDefault();
24-
return querySelector('.ptt td:first-child:not(.ptdd)')?.click();
15+
// 使用上下方向键进行投票
16+
if (unsafeWindow.selected_tagid) {
17+
switch (e.key) {
18+
case 'ArrowUp':
19+
e.preventDefault();
20+
return unsafeWindow?.tag_vote_up();
21+
case 'ArrowDown':
22+
e.preventDefault();
23+
return unsafeWindow?.tag_vote_down();
24+
}
2525
}
2626

27-
// 使用上下方向键进行投票
28-
if (!unsafeWindow.selected_tagid) return;
29-
switch (e.key) {
30-
case 'ArrowUp':
27+
switch (hotkeysMap()[getKeyboardCode(e)]) {
28+
case 'scroll_right':
3129
e.preventDefault();
32-
return unsafeWindow?.tag_vote_up();
33-
case 'ArrowDown':
30+
return querySelector('.ptt td:last-child:not(.ptdd)')?.click();
31+
case 'scroll_left':
3432
e.preventDefault();
35-
return unsafeWindow?.tag_vote_down();
33+
return querySelector('.ptt td:first-child:not(.ptdd)')?.click();
3634
}
3735
});
3836
} else {
3937
linstenKeydown((e) => {
40-
switch (e.key) {
41-
case 'ArrowRight':
42-
case 'd':
38+
switch (hotkeysMap()[getKeyboardCode(e)]) {
39+
case 'scroll_right':
4340
e.preventDefault();
4441
return querySelector('#unext')?.click();
45-
46-
case 'ArrowLeft':
47-
case 'a':
42+
case 'scroll_left':
4843
e.preventDefault();
4944
return querySelector('#uprev')?.click();
5045
}

src/site/ehentai/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
import { escHandler, createEhContext } from './helper';
3232
import { quickFavorite } from './quickFavorite';
3333
import { crossSiteLink } from './crossSiteLink';
34-
import { hotkeysPageTurn } from './hotkeys';
34+
import { addHotkeysActions } from './hotkeys';
3535
import { colorizeTag } from './colorizeTag';
3636
import { quickRating } from './quickRating';
3737
import { quickTagDefine } from './quickTagDefine';
@@ -47,8 +47,8 @@ import { expandTagList } from './expandTagList';
4747
const context = await createEhContext({
4848
/** 关联外站 */
4949
cross_site_link: true,
50-
/** 快捷键 */
51-
hotkeys: true,
50+
/** 增加快捷键操作 */
51+
add_hotkeys_actions: true,
5252
/** 识别广告页 */
5353
detect_ad: true,
5454
/** 快捷收藏 */
@@ -87,17 +87,18 @@ import { expandTagList } from './expandTagList';
8787
<>
8888
<For
8989
each={[
90+
'colorize_tag', // 标签染色
9091
'float_tag_list', // 悬浮标签列表
9192
'expand_tag_list', // 展开标签列表
9293
'tag_lint', // 标签检查
93-
'colorize_tag', // 标签染色
9494
'',
9595
'quick_favorite', // 快捷收藏
9696
'quick_rating', // 快捷评分
9797
'quick_tag_define', // 快捷查看标签定义
9898
'',
9999
'cross_site_link', // 关联外站
100100
'detect_ad', // 识别广告页
101+
'add_hotkeys_actions', // 增加快捷键操作
101102
'auto_adjust_option', // 自动调整配置
102103
]}
103104
>
@@ -181,7 +182,7 @@ import { expandTagList } from './expandTagList';
181182
requestIdleCallback(() => expandTagList(context), 1000);
182183

183184
// 不是漫画页就退出
184-
if (context.type !== 'gallery') return hotkeysPageTurn(context);
185+
if (context.type !== 'gallery') return addHotkeysActions(context);
185186

186187
// 自动调整阅读配置
187188
if (
@@ -374,7 +375,7 @@ import { expandTagList } from './expandTagList';
374375
}, sidebarDom);
375376

376377
// 等加载按钮渲染好后再绑定快捷键,防止在还没准备好时就触发加载导致出错
377-
if (options.hotkeys) hotkeysPageTurn(context);
378+
addHotkeysActions(context);
378379

379380
/** 获取新的图片页地址 */
380381
const getNewImgPageUrl = async (url: string) => {

src/userscript/main/migration.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,17 @@ export const migration = async (version: string) => {
172172
await renameOption(key, ['associate_nhentai => cross_site_link']);
173173
}
174174
}
175+
176+
if (versionLt(version, '11.13'))
177+
for (const key of values) {
178+
switch (key) {
179+
case 'Version':
180+
case 'Languages':
181+
case 'HotKeys':
182+
continue;
183+
184+
default:
185+
await renameOption(key, ['hotkeys => add_hotkeys_actions']);
186+
}
187+
}
175188
};

0 commit comments

Comments
 (0)