Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Adding support for StartPage.com #21

Open
wants to merge 7 commits into
base: main
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
7 changes: 7 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum CardStatus {
'PleaseLogin',
'UnknownError',
'TooManyRequests',
'GeneralError',
}
const answer = ref(null)
const cardStatus = ref<CardStatus>()
Expand Down Expand Up @@ -140,6 +141,10 @@ async function getAnswer(question: string, callback) {
removeAccessToken()
cardStatus.value = 'PleaseLogin'
}

if (event.status !== 200)
cardStatus.value = 'GeneralError'

if (event.status === 403)
cardStatus.value = 'BlockedByCloudflare'

Expand All @@ -160,6 +165,8 @@ async function getAnswer(question: string, callback) {

function getQuestion() {
switch (getWebsite().name) {
case 'startpage':
return document.getElementById("q").value;
case 'baidu':
return new URL(window.location.href).searchParams.get('wd')
case 'deepl': {
Expand Down
3 changes: 3 additions & 0 deletions src/components/ChatGPTCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ defineProps(['status', 'answer'])
<div v-else-if="status === 'TooManyRequests'" class="chat-gpt-container">
<p>{{ i18n('tooManyRequests') }}</p>
</div>
<div v-else-if="status === 'GeneralError'" class="chat-gpt-container">
<p>{{ i18n('generalError') }}</p>
</div>
</template>
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function initUI(container: HTMLDivElement) {
case 'duckduckgo':
duckduckgoInjectContainer(container)
break
case 'startpage':
startpageInjectContainer(container)
break
case 'deepl':
deeplInjectContainer(container)
break
Expand Down Expand Up @@ -86,6 +89,11 @@ function initUI(container: HTMLDivElement) {
const ChatGPTCard: Element = document.getElementsByClassName('results--sidebar')[0]
ChatGPTCard.prepend(container)
}
function startpageInjectContainer(container: HTMLDivElement) {
const ChatGPTCard: Element = document.getElementsByClassName('sidebar-results')[0]
container2.classList.add("sx-kp");
ChatGPTCard.prepend(container)
}
function deeplInjectContainer(container: HTMLDivElement) {
const button = document.createElement('button')
button.innerHTML = i18n('chatGPTTranslate')
Expand Down
3 changes: 3 additions & 0 deletions src/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function config(lang: string) {
networkException: '网络异常,请刷新页面。',
containerPosition: '容器位置 - 侧面(1)/顶部(0): ',
chatGPTTranslate: 'ChatGPT 翻译',
generalError: "NEEDS TRANSLATING: Error... Failed to get valid response from ChatGPT",
}
break
case 'zh-TW':
Expand All @@ -31,6 +32,7 @@ export function config(lang: string) {
networkException: '網路異常,請刷新頁面。',
containerPosition: '容器位置 - 側面(1)/頂部(0):',
chatGPTTranslate: 'ChatGPT 翻譯',
generalError: "NEEDS TRANSLATING: Error... Failed to get valid response from ChatGPT",
}
break
default:
Expand All @@ -43,6 +45,7 @@ export function config(lang: string) {
networkException: 'Network exception, please refresh the page.',
containerPosition: 'Container Position - Side(1)/Top(0): ',
chatGPTTranslate: 'ChatGPT Translate',
generalError: "Error... Failed to get valid response from ChatGPT",
}
}
return result
Expand Down
2 changes: 2 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export function getWebsite() {
return configRequestImmediately('baidu')
case 'duckduckgo.com':
return configRequestImmediately('duckduckgo')
case 'www.startpage.com':
return configRequestImmediately('startpage')
case 'www.deepl.com':
return configRequestAfterClickButton('deepl')
default:
Expand Down