mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 14:04:21 +01:00
feat: import/export config via clipboard
This commit is contained in:
@@ -636,6 +636,7 @@ const ConfigUI = (props: ConfigProps) => {
|
|||||||
const i18n = useTranslation();
|
const i18n = useTranslation();
|
||||||
const [menuIndex, setMenuIndex] = createSignal<number | null>(null);
|
const [menuIndex, setMenuIndex] = createSignal<number | null>(null);
|
||||||
const { canImport, importConfig } = useOldConfig();
|
const { canImport, importConfig } = useOldConfig();
|
||||||
|
const { config, setConfig } = useConfig();
|
||||||
|
|
||||||
const menu = [
|
const menu = [
|
||||||
{
|
{
|
||||||
@@ -692,19 +693,54 @@ const ConfigUI = (props: ConfigProps) => {
|
|||||||
fallback={
|
fallback={
|
||||||
<>
|
<>
|
||||||
<h2 class="flex-1 text-center text-lg font-bold">{i18n()('config.config')}</h2>
|
<h2 class="flex-1 text-center text-lg font-bold">{i18n()('config.config')}</h2>
|
||||||
<Show when={canImport()}>
|
<div class="flex gap-1">
|
||||||
<button
|
<Show when={canImport() && window.location.host === 'syusui-s.github.io'}>
|
||||||
type="button"
|
<button
|
||||||
class="rounded bg-primary p-2 text-primary-fg"
|
type="button"
|
||||||
onClick={() => {
|
class="rounded bg-primary p-2 text-primary-fg"
|
||||||
if (window.confirm(i18n()('config.confirmImportOldDomainConfig'))) {
|
onClick={() => {
|
||||||
importConfig();
|
if (window.confirm(i18n()('config.confirmImportOldDomainConfig'))) {
|
||||||
}
|
importConfig();
|
||||||
}}
|
}
|
||||||
>
|
}}
|
||||||
{i18n()('config.importOldDomainConfig')}
|
>
|
||||||
</button>
|
{i18n()('config.importOldDomainConfig')}
|
||||||
</Show>
|
</button>
|
||||||
|
</Show>
|
||||||
|
<Show when={window.location.host === 'syusui-s.github.io'}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded bg-primary p-2 text-primary-fg"
|
||||||
|
onClick={() => {
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(JSON.stringify(config(), null, 2))
|
||||||
|
.then(() => window.alert('OK'))
|
||||||
|
.catch(() => window.alert('failed to copy'));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{i18n()('config.copyToClipboard')}
|
||||||
|
</button>
|
||||||
|
</Show>
|
||||||
|
<Show when={window.location.host === 'rabbit.syusui.net'}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded bg-primary p-2 text-primary-fg"
|
||||||
|
onClick={() => {
|
||||||
|
const text = window.prompt('Paste config') ?? '';
|
||||||
|
if (text.length === 0) {
|
||||||
|
window.alert('empty');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const json = JSON.parse(text) as ReturnType<typeof config>;
|
||||||
|
if (window.confirm(`import?:\n${text}`)) {
|
||||||
|
setConfig(json);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{i18n()('config.importFromClipboard')}
|
||||||
|
</button>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
<ul class="flex flex-col">
|
<ul class="flex flex-col">
|
||||||
<For each={menu}>
|
<For each={menu}>
|
||||||
{(menuItem, i) => (
|
{(menuItem, i) => (
|
||||||
|
|||||||
@@ -126,7 +126,9 @@ export default {
|
|||||||
config: {
|
config: {
|
||||||
config: 'Settings',
|
config: 'Settings',
|
||||||
importOldDomainConfig: 'Import config from the old domain',
|
importOldDomainConfig: 'Import config from the old domain',
|
||||||
confirmImportOldDomainConfig: 'Import? (The config will be overwritten)',
|
confirmImport: 'Import? (The config will be overwritten)',
|
||||||
|
copyToClipboard: 'Copy to clipboard',
|
||||||
|
importFromClipboard: 'Import from clipboard',
|
||||||
profile: {
|
profile: {
|
||||||
profile: 'Profile',
|
profile: 'Profile',
|
||||||
openProfile: 'Open',
|
openProfile: 'Open',
|
||||||
|
|||||||
@@ -122,7 +122,9 @@ export default {
|
|||||||
config: {
|
config: {
|
||||||
config: '設定',
|
config: '設定',
|
||||||
importOldDomainConfig: '古いドメインから設定をインポート',
|
importOldDomainConfig: '古いドメインから設定をインポート',
|
||||||
confirmImportOldDomainConfig: 'インポートしますか?(現在の設定は上書きされます)',
|
confirmImport: 'インポートしますか?(現在の設定は上書きされます)',
|
||||||
|
copyToClipboard: 'クリップボードに設定をコピー',
|
||||||
|
importFromClipboard: '設定をクリップボードから読み込む',
|
||||||
profile: {
|
profile: {
|
||||||
profile: 'プロフィール',
|
profile: 'プロフィール',
|
||||||
openProfile: '開く',
|
openProfile: '開く',
|
||||||
|
|||||||
Reference in New Issue
Block a user