From 8c2078856c4c47a7acaaa6e2fa0bd74bd556e4b2 Mon Sep 17 00:00:00 2001 From: Bazoogle <8096843+Bazoogle@users.noreply.github.com> Date: Fri, 31 Mar 2023 23:55:24 -0400 Subject: [PATCH 1/7] Added startpage injection Added container injection for the search engine startpage.com --- src/main.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.ts b/src/main.ts index 2e24417..51597a6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,6 +28,9 @@ function initUI(container: HTMLDivElement) { case 'duckduckgo': duckduckgoInjectContainer(container) break + case 'startpage': + startpageInjectContainer(container) + break case 'deepl': deeplInjectContainer(container) break @@ -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') From 4693e8e86ea7a5e4ec412a693ff2a2a0e0281a7d Mon Sep 17 00:00:00 2001 From: Bazoogle <8096843+Bazoogle@users.noreply.github.com> Date: Sat, 1 Apr 2023 00:01:36 -0400 Subject: [PATCH 2/7] Added StartPage search query Startpage.com search query does not always have the search in the URL parameter. The next best option is to get the value from the search element. Also added an error for any status that isn't 200, to show it was not working. I was having issues because it told me it was waiting for ChatGPT to answer, but it had already thrown an error. This at least shows that something is wrong. --- src/App.vue | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/App.vue b/src/App.vue index 56bcad2..3255758 100644 --- a/src/App.vue +++ b/src/App.vue @@ -145,6 +145,9 @@ async function getAnswer(question: string, callback) { if (event.status === 429) cardStatus.value = 'TooManyRequests' + + if (event.status !== 200) + cardStatus.value = 'GeneralError' if (getUserscriptManager() !== 'Tampermonkey') { if (event.response) @@ -160,6 +163,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': { From a1144d964405d89623e10ee7543f54fa9cb17d3f Mon Sep 17 00:00:00 2001 From: Bazoogle <8096843+Bazoogle@users.noreply.github.com> Date: Sat, 1 Apr 2023 00:02:08 -0400 Subject: [PATCH 3/7] Fixed CardStatus enum --- src/App.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App.vue b/src/App.vue index 3255758..7f4b6f8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -12,6 +12,7 @@ enum CardStatus { 'PleaseLogin', 'UnknownError', 'TooManyRequests', + 'GeneralError', } const answer = ref(null) const cardStatus = ref() From 857c83ad833eba17acbd5922d50ecc016e23f1ed Mon Sep 17 00:00:00 2001 From: Bazoogle <8096843+Bazoogle@users.noreply.github.com> Date: Sat, 1 Apr 2023 00:03:28 -0400 Subject: [PATCH 4/7] Added general error to the alert options --- src/components/ChatGPTCard.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/ChatGPTCard.vue b/src/components/ChatGPTCard.vue index d14178c..1418075 100644 --- a/src/components/ChatGPTCard.vue +++ b/src/components/ChatGPTCard.vue @@ -25,4 +25,7 @@ defineProps(['status', 'answer'])

{{ i18n('tooManyRequests') }}

+
+

{{ i18n('generalError') }}

+
From 76878e05955a3ada9c0252eeb0e438d2b9da877d Mon Sep 17 00:00:00 2001 From: Bazoogle <8096843+Bazoogle@users.noreply.github.com> Date: Sat, 1 Apr 2023 00:05:15 -0400 Subject: [PATCH 5/7] Added GeneralError text Needs translating --- src/utils/i18n.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts index 7d22728..551d7d7 100644 --- a/src/utils/i18n.ts +++ b/src/utils/i18n.ts @@ -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': @@ -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: @@ -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 From 6672689c66a2d5e61101cdc10027bf32b3cc84b4 Mon Sep 17 00:00:00 2001 From: Bazoogle <8096843+Bazoogle@users.noreply.github.com> Date: Sat, 1 Apr 2023 00:06:08 -0400 Subject: [PATCH 6/7] Added startpage to the getWebsite switch --- src/utils/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/index.ts b/src/utils/index.ts index 1c74558..3fa1dcc 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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: From 29e976be7a5e3cf4e80c05ee0e559cbb9f405d79 Mon Sep 17 00:00:00 2001 From: Bazoogle <8096843+Bazoogle@users.noreply.github.com> Date: Sat, 1 Apr 2023 01:13:10 -0400 Subject: [PATCH 7/7] General Status Error Fix moved the general status error to before the other errors, so if there was an accounted for error it would overwrite the general error. This could definitely be arranged better with some if else statements --- src/App.vue | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/App.vue b/src/App.vue index 7f4b6f8..e61deeb 100644 --- a/src/App.vue +++ b/src/App.vue @@ -141,14 +141,15 @@ async function getAnswer(question: string, callback) { removeAccessToken() cardStatus.value = 'PleaseLogin' } + + if (event.status !== 200) + cardStatus.value = 'GeneralError' + if (event.status === 403) cardStatus.value = 'BlockedByCloudflare' if (event.status === 429) cardStatus.value = 'TooManyRequests' - - if (event.status !== 200) - cardStatus.value = 'GeneralError' if (getUserscriptManager() !== 'Tampermonkey') { if (event.response)