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 [menuIndex, setMenuIndex] = createSignal<number | null>(null);
|
||||
const { canImport, importConfig } = useOldConfig();
|
||||
const { config, setConfig } = useConfig();
|
||||
|
||||
const menu = [
|
||||
{
|
||||
@@ -692,7 +693,8 @@ const ConfigUI = (props: ConfigProps) => {
|
||||
fallback={
|
||||
<>
|
||||
<h2 class="flex-1 text-center text-lg font-bold">{i18n()('config.config')}</h2>
|
||||
<Show when={canImport()}>
|
||||
<div class="flex gap-1">
|
||||
<Show when={canImport() && window.location.host === 'syusui-s.github.io'}>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded bg-primary p-2 text-primary-fg"
|
||||
@@ -705,6 +707,40 @@ const ConfigUI = (props: ConfigProps) => {
|
||||
{i18n()('config.importOldDomainConfig')}
|
||||
</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">
|
||||
<For each={menu}>
|
||||
{(menuItem, i) => (
|
||||
|
||||
@@ -126,7 +126,9 @@ export default {
|
||||
config: {
|
||||
config: 'Settings',
|
||||
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',
|
||||
openProfile: 'Open',
|
||||
|
||||
@@ -122,7 +122,9 @@ export default {
|
||||
config: {
|
||||
config: '設定',
|
||||
importOldDomainConfig: '古いドメインから設定をインポート',
|
||||
confirmImportOldDomainConfig: 'インポートしますか?(現在の設定は上書きされます)',
|
||||
confirmImport: 'インポートしますか?(現在の設定は上書きされます)',
|
||||
copyToClipboard: 'クリップボードに設定をコピー',
|
||||
importFromClipboard: '設定をクリップボードから読み込む',
|
||||
profile: {
|
||||
profile: 'プロフィール',
|
||||
openProfile: '開く',
|
||||
|
||||
Reference in New Issue
Block a user