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

Merged
merged 8 commits into from
Dec 27, 2024
Merged
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 @@ -4215,6 +4215,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 @@ -1045,6 +1045,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
6 changes: 6 additions & 0 deletions packages/frontend/src/pages/settings/general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitch v-model="disableNyaize">{{ i18n.ts.noNyaization }} <span class="_beta">CherryPick</span></MkSwitch>
<MkSwitch v-model="checkMultipleRenote">{{ i18n.ts.showMultipleRenoteWarning }} <span class="_beta">yojo-art</span></MkSwitch>
</div>
<MkInput v-model="searchEngine" manualSave :spellcheck="false">
<template #label>{{ i18n.ts.search }}<span class="_beta" style="vertical-align: middle;">yojo-art</span></template>
<template #caption>{{ i18n.ts.searchEngineDescription }}</template>
</MkInput>
<MkSelect v-model="serverDisconnectedBehavior">
<template #label>{{ i18n.ts.whenServerDisconnected }} <span class="_beta" style="vertical-align: middle;">CherryPick</span></template>
<option value="reload">{{ i18n.ts._serverDisconnectedBehavior.reload }}</option>
Expand Down Expand Up @@ -161,6 +165,7 @@ import FormSection from '@/components/form/section.vue';
import FormLink from '@/components/form/link.vue';
import MkLink from '@/components/MkLink.vue';
import MkInfo from '@/components/MkInfo.vue';
import MkInput from '@/components/MkInput.vue';
import { defaultStore } from '@/store.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
Expand Down Expand Up @@ -201,6 +206,7 @@ const useAutoTranslate = computed(defaultStore.makeGetterSetter('useAutoTranslat
const welcomeBackToast = computed(defaultStore.makeGetterSetter('welcomeBackToast'));
const disableNyaize = computed(defaultStore.makeGetterSetter('disableNyaize'));
const checkMultipleRenote = computed(defaultStore.makeGetterSetter('checkMultipleRenote'));
const searchEngine = computed(defaultStore.makeGetterSetter('searchEngine'));

watch(lang, () => {
miLocalStorage.setItem('lang', lang.value as string);
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/pages/settings/preferences-backups.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ const defaultStoreSaveKeys: (keyof typeof defaultStore['state'])[] = [
'showMoreButtonInNoteFooter',
'selectReaction',
// #endregion CherryPick
// #region yojo-art
'checkMultipleRenote',
'searchEngine',
// #endregion yojo-art
];
const coldDeviceStorageSaveKeys: (keyof typeof ColdDeviceStorage.default)[] = [
'lightTheme',
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: 'https://www.google.com/search?q=%s',
},

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