Skip to content

Commit

Permalink
Merge pull request #27 from web-dahuyou/dev
Browse files Browse the repository at this point in the history
复制链接支持自定义模板
  • Loading branch information
web-dahuyou authored Aug 25, 2024
2 parents 8360b4f + 81d3a23 commit a3a46ae
Show file tree
Hide file tree
Showing 20 changed files with 378 additions and 206 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- 标签页支持自定义编辑修改标题和url。
- 添加固定置顶的特殊分类-**中转站**,发送标签页/标签组时自动收集到中转站中。
- 添加标签组按字母排序功能
- 支持一键复制标签组所有标签页的链接, 复制链接支持自定义模板


## 功能截图
Expand Down
5 changes: 3 additions & 2 deletions entrypoints/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
magenta,
gold,
} from '@ant-design/colors';
import type { LanguageTypes, SettingsProps, TabEvents, SyncType } from '~/entrypoints/types';
import type { LanguageTypes, EnumSettingsProps, TabEvents, SyncType } from '~/entrypoints/types';

export const GITHUB_URL = 'https://github.com/web-dahuyou/NiceTab';

Expand Down Expand Up @@ -43,7 +43,7 @@ export const ENUM_ACTION_NAME = {
OPEN_ADMIN_TAB: 'action:openAdminTab', // 打开管理后台
};
// 设置项枚举
export const ENUM_SETTINGS_PROPS: Record<string, keyof SettingsProps> = {
export const ENUM_SETTINGS_PROPS: EnumSettingsProps = {
LANGUAGE: 'language', // 语言
OPEN_ADMIN_TAB_AFTER_BROWSER_LAUNCH: 'openAdminTabAfterBrowserLaunch', // 启动浏览器时是否自动打开管理后台
OPEN_ADMIN_TAB_AFTER_SEND_TABS: 'openAdminTabAfterSendTabs', // 发送标签页后是否打开管理后台
Expand All @@ -54,6 +54,7 @@ export const ENUM_SETTINGS_PROPS: Record<string, keyof SettingsProps> = {
DELETE_UNLOCKED_EMPTY_GROUP: 'deleteUnlockedEmptyGroup', // 是否删除未锁定的空标签组
ALLOW_DUPLICATE_TABS: 'allowDuplicateTabs', // 同一个标签组中是否允许重复的标签页
ALLOW_DUPLICATE_GROUPS: 'allowDuplicateGroups', // 同一个分类中是否允许重复的标签组
LINK_TEMPLATE: 'linkTemplate', // 链接模板
};

// tab 事件
Expand Down
4 changes: 2 additions & 2 deletions entrypoints/common/contextMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const { LANGUAGE, ALLOW_SEND_PINNED_TABS } = ENUM_SETTINGS_PROPS;

const getMenus = async (): Promise<Menus.CreateCreatePropertiesType[]> => {
const settings = await settingsUtils.getSettings();
const language = settings[LANGUAGE] as LanguageTypes || defaultLanguage;
const language = settings[LANGUAGE] || defaultLanguage;
const customMessages = getCustomLocaleMessages(language);

return [
{ id: ENUM_ACTION_NAME.OPEN_ADMIN_TAB, title: customMessages['common.openAdminPage'], contexts: ['all'] },
{ id: ENUM_ACTION_NAME.SEND_ALL_TABS, title: customMessages['common.sendAllTabs'], contexts: ['all'] },
{ id: ENUM_ACTION_NAME.SEND_CURRENT_TAB, title: customMessages['common.sendCurrentTab'], contexts: ['all'] },
{ id: ENUM_ACTION_NAME.OPEN_ADMIN_TAB, title: customMessages['common.openAdminPage'], contexts: ['all'] },
{ id: ENUM_ACTION_NAME.SEND_OTHER_TABS, title: customMessages['common.sendOtherTabs'], contexts: ['all'] },
{ id: ENUM_ACTION_NAME.SEND_LEFT_TABS, title: customMessages['common.sendLeftTabs'], contexts: ['all'] },
{ id: ENUM_ACTION_NAME.SEND_RIGHT_TABS, title: customMessages['common.sendRightTabs'], contexts: ['all'] },
Expand Down
3 changes: 3 additions & 0 deletions entrypoints/common/locale/modules/common/enUS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default {
'common.enableSelect': 'Enable Select',
'common.disableSelect': 'Disable Select',
'common.name': 'Name',
'common.title': 'Title',
'common.url': 'URL',
'common.link': 'Link',
'common.goToGithub': 'Give me a star',
'common.update.available': 'New version available',
'common.update.upgradeNow': 'Upgrade right now',
Expand All @@ -55,4 +57,5 @@ export default {
'common.comingSoon': 'Coming Soon',
'common.CopySuccess': 'Copy Success',
'common.CopyFailed': 'Copy Failed',
'common.quickAction': 'Quick Action',
}
3 changes: 3 additions & 0 deletions entrypoints/common/locale/modules/common/zhCN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default {
'common.enableSelect': '开启选择',
'common.disableSelect': '关闭选择',
'common.name': '名称',
'common.title': '标题',
'common.url': '网址',
'common.link': '链接',
'common.goToGithub': '给个小星星吧',
'common.update.available': '有可用的新版本',
'common.update.upgradeNow': '立即升级',
Expand All @@ -55,4 +57,5 @@ export default {
'common.comingSoon': '敬请期待',
'common.CopySuccess': '复制成功',
'common.CopyFailed': '复制失败',
'common.quickAction': '快捷操作',
}
4 changes: 4 additions & 0 deletions entrypoints/common/locale/modules/settings/enUS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ export default {
'settings.allowDuplicateGroups': 'When sending tabs - retain duplicate groups ?',
'settings.allowDuplicateGroups.yes': 'Retain',
'settings.allowDuplicateGroups.no': 'Merge duplicate groups (sending groups merge to Staging Area groups)',
'settings.linkTemplate': 'Copy Links Format Template',
'settings.linkTemplate.placeholder': 'Default format',
'settings.linkTemplate.tooltip': 'Format for copy links, using the Mustache format',

}
3 changes: 3 additions & 0 deletions entrypoints/common/locale/modules/settings/zhCN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ export default {
'settings.allowDuplicateGroups': '发送标签页时-是否保留重复的标签组{mark}',
'settings.allowDuplicateGroups.yes': '保留',
'settings.allowDuplicateGroups.no': '去重(发送的标签组和中转站的标签组合并)',
'settings.linkTemplate': '复制链接模板格式',
'settings.linkTemplate.placeholder': '默认格式为',
'settings.linkTemplate.tooltip': '复制链接所用的模板格式, 采用 Mustache 格式',
}
2 changes: 2 additions & 0 deletions entrypoints/common/storage/settingsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
DELETE_UNLOCKED_EMPTY_GROUP,
ALLOW_DUPLICATE_TABS,
ALLOW_DUPLICATE_GROUPS,
LINK_TEMPLATE,
} = ENUM_SETTINGS_PROPS;

// 设置工具类
Expand All @@ -28,6 +29,7 @@ export default class SettingsUtils {
[DELETE_UNLOCKED_EMPTY_GROUP]: true, // 是否删除未锁定的空标签组
[ALLOW_DUPLICATE_TABS]: true, // 同一个标签组中是否允许重复的标签页
[ALLOW_DUPLICATE_GROUPS]: true, // 同一个分类中是否允许重复的标签组
[LINK_TEMPLATE]: '{{url}} | {{title}}', // 复制的链接模板
};
settings: SettingsProps = this.initialSettings;

Expand Down
22 changes: 19 additions & 3 deletions entrypoints/common/storage/tabListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ import {
} from '../utils';
import Store from './instanceStore';

const { DELETE_UNLOCKED_EMPTY_GROUP, ALLOW_DUPLICATE_TABS, ALLOW_DUPLICATE_GROUPS } =
ENUM_SETTINGS_PROPS;
const {
DELETE_UNLOCKED_EMPTY_GROUP,
ALLOW_DUPLICATE_TABS,
ALLOW_DUPLICATE_GROUPS,
LINK_TEMPLATE,
} = ENUM_SETTINGS_PROPS;

/**
* @description: 列表去重(新列表从队首插入)
Expand Down Expand Up @@ -615,7 +619,7 @@ export default class TabListUtils {
targetList: targetTag.groupList || [],
insertList: allSourceGroups,
exceptValue: UNNAMED_GROUP,
})
});

await this.setTagList(tagList);
} else {
Expand Down Expand Up @@ -1128,4 +1132,16 @@ export default class TabListUtils {
});
return exportTagList;
}
// 复制链接
copyLinks(tabs: TabItem[]): string {
const settings = Store.settingsUtils?.settings;
const linkTemplate = settings[LINK_TEMPLATE] || '{{url}} | {{title}}';
return tabs
.map((tab) => {
return linkTemplate
.replace(/\{\{\s*title\s*\}\}/g, tab.title || '')
.replace(/\{\{\s*url\s*\}\}/g, tab.url || '');
})
.join('\n');
}
}
2 changes: 1 addition & 1 deletion entrypoints/common/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function openAdminTab(
params?: { tagId: string; groupId: string }
) {
const settings = settingsData || (await settingsUtils.getSettings());
const openAdminTabAfterSendTabs = settings[OPEN_ADMIN_TAB_AFTER_SEND_TABS] as boolean;
const openAdminTabAfterSendTabs = settings[OPEN_ADMIN_TAB_AFTER_SEND_TABS];
await openAdminRoutePage({ path: '/home', query: params }, openAdminTabAfterSendTabs);

if (!openAdminTabAfterSendTabs) {
Expand Down
3 changes: 1 addition & 2 deletions entrypoints/common/utils/locale.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getCustomLocaleMessages } from '~/entrypoints/common/locale';
import type { LanguageTypes } from '~/entrypoints/types';
import { settingsUtils } from '../storage';
import { ENUM_SETTINGS_PROPS, defaultLanguage } from '../constants';

Expand All @@ -8,7 +7,7 @@ const { LANGUAGE } = ENUM_SETTINGS_PROPS;
// 在react上下文之外获取locale信息
export function getLocaleMessages() {
const settings = settingsUtils.settings;
const language = (settings[LANGUAGE] as LanguageTypes) || defaultLanguage;
const language = settings[LANGUAGE] || defaultLanguage;
return getCustomLocaleMessages(language);
}

Expand Down
2 changes: 1 addition & 1 deletion entrypoints/options/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
import type { ColorItem } from '~/entrypoints/types';
import themeIcon from '/icon/theme.svg';
import Home from './home/index.tsx';
import Settings from './Settings.tsx';
import Settings from './settings/index.tsx';
import ImportExport from './importExport/index.tsx';
import SyncPage from './sync/index.tsx';
import RecycleBin from './recycleBin/index.tsx';
Expand Down
171 changes: 0 additions & 171 deletions entrypoints/options/Settings.tsx

This file was deleted.

Loading

0 comments on commit a3a46ae

Please sign in to comment.