Skip to content

Commit

Permalink
fix: 🐛 修复出现多余功能按钮的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hymbz committed Jul 12, 2024
1 parent c9f4d8e commit 27a1ba4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/Manga/actions/operate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export const handleWheel = (e: WheelEvent) => {
) {
e.preventDefault();
if (store.option.scrollMode.fitToWidth) return;
return zoomScrollModeImg(isWheelDown ? -0.1 : 0.1);
return zoomScrollModeImg(isWheelDown ? -0.05 : 0.05);
}

if (e.ctrlKey || e.altKey || store.zoom.scale !== 100) {
Expand Down
22 changes: 20 additions & 2 deletions src/helper/useSiteOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ const getHotkeys = async (): Promise<Record<string, string[]>> => ({
...(await GM.getValue<Record<string, string[]>>('Hotkeys', {})),
});

/** 清理多余的配置项 */
const clear = <T extends Record<string, any> = {}>(
options: T,
defaultOptions: T,
) => {
let isClear = false;
for (const key of Object.keys(options)) {
if (Reflect.has(defaultOptions, key)) continue;
Reflect.deleteProperty(options, key);
isClear = true;
}
return isClear;
};

/**
* 对修改站点配置的相关方法的封装
* @param name 站点名
Expand All @@ -32,6 +46,8 @@ export const useSiteOptions = async <T = Record<string, any>>(
type SaveOptions = T & SiteOptions;

const _defaultOptions = {
option: undefined,
defaultOption: undefined,
autoShow: true,
hiddenFAB: false,
...defaultOptions,
Expand All @@ -43,8 +59,8 @@ export const useSiteOptions = async <T = Record<string, any>>(
assign(_defaultOptions, saveOptions),
);

const setOptions = async (newValue: Partial<SaveOptions>) => {
Object.assign(options, newValue);
const setOptions = async (newValue?: Partial<SaveOptions>) => {
if (newValue) Object.assign(options, newValue);
// 只保存和默认设置不同的部分
return GM.setValue(name, difference(options, _defaultOptions));
};
Expand All @@ -54,6 +70,8 @@ export const useSiteOptions = async <T = Record<string, any>>(
const isStored = saveOptions !== undefined;
// 如果当前站点没有存储配置,就补充上去
if (!isStored) await GM.setValue(name, {});
// 否则检查是否有多余的配置
else if (clear(options, _defaultOptions)) await setOptions();

return {
/** 站点配置 */
Expand Down

0 comments on commit 27a1ba4

Please sign in to comment.