mirror of https://github.com/msgbyte/tailchat
feat: 增加字体放大插件
parent
109130780a
commit
caf5a45fe1
@ -1,3 +1,4 @@
|
|||||||
const PLUGIN_NAME = '{{id}}';
|
const PLUGIN_ID = '{{id}}';
|
||||||
|
const PLUGIN_NAME = '{{name}}';
|
||||||
|
|
||||||
console.log(`Plugin ${PLUGIN_NAME} is loaded`);
|
console.log(`Plugin ${PLUGIN_NAME}(${PLUGIN_ID}) is loaded`);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
const PLUGIN_NAME = '{{id}}';
|
const PLUGIN_ID = '{{id}}';
|
||||||
|
const PLUGIN_NAME = '{{name}}';
|
||||||
|
|
||||||
console.log(`Plugin ${PLUGIN_NAME} is loaded`);
|
console.log(`Plugin ${PLUGIN_NAME}(${PLUGIN_ID}) is loaded`);
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"label": "字号放大",
|
||||||
|
"name": "com.msgbyte.biggerfont",
|
||||||
|
"url": "/plugins/com.msgbyte.biggerfont/index.js",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"author": "moonrailgun",
|
||||||
|
"description": "为Tailchat增加放大字号的功能,方便不同用户群体",
|
||||||
|
"requireRestart": true
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "@plugins/com.msgbyte.biggerfont",
|
||||||
|
"main": "src/index.tsx",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "为Tailchat增加放大字号的功能,方便不同用户群体",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"sync:declaration": "tailchat declaration github"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"lodash": "^4.17.21"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/lodash": "^4.14.191",
|
||||||
|
"@types/styled-components": "^5.1.26",
|
||||||
|
"react": "18.2.0",
|
||||||
|
"styled-components": "^5.3.6"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
export const PLUGIN_ID = 'com.msgbyte.biggerfont';
|
||||||
|
|
||||||
|
export const PLUGIN_CONFIG = `${PLUGIN_ID}.config`;
|
@ -0,0 +1,49 @@
|
|||||||
|
import {
|
||||||
|
regPluginSettings,
|
||||||
|
getCachedUserSettings,
|
||||||
|
sharedEvent,
|
||||||
|
} from '@capital/common';
|
||||||
|
import { PLUGIN_CONFIG, PLUGIN_ID } from './const';
|
||||||
|
import { Translate } from './translate';
|
||||||
|
import _get from 'lodash/get';
|
||||||
|
|
||||||
|
console.log(`Plugin ${PLUGIN_ID} is loaded`);
|
||||||
|
|
||||||
|
regPluginSettings({
|
||||||
|
name: PLUGIN_CONFIG,
|
||||||
|
label: Translate.name,
|
||||||
|
position: 'system',
|
||||||
|
type: 'select',
|
||||||
|
defaultValue: '',
|
||||||
|
options: [
|
||||||
|
{ label: Translate.default, value: '' },
|
||||||
|
{ label: Translate.md, value: 'md' },
|
||||||
|
{ label: Translate.lg, value: 'lg' },
|
||||||
|
{ label: Translate.xl, value: 'xl' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
getCachedUserSettings().then((settings) => {
|
||||||
|
updateFontsize(settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
sharedEvent.on('userSettingsUpdate', (settings) => {
|
||||||
|
updateFontsize(settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateFontsize(settings: any) {
|
||||||
|
const fontSize = _get(settings, PLUGIN_CONFIG);
|
||||||
|
|
||||||
|
if (typeof settings === 'object' && typeof fontSize === 'string') {
|
||||||
|
if (fontSize === '') {
|
||||||
|
// 清除字号设置
|
||||||
|
document.documentElement.style.fontSize = undefined;
|
||||||
|
} else if (fontSize === 'md') {
|
||||||
|
document.documentElement.style.fontSize = '18px';
|
||||||
|
} else if (fontSize === 'lg') {
|
||||||
|
document.documentElement.style.fontSize = '20px';
|
||||||
|
} else if (fontSize === 'xl') {
|
||||||
|
document.documentElement.style.fontSize = '22px';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
import { localTrans } from '@capital/common';
|
||||||
|
|
||||||
|
export const Translate = {
|
||||||
|
name: localTrans({
|
||||||
|
'zh-CN': '放大字号',
|
||||||
|
'en-US': 'Increase font size',
|
||||||
|
}),
|
||||||
|
default: localTrans({ 'zh-CN': '默认', 'en-US': 'Default' }),
|
||||||
|
md: localTrans({ 'zh-CN': '中号', 'en-US': 'Middle' }),
|
||||||
|
lg: localTrans({
|
||||||
|
'zh-CN': '大号',
|
||||||
|
'en-US': 'Large',
|
||||||
|
}),
|
||||||
|
xl: localTrans({
|
||||||
|
'zh-CN': '特大号',
|
||||||
|
'en-US': 'Extra Large',
|
||||||
|
}),
|
||||||
|
};
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"jsx": "react",
|
||||||
|
"importsNotUsedAsValues": "error"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
declare module '@capital/common';
|
||||||
|
declare module '@capital/component';
|
Loading…
Reference in New Issue