Skip to content

Commit 24b3750

Browse files
authored
Merge pull request #554
* feat: custome search engine * fix import * Rollback elements
1 parent 23f47b9 commit 24b3750

File tree

6 files changed

+212
-2
lines changed

6 files changed

+212
-2
lines changed

locales/en-US.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,3 +3170,17 @@ _scheduledNoteDelete:
31703170
_getQRCode:
31713171
title: "Scan QR Code"
31723172
description: "Can scan or share the QR code below."
3173+
3174+
_searchSite:
3175+
title: "Search Engine"
3176+
description: "Change search engine that used in search MFM."
3177+
google: "Google"
3178+
bing: "Bing"
3179+
yahoo: "Yahoo"
3180+
baidu: "Baidu"
3181+
naver: "NAVER"
3182+
duckduckgo: "DuckDuckGo"
3183+
other: "Other"
3184+
otherDescription: "Use Other search engine"
3185+
query: "Query"
3186+
queryDescription: "Input query scheme for search engine. For example, If https://www.ecosia.org/search?q=test, input 'q'."

locales/index.d.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12115,6 +12115,65 @@ export interface Locale extends ILocale {
1211512115
*/
1211612116
"sent": string;
1211712117
};
12118+
"_remoteLookupErrors": {
12119+
"_federationNotAllowed": {
12120+
/**
12121+
* このサーバーとは通信できません
12122+
*/
12123+
"title": string;
12124+
/**
12125+
* このサーバーとの通信が無効化されているか、このサーバーをブロックしている・ブロックされている可能性があります。
12126+
* サーバー管理者にお問い合わせください。
12127+
*/
12128+
"description": string;
12129+
};
12130+
"_uriInvalid": {
12131+
/**
12132+
* URIが不正です
12133+
*/
12134+
"title": string;
12135+
/**
12136+
* 入力されたURIに問題があります。URIに使用できない文字を入力していないか確認してください。
12137+
*/
12138+
"description": string;
12139+
};
12140+
"_requestFailed": {
12141+
/**
12142+
* リクエストに失敗しました
12143+
*/
12144+
"title": string;
12145+
/**
12146+
* このサーバーとの通信に失敗しました。相手サーバーがダウンしている可能性があります。また、不正なURIや存在しないURIを入力していないか確認してください。
12147+
*/
12148+
"description": string;
12149+
};
12150+
"_responseInvalid": {
12151+
/**
12152+
* レスポンスが不正です
12153+
*/
12154+
"title": string;
12155+
/**
12156+
* このサーバーと通信することはできましたが、得られたデータが不正なものでした。
12157+
*/
12158+
"description": string;
12159+
};
12160+
"_responseInvalidIdHostNotMatch": {
12161+
/**
12162+
* 入力されたURIのドメインと最終的に得られたURIのドメインとが異なります。第三者のサーバーを介してリモートのコンテンツを照会している場合は、発信元のサーバーで取得できるURIを使用して照会し直してください。
12163+
*/
12164+
"description": string;
12165+
};
12166+
"_noSuchObject": {
12167+
/**
12168+
* 見つかりません
12169+
*/
12170+
"title": string;
12171+
/**
12172+
* 要求されたリソースは見つかりませんでした。URIをもう一度お確かめください。
12173+
*/
12174+
"description": string;
12175+
};
12176+
};
1211812177
"_abuse": {
1211912178
"_resolver": {
1212012179
/**
@@ -12303,6 +12362,60 @@ export interface Locale extends ILocale {
1230312362
*/
1230412363
"description": string;
1230512364
};
12365+
"_searchSite": {
12366+
/**
12367+
* 検索エンジン
12368+
*/
12369+
"title": string;
12370+
/**
12371+
* MFMの検索構文で検索できるサイトを変更します。
12372+
*/
12373+
"description": string;
12374+
/**
12375+
* Google
12376+
*/
12377+
"google": string;
12378+
/**
12379+
* Bing
12380+
*/
12381+
"bing": string;
12382+
/**
12383+
* Yahoo
12384+
*/
12385+
"yahoo": string;
12386+
/**
12387+
* Baidu
12388+
*/
12389+
"baidu": string;
12390+
/**
12391+
* NAVER
12392+
*/
12393+
"naver": string;
12394+
/**
12395+
* DuckDuckGo
12396+
*/
12397+
"duckduckgo": string;
12398+
/**
12399+
* その他
12400+
*/
12401+
"other": string;
12402+
/**
12403+
* その他の検索エンジン
12404+
*/
12405+
"otherSearchEngine": string;
12406+
/**
12407+
* その他の検索エンジンを使用します。
12408+
*/
12409+
"otherDescription": string;
12410+
/**
12411+
* 検索クエリ
12412+
*/
12413+
"query": string;
12414+
/**
12415+
* 検索エンジンが使用するクエリを入力します。(例: https://www.ecosia.org/search?q=test の場合qを入れる)
12416+
*/
12417+
"queryDescription": string;
12418+
};
1230612419
}
1230712420
declare const locales: {
1230812421
[lang: string]: Locale;

locales/ja-JP.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,3 +3297,18 @@ _scheduledNoteDelete:
32973297
_getQRCode:
32983298
title: "QRコードをスキャンする"
32993299
description: "以下のQRコードをスキャンまたは共有できます。"
3300+
3301+
_searchSite:
3302+
title: "検索エンジン"
3303+
description: "MFMの検索構文で検索できるサイトを変更します。"
3304+
google: "Google"
3305+
bing: "Bing"
3306+
yahoo: "Yahoo"
3307+
baidu: "Baidu"
3308+
naver: "NAVER"
3309+
duckduckgo: "DuckDuckGo"
3310+
other: "その他"
3311+
otherSearchEngine: "その他の検索エンジン"
3312+
otherDescription: "その他の検索エンジンを使用します。"
3313+
query: "検索クエリ"
3314+
queryDescription: "検索エンジンが使用するクエリを入力します。(例: https://www.ecosia.org/search?q=test の場合qを入れる)"

packages/frontend/src/components/MkGoogle.vue

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only
1313
<script lang="ts" setup>
1414
import { ref } from 'vue';
1515
import { i18n } from '@/i18n.js';
16+
import { defaultStore } from '@/store.js';
1617
1718
const props = defineProps<{
1819
q: string;
@@ -22,8 +23,40 @@ const query = ref(props.q);
2223
2324
const search = () => {
2425
const sp = new URLSearchParams();
25-
sp.append('q', query.value);
26-
window.open(`https://www.google.com/search?${sp.toString()}`, '_blank', 'noopener');
26+
let url = '';
27+
switch (defaultStore.state.searchEngine) {
28+
case 'google':
29+
sp.append('q', query.value);
30+
url = `https://www.google.com/search?${sp.toString()}`;
31+
break;
32+
case 'bing':
33+
sp.append('q', query.value);
34+
url = `https://www.bing.com/search?${sp.toString()}`;
35+
break;
36+
case 'yahoo':
37+
sp.append('p', query.value);
38+
url = `https://search.yahoo.com/search?${sp.toString()}`;
39+
break;
40+
case 'baidu':
41+
// see detail: https://www.jademond.com/magazine/baidu-search-url-parameters/
42+
sp.append('wd', query.value);
43+
url = `https://www.baidu.com/s?${sp.toString()}`;
44+
break;
45+
case 'naver':
46+
sp.append('query', query.value);
47+
url = `https://search.naver.com/search.naver?${sp.toString()}`;
48+
break;
49+
case 'duckduckgo':
50+
sp.append('q', query.value);
51+
url = `https://duckduckgo.com/?${sp.toString()}`;
52+
break;
53+
case 'other':
54+
sp.append(defaultStore.state.searchEngineUrlQuery, query.value);
55+
url = `${defaultStore.state.searchEngineUrl}${sp.toString()}`;
56+
break;
57+
}
58+
59+
window.open(url, '_blank', 'noopener');
2760
};
2861
</script>
2962

packages/frontend/src/pages/settings/general.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,25 @@ SPDX-License-Identifier: AGPL-3.0-only
152152
<option value="S">{{ i18n.ts._hemisphere.S }}</option>
153153
<template #caption>{{ i18n.ts._hemisphere.caption }}</template>
154154
</MkRadios>
155+
<MkSelect v-model="searchEngine">
156+
<template #label>{{ i18n.ts._searchSite.title }}</template>
157+
<template #caption>{{ i18n.ts._searchSite.description }}</template>
158+
<option value="google">{{ i18n.ts._searchSite.google }}</option>
159+
<option value="bing">{{ i18n.ts._searchSite.bing }}</option>
160+
<option value="yahoo">{{ i18n.ts._searchSite.yahoo }}</option>
161+
<option value="baidu">{{ i18n.ts._searchSite.baidu }}</option>
162+
<option value="naver">{{ i18n.ts._searchSite.naver }}</option>
163+
<option value="duckduckgo">{{ i18n.ts._searchSite.duckduckgo }}</option>
164+
<option value="other">{{ i18n.ts._searchSite.other }}</option>
165+
</MkSelect>
166+
<MkInput v-if="defaultStore.state.searchEngine == 'other'" v-model="searchEngineUrl">
167+
<template #label>{{ i18n.ts._searchSite.otherSearchEngine }}</template>
168+
<template #caption>{{ i18n.ts._searchSite.otherDescription }}</template>
169+
</MkInput>
170+
<MkInput v-if="defaultStore.state.searchEngine == 'other'" v-model="searchEngineUrlQuery">
171+
<template #label>{{ i18n.ts._searchSite.query }}</template>
172+
<template #caption>{{ i18n.ts._searchSite.queryDescription }}</template>
173+
</MkInput>
155174
<MkFolder>
156175
<template #label>{{ i18n.ts.additionalEmojiDictionary }}</template>
157176
<div class="_buttons">
@@ -191,6 +210,7 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
191210
import { miLocalStorage } from '@/local-storage.js';
192211
import { globalEvents } from '@/events.js';
193212
import { $i } from '@/account.js';
213+
import MkInput from '@/components/MkInput.vue';
194214
195215
const lang = ref(miLocalStorage.getItem('lang'));
196216
const dataSaver = ref(defaultStore.state.dataSaver);
@@ -223,6 +243,9 @@ const useAutoTranslate = computed(defaultStore.makeGetterSetter('useAutoTranslat
223243
const welcomeBackToast = computed(defaultStore.makeGetterSetter('welcomeBackToast'));
224244
const disableNyaize = computed(defaultStore.makeGetterSetter('disableNyaize'));
225245
const externalNavigationWarning = computed(defaultStore.makeGetterSetter('externalNavigationWarning'));
246+
const searchEngine = computed(defaultStore.makeGetterSetter('searchEngine'));
247+
const searchEngineUrl = computed(defaultStore.makeGetterSetter('searchEngineUrl'));
248+
const searchEngineUrlQuery = computed(defaultStore.makeGetterSetter('searchEngineUrlQuery'));
226249
227250
watch(lang, () => {
228251
miLocalStorage.setItem('lang', lang.value as string);

packages/frontend/src/store.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,18 @@ export const defaultStore = markRaw(new Storage('base', {
582582
where: 'device',
583583
default: false,
584584
},
585+
searchEngine: {
586+
where: 'device',
587+
default: 'google' as 'google' | 'bing' | 'yahoo' | 'baidu'| 'naver' | 'duckduckgo' | 'other',
588+
},
589+
searchEngineUrl: {
590+
where: 'device',
591+
default: 'https://www.ecosia.org/search?',
592+
},
593+
searchEngineUrlQuery: {
594+
where: 'device',
595+
default: 'q',
596+
},
585597

586598
// - Settings/Appearance
587599
collapseReplies: {

0 commit comments

Comments
 (0)