Skip to content

Commit 5b3dc58

Browse files
committed
feat: ✨ 将 ehentai 部分增强功能的开关,从网页悬浮按钮移至阅读模式的设置里
1 parent af3a2d2 commit 5b3dc58

10 files changed

Lines changed: 140 additions & 46 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ Cotrans 也有自己的油猴脚本 —— 「[Cotrans 漫画/图片翻译器](h
250250
>
251251
> 如果需要经常下载和翻译的话,建议再开启「[图像识别](#图像识别)」功能,在加载阶段直接下载好图片文件,避免之后因图片链接过期而出错。
252252
253+
> 因为站点增强功能过多,为了避免屏幕放不下,部分功能的开关不显示在悬浮按钮上,而是放到了进入阅读模式后的设置面板里。
254+
253255
### 加载指定页码
254256

255257
在按住 `Shift` 的情况下点击侧边栏的「Load comic」按钮将会弹出一个输入框,可以通过输入 `1, 3-5, 9-` 格式的页码范围来只加载对应页码的图片。

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ Cotrans 也有自己的油猴脚本 —— 「[Cotrans 漫画/图片翻译器](h
250250
>
251251
> 如果需要经常下载和翻译的话,建议再开启「[图像识别](#图像识别)」功能,在加载阶段直接下载好图片文件,避免之后因图片链接过期而出错。
252252
253+
> 因为站点增强功能过多,为了避免屏幕放不下,部分功能的开关不显示在悬浮按钮上,而是放到了进入阅读模式后的设置面板里。
254+
253255
### 加载指定页码
254256

255257
在按住 `Shift` 的情况下点击侧边栏的「Load comic」按钮将会弹出一个输入框,可以通过输入 `1, 3-5, 9-` 格式的页码范围来只加载对应页码的图片。

src/components/Manga/components/Setting.module.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@
3232
rgb(0 0 0 / 12%) 0 1px 5px 0;
3333

3434
& hr {
35-
margin: 0;
35+
margin: 0.5em 0;
3636
color: white;
3737
}
38+
39+
& > hr {
40+
margin: 0;
41+
}
3842
}
3943

4044
.SettingBlock {
@@ -87,6 +91,12 @@
8791
background-color: var(--page-bg);
8892
}
8993

94+
.SettingBlockBody .SettingBlockSubtitle {
95+
position: unset;
96+
height: 1em;
97+
line-height: 1em;
98+
}
99+
90100
.SettingsItem {
91101
display: flex;
92102
align-items: center;

src/components/Manga/components/SettingHotkeys.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const KeyItem: Component<{
8989
);
9090
};
9191

92-
const ShowHotkeys: Component<{ keys: string[] }> = (props) => (
92+
export const SettingHotkeys: Component<{ keys: string[] }> = (props) => (
9393
<For each={props.keys}>
9494
{(name) => (
9595
<div class={classes.hotkeys}>
@@ -150,7 +150,7 @@ const OtherHotkeys: Component<{ keys: string[] }> = (props) => {
150150
);
151151
};
152152

153-
export const SettingHotkeys: Component = () => {
153+
export const SettingHotkeysBlock: Component = () => {
154154
const hotkeys = createRootMemo(() => {
155155
const show: string[] = [];
156156
const other: string[] = [];
@@ -161,7 +161,7 @@ export const SettingHotkeys: Component = () => {
161161

162162
return (
163163
<>
164-
<ShowHotkeys keys={hotkeys().show} />
164+
<SettingHotkeys keys={hotkeys().show} />
165165
<Show when={hotkeys().other.length}>
166166
<OtherHotkeys keys={hotkeys().other} />
167167
</Show>

src/components/Manga/components/SettingPanel.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { type Component, For, createSignal } from 'solid-js';
1+
import {
2+
type Component,
3+
type ParentComponent,
4+
For,
5+
createSignal,
6+
} from 'solid-js';
27
import { lang, createEffectOn } from 'helper';
38

49
import { defaultSettingList } from '../defaultSettingList';
@@ -7,6 +12,16 @@ import { stopPropagation } from '../helper';
712
import { bindRef } from '../actions';
813
import classes from '../index.module.css';
914

15+
export const SettingBlockSubtitle: ParentComponent<{
16+
onClick?: () => void;
17+
}> = (props) => (
18+
<div
19+
class={classes.SettingBlockSubtitle}
20+
on:click={props.onClick}
21+
children={props.children}
22+
/>
23+
);
24+
1025
/** 菜单面板 */
1126
export const SettingPanel: Component = () => (
1227
<div
@@ -31,13 +46,10 @@ export const SettingPanel: Component = () => (
3146
<>
3247
{i() ? <hr /> : null}
3348
<div class={classes.SettingBlock} data-show={show()}>
34-
<div
35-
class={classes.SettingBlockSubtitle}
36-
on:click={() => setShwo((prev) => !prev)}
37-
>
49+
<SettingBlockSubtitle onClick={() => setShwo((prev) => !prev)}>
3850
{name}
39-
{show() ? null : ' …'}
40-
</div>
51+
{show() ? null : '…'}
52+
</SettingBlockSubtitle>
4153
<div class={classes.SettingBlockBody}>
4254
<SettingItem />
4355
</div>

src/components/Manga/defaultSettingList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { lang, setLang, t, clamp, throttle, needDarkMode } from 'helper';
55

66
import { SettingsItem } from './components/SettingsItem';
77
import { SettingsItemSwitch } from './components/SettingsItemSwitch';
8-
import { SettingHotkeys } from './components/SettingHotkeys';
8+
import { SettingHotkeysBlock } from './components/SettingHotkeys';
99
import { SettingTranslation } from './components/SettingTranslation';
1010
import { SettingsShowItem } from './components/SettingsShowItem';
1111
import { SettingsItemSelect } from './components/SettingsItemSelect';
@@ -388,7 +388,7 @@ export const defaultSettingList: () => SettingList = () => [
388388
SettingTranslation,
389389
() => store.option.translation.server !== 'disable',
390390
],
391-
[t('other.hotkeys'), SettingHotkeys],
391+
[t('other.hotkeys'), SettingHotkeysBlock],
392392
[
393393
t('other.other'),
394394
() => (

src/components/Manga/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ export const Manga: Component<MangaProps> = (props) => {
9595
);
9696
};
9797

98-
export { store, setState, _setState, refs } from './store/index';
99-
export { downloadImg } from './helper';
10098
export * from './actions';
99+
export { downloadImg } from './helper';
100+
export { store, setState, _setState, refs } from './store/index';
101+
export { SettingsItem } from './components/SettingsItem';
102+
export { SettingsItemSwitch } from './components/SettingsItemSwitch';
103+
export { SettingsItemNumber } from './components/SettingsItemNumber';
104+
export { SettingHotkeys } from './components/SettingHotkeys';
105+
export { SettingBlockSubtitle } from './components/SettingPanel';

src/site/ehentai/index.tsx

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { createSignal } from 'solid-js';
1+
import { createSignal, type Component, For, Show } from 'solid-js';
22
import { render } from 'solid-js/web';
3-
import { request, toast, type LoadImgFn } from 'main';
4-
import { type MangaProps, imgList as MangaImgList } from 'components/Manga';
3+
import { request, toast, useSpeedDial, type LoadImgFn } from 'main';
4+
import {
5+
type MangaProps,
6+
imgList as MangaImgList,
7+
SettingsItemSwitch,
8+
SettingHotkeys,
9+
SettingBlockSubtitle,
10+
} from 'components/Manga';
511
import {
612
t,
713
querySelector,
@@ -74,8 +80,56 @@ import { expandTagList } from './expandTagList';
7480
setImgList,
7581
setFab,
7682
setManga,
83+
setOptions,
7784
} = context;
7885

86+
const SiteSettings: Component = () => (
87+
<>
88+
<For
89+
each={[
90+
'float_tag_list', // 悬浮标签列表
91+
'expand_tag_list', // 展开标签列表
92+
'tag_lint', // 标签检查
93+
'colorize_tag', // 标签染色
94+
'',
95+
'quick_favorite', // 快捷收藏
96+
'quick_rating', // 快捷评分
97+
'quick_tag_define', // 快捷查看标签定义
98+
'',
99+
'cross_site_link', // 关联外站
100+
'detect_ad', // 识别广告页
101+
'auto_adjust_option', // 自动调整配置
102+
]}
103+
>
104+
{(name) => (
105+
<Show when={name} fallback={<hr />}>
106+
<SettingsItemSwitch
107+
name={t(`site.add_feature.${name}`)}
108+
value={options[name]}
109+
onChange={(v) => setOptions({ [name]: v })}
110+
/>
111+
</Show>
112+
)}
113+
</For>
114+
<hr />
115+
<SettingBlockSubtitle>{t('other.hotkeys')}</SettingBlockSubtitle>
116+
<SettingHotkeys keys={['float_tag_list']} />
117+
</>
118+
);
119+
setManga({
120+
editSettingList: (list) => [...list, ['E-Hentai', SiteSettings]],
121+
});
122+
setFab({
123+
speedDial: [
124+
...useSpeedDial(options, setOptions, context.placement, [
125+
'tag_lint',
126+
'colorize_tag',
127+
'cross_site_link',
128+
'detect_ad',
129+
]),
130+
],
131+
});
132+
79133
if (context.type === 'mpv') {
80134
return setComicLoad(() => {
81135
const imgEleList = querySelectorAll('.mimg[id]');

src/userscript/main/useInit.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export const useInit = async <T extends Record<string, any>>(
242242
fabProps,
243243
needAutoShow,
244244
isStored,
245+
placement,
245246

246247
comicMap,
247248
setComicMap,

src/userscript/main/useSpeedDial.tsx

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const useSpeedDial = <
1717
options: SaveOptions,
1818
setOptions: (newOptions: Partial<SaveOptions>) => Promise<void>,
1919
placement: () => 'left' | 'right',
20+
showOtherList?: string[],
2021
) => {
2122
const DefaultButton: Component<{
2223
optionName: keyof SaveOptions & string;
@@ -44,36 +45,43 @@ export const useSpeedDial = <
4445
/>
4546
);
4647

47-
const list = Object.keys(options)
48-
.map((optionName) => {
49-
switch (optionName) {
50-
case 'hiddenFAB':
51-
case 'option':
52-
return null;
48+
const list: Component[] = [];
5349

54-
case 'autoShow':
55-
return () => (
56-
<DefaultButton
57-
optionName="autoShow"
58-
showName={t('site.add_feature.auto_show')}
59-
children={options.autoShow ? <MdFlashOn /> : <MdFlashOff />}
60-
/>
61-
);
62-
case 'lockOption':
63-
return () => (
64-
<DefaultButton
65-
optionName="lockOption"
66-
showName={t('site.add_feature.lock_option')}
67-
children={options.lockOption ? <MdLock /> : <MdLockOpen />}
68-
/>
69-
);
50+
for (const optionName of Object.keys(options)) {
51+
switch (optionName) {
52+
case 'hiddenFAB':
53+
case 'option':
54+
continue;
7055

71-
default:
72-
if (typeof options[optionName] !== 'boolean') return null;
73-
return () => <DefaultButton optionName={optionName} />;
74-
}
75-
})
76-
.filter(Boolean) as Component[];
56+
case 'autoShow':
57+
list.push(() => (
58+
<DefaultButton
59+
optionName="autoShow"
60+
showName={t('site.add_feature.auto_show')}
61+
children={options.autoShow ? <MdFlashOn /> : <MdFlashOff />}
62+
/>
63+
));
64+
break;
65+
66+
case 'lockOption':
67+
list.push(() => (
68+
<DefaultButton
69+
optionName="lockOption"
70+
showName={t('site.add_feature.lock_option')}
71+
children={options.lockOption ? <MdLock /> : <MdLockOpen />}
72+
/>
73+
));
74+
break;
75+
76+
default:
77+
if (!showOtherList && typeof options[optionName] === 'boolean')
78+
list.push(() => <DefaultButton optionName={optionName} />);
79+
}
80+
}
81+
82+
if (showOtherList)
83+
for (const optionName of showOtherList)
84+
list.push(() => <DefaultButton optionName={optionName} />);
7785

7886
return list;
7987
};

0 commit comments

Comments
 (0)