Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MFMの検索エンジンをユーザー設定で変える #575

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4211,6 +4211,10 @@ export interface Locale extends ILocale {
* CWを維持する
*/
"keepCw": string;
/**
* %sが検索語句に置き換えられます
*/
"searchEngineDescription": string;
/**
* Pub/Subのアカウント
*/
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ usernameInfo: "サーバー上であなたのアカウントを一意に識別
aiChanMode: "藍モード"
devMode: "開発者モード"
keepCw: "CWを維持する"
searchEngineDescription: "%sが検索語句に置き換えられます"
pubSub: "Pub/Subのアカウント"
lastCommunication: "直近の通信"
resolved: "解決済み"
Expand Down
15 changes: 12 additions & 3 deletions packages/frontend/src/components/MkGoogle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { ref } from 'vue';
import { url as local } from '@@/js/config.js';
import { i18n } from '@/i18n.js';
import { defaultStore } from '@/store.js';
import { useRouter } from '@/router/supplier.js';

const router = useRouter();

const props = defineProps<{
q: string;
Expand All @@ -21,9 +26,13 @@ const props = defineProps<{
const query = ref(props.q);

const search = () => {
const sp = new URLSearchParams();
sp.append('q', query.value);
window.open(`https://www.google.com/search?${sp.toString()}`, '_blank', 'noopener');
const searchUrl = String(defaultStore.state.searchEngine).replaceAll('%s', encodeURIComponent(query.value));
const url = new URL(searchUrl, local);
if (url.origin === local) {
router.push(url.toString().substring(local.length));
} else {
window.open(searchUrl, '_blank', 'noopener');
}
};
</script>

Expand Down
7 changes: 7 additions & 0 deletions packages/frontend/src/pages/settings/privacy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ SPDX-License-Identifier: AGPL-3.0-only
</FormSection>

<MkSwitch v-model="keepCw" @update:modelValue="save()">{{ i18n.ts.keepCw }}</MkSwitch>

<MkInput v-model="searchEngine" manualSave :spellcheck="false">
<template #label>{{ i18n.ts.search }}<span class="_beta">yojo-art</span></template>
<template #caption>{{ i18n.ts.searchEngineDescription }}</template>
</MkInput>
</div>
</template>

Expand All @@ -110,6 +115,7 @@ import MkSelect from '@/components/MkSelect.vue';
import FormSection from '@/components/form/section.vue';
import MkFolder from '@/components/MkFolder.vue';
import MkInfo from '@/components/MkInfo.vue';
import MkInput from '@/components/MkInput.vue';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { defaultStore } from '@/store.js';
import { i18n } from '@/i18n.js';
Expand All @@ -135,6 +141,7 @@ const defaultNoteSearchbility = computed(defaultStore.makeGetterSetter('defaultN
const rememberNoteSearchbility = computed(defaultStore.makeGetterSetter('rememberNoteSearchbility'));
const rememberNoteVisibility = computed(defaultStore.makeGetterSetter('rememberNoteVisibility'));
const keepCw = computed(defaultStore.makeGetterSetter('keepCw'));
const searchEngine = computed(defaultStore.makeGetterSetter('searchEngine'));

function save() {
console.log(typeof(searchableBy.value));
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export const defaultStore = markRaw(new Storage('base', {
where: 'account',
default: [] as string[],
},
searchEngine: {
where: 'account',
default: '/search?q=%s',
},

menu: {
where: 'deviceAccount',
Expand Down
Loading