From e47d7370b3ac06c0b0540256e3e96a94c619a32e Mon Sep 17 00:00:00 2001 From: Andhavarapu Balu <74148176+JustTheCoolest@users.noreply.github.com> Date: Thu, 21 Mar 2024 16:53:15 +0530 Subject: [PATCH 01/11] Pane can be selected and loaded. Error after that --- src/lib/constants.ts | 2 + src/providers/google.js | 85 + test_google.html | 7446 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 7533 insertions(+) create mode 100644 src/providers/google.js create mode 100644 test_google.html diff --git a/src/lib/constants.ts b/src/lib/constants.ts index fd085e2..d3bbc5e 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -18,6 +18,7 @@ import Poe from 'providers/poe'; import InflectionPi from 'providers/inflection'; import StableChat from 'providers/stablechat'; import Falcon180BSpace from 'providers/falcon180bspace'; +import Google from 'providers/google'; export const allProviders = [ OpenAi, @@ -40,4 +41,5 @@ export const allProviders = [ LeptonLlama, Vercel, Smol, + Google, ]; diff --git a/src/providers/google.js b/src/providers/google.js new file mode 100644 index 0000000..04856bf --- /dev/null +++ b/src/providers/google.js @@ -0,0 +1,85 @@ +const Provider = require('./provider'); + +class Google extends Provider { + static webviewId = 'webviewGOOGLE'; + static fullName = 'Google Search'; + static shortName = 'Google'; + + static url = 'https://google.com/'; + + static handleInput(input) { + const fullName = this.fullName; + this.getWebview().executeJavaScript(`{ + var inputElement = document.querySelector('#APjFqb'); + if (inputElement) { + inputElement.innerHTML = \`${input}\` + } + }`); + } + + static handleSubmit() { + this.getWebview().executeJavaScript(`{ + var btn = document.querySelector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.FPdoLc.lJ9FBc > center > input.gNO89b"); + if (!btn) var btn = document.querySelector('body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf.emcav > div.UUbT9.EyBRub > div.aajZCb > div.lJ9FBc > center > input.gNO89b'); + if (!btn) var btn = document.querySelector('#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > button > div > span > svg'); + if (btn) { + btn.focus(); + btn.disabled = false; + btn.click(); + } + }`); + } + + static handleCss() { + this.getWebview().addEventListener('dom-ready', () => { + // hide message below text input, sidebar, suggestions on new chat + setTimeout(() => { + this.getWebview().insertCSS(` + /* hide the claude avatar in response */ + .p-1.w-9.h-9.shrink-0 { + display: none; + } + /* reduce claude prompt margins */ + .mx-4.md\:mx-12.mb-2.md\:mb-4.mt-2.w-auto { + margin: 0 !important; + } + + `); + }, 1000); + setTimeout(() => { + this.getWebview().executeJavaScript(`{ + // hide welcome back title + document.querySelector('h2').style.display = 'none'; + }`); + }, 1000); + }); + } + + static handleDarkMode(isDarkMode) { + if (isDarkMode) { + this.getWebview().insertCSS(` + body { + background-color: #1d1d1d !important; + filter: invert(100%) hue-rotate(180deg); + } + `); + } else { + this.getWebview().insertCSS(` + body { + background-color: #ffffff !important; + filter: none; + } + `); + } + } + + static getUserAgent() { + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'; + } + + static isEnabled() { + return window.electron.electronStore.get(`${this.webviewId}Enabled`, true); + } +} + +module.exports = Google; diff --git a/test_google.html b/test_google.html new file mode 100644 index 0000000..c779a18 --- /dev/null +++ b/test_google.html @@ -0,0 +1,7446 @@ + + + + + + + + + + Google + + + + + + + + + + + +
+ +
+ +
+ Google +
+
+
+ + + + +
+
+
+ +
+
+
+ +
+ + +
+
+
+ +
+
+ +
+ + + +
+
+ + +
+
+ +
+ + + + + + + +
+ +
+ + + + + + + + + + + +
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+ +
+ + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
Google apps
+
Search Labs
+
+
+
Google Account
+
Balu Andhavarapu
+
balu.somenumbers@gmail.com
+
+
+
+
+
+ + + + \ No newline at end of file From 3138a90721e40f2b5d126d4b69673bc01ae296e7 Mon Sep 17 00:00:00 2001 From: Andhavarapu Balu <74148176+JustTheCoolest@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:43:53 +0530 Subject: [PATCH 02/11] cleared handleCss of google, bug got less intense --- src/providers/google.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/providers/google.js b/src/providers/google.js index 04856bf..8bda23b 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -31,28 +31,6 @@ class Google extends Provider { } static handleCss() { - this.getWebview().addEventListener('dom-ready', () => { - // hide message below text input, sidebar, suggestions on new chat - setTimeout(() => { - this.getWebview().insertCSS(` - /* hide the claude avatar in response */ - .p-1.w-9.h-9.shrink-0 { - display: none; - } - /* reduce claude prompt margins */ - .mx-4.md\:mx-12.mb-2.md\:mb-4.mt-2.w-auto { - margin: 0 !important; - } - - `); - }, 1000); - setTimeout(() => { - this.getWebview().executeJavaScript(`{ - // hide welcome back title - document.querySelector('h2').style.display = 'none'; - }`); - }, 1000); - }); } static handleDarkMode(isDarkMode) { From d407a69f8051cf1028462de996a6a178efa80e00 Mon Sep 17 00:00:00 2001 From: Andhavarapu Balu <74148176+JustTheCoolest@users.noreply.github.com> Date: Tue, 9 Apr 2024 22:28:52 +0530 Subject: [PATCH 03/11] activated Provider.getUserAgent for Claude2 and Google --- src/providers/claude2.js | 2 +- src/providers/google.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/providers/claude2.js b/src/providers/claude2.js index 0400705..41ccb02 100644 --- a/src/providers/claude2.js +++ b/src/providers/claude2.js @@ -74,7 +74,7 @@ class Claude2 extends Provider { } static getUserAgent() { - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'; + return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'; } static isEnabled() { diff --git a/src/providers/google.js b/src/providers/google.js index 8bda23b..76d8f64 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -52,7 +52,7 @@ class Google extends Provider { } static getUserAgent() { - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'; + return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'; } static isEnabled() { From 3122f26f9f7de23140395b9cacd7b7286977af96 Mon Sep 17 00:00:00 2001 From: Andhavarapu Balu <74148176+JustTheCoolest@users.noreply.github.com> Date: Tue, 9 Apr 2024 22:30:18 +0530 Subject: [PATCH 04/11] minor innerRef fix (not sure of the theory behind it) --- src/renderer/browserPane.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/renderer/browserPane.tsx b/src/renderer/browserPane.tsx index d023961..533e9e6 100644 --- a/src/renderer/browserPane.tsx +++ b/src/renderer/browserPane.tsx @@ -80,7 +80,10 @@ export function BrowserPane({ {(provided2, snapshot) => ( -
+
From 67b665bfc0758b7660ff0426bb3c5527b2be92dd Mon Sep 17 00:00:00 2001 From: Andhavarapu Balu <74148176+JustTheCoolest@users.noreply.github.com> Date: Tue, 9 Apr 2024 22:30:48 +0530 Subject: [PATCH 05/11] succesfully got Google to work! (bugs pending fixes) --- src/providers/google.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/providers/google.js b/src/providers/google.js index 76d8f64..83f69bb 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -8,13 +8,19 @@ class Google extends Provider { static url = 'https://google.com/'; static handleInput(input) { - const fullName = this.fullName; - this.getWebview().executeJavaScript(`{ - var inputElement = document.querySelector('#APjFqb'); - if (inputElement) { - inputElement.innerHTML = \`${input}\` - } - }`); + console.log(input); + let webview = this.getWebview(); + webview.executeJavaScript(` + var inputElement = document.querySelector('#APjFqb'); + if (inputElement) { + inputElement.value = "${input}"; + "Element updated"; + } else { + "Element not found"; + } + `) + .then(output => console.log(output)) + .catch(error => console.error(error)); } static handleSubmit() { From 26140593f8d30b6c4e7ab485d5c5e4d4d6fd9a4f Mon Sep 17 00:00:00 2001 From: Andhavarapu Balu <74148176+JustTheCoolest@users.noreply.github.com> Date: Thu, 11 Apr 2024 21:52:04 +0530 Subject: [PATCH 06/11] Added redirect back to home when input is given (bug: redirecting when page did not load will crash) --- src/providers/google.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/providers/google.js b/src/providers/google.js index 83f69bb..ec29938 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -5,35 +5,33 @@ class Google extends Provider { static fullName = 'Google Search'; static shortName = 'Google'; - static url = 'https://google.com/'; + static url = 'https://www.google.com/'; static handleInput(input) { - console.log(input); let webview = this.getWebview(); + input = JSON.stringify(input); + console.log(webview.getURL(), this.url); + if (!webview.getURL().startsWith(this.url)) { + webview.loadURL(this.url); + } webview.executeJavaScript(` var inputElement = document.querySelector('#APjFqb'); - if (inputElement) { - inputElement.value = "${input}"; - "Element updated"; - } else { - "Element not found"; - } + inputElement.value = ${input}; `) - .then(output => console.log(output)) - .catch(error => console.error(error)); } static handleSubmit() { - this.getWebview().executeJavaScript(`{ - var btn = document.querySelector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.FPdoLc.lJ9FBc > center > input.gNO89b"); - if (!btn) var btn = document.querySelector('body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf.emcav > div.UUbT9.EyBRub > div.aajZCb > div.lJ9FBc > center > input.gNO89b'); - if (!btn) var btn = document.querySelector('#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > button > div > span > svg'); - if (btn) { - btn.focus(); - btn.disabled = false; - btn.click(); - } - }`); + this.getWebview().executeJavaScript(` + { + var btn = document.querySelector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.FPdoLc.lJ9FBc > center > input.gNO89b"); + if (!btn) btn = document.querySelector('body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf.emcav > div.UUbT9.EyBRub > div.aajZCb > div.lJ9FBc > center > input.gNO89b'); + if (!btn) btn = document.querySelector('#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > button'); + if (btn) { + btn.focus(); + btn.disabled = false; + btn.click(); + } + }`) } static handleCss() { From 8697a5df451b6a0f594d78c1fed0c40e5933157d Mon Sep 17 00:00:00 2001 From: PS Vijay Date: Thu, 11 Apr 2024 21:54:17 +0530 Subject: [PATCH 07/11] Styling Google Search Home Page --- src/providers/google.js | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/providers/google.js b/src/providers/google.js index 83f69bb..8abe76f 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -10,7 +10,9 @@ class Google extends Provider { static handleInput(input) { console.log(input); let webview = this.getWebview(); - webview.executeJavaScript(` + webview + .executeJavaScript( + ` var inputElement = document.querySelector('#APjFqb'); if (inputElement) { inputElement.value = "${input}"; @@ -18,9 +20,10 @@ class Google extends Provider { } else { "Element not found"; } - `) - .then(output => console.log(output)) - .catch(error => console.error(error)); + `, + ) + .then((output) => console.log(output)) + .catch((error) => console.error(error)); } static handleSubmit() { @@ -37,6 +40,34 @@ class Google extends Provider { } static handleCss() { + this.getWebview().addEventListener('dom-ready', () => { + this.getWebview().insertCSS(` + html,body{ + zoom:80%; + font-size:14px; + overflow: hidden; + scrollbar-width: none; + } + .L3eUgb{ + max-width:75%; + margin:0 auto; + } + @media (max-width:275px){ + html,body{ + zoom:70%; + font-size:12px; + } + .L3eUgb{ + margin:0 auto 0 4rem; + } + } + @media (max-width:220px){ + .L3eUgb{ + margin:0 auto 0 0.5rem; + } + } + `); + }); } static handleDarkMode(isDarkMode) { From 095d60638a36e31e0659820674756baad53d1e55 Mon Sep 17 00:00:00 2001 From: PS Vijay Date: Thu, 11 Apr 2024 23:33:57 +0530 Subject: [PATCH 08/11] fixed scroll bar issues --- src/providers/google.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/providers/google.js b/src/providers/google.js index 8abe76f..c2157ff 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -39,31 +39,48 @@ class Google extends Provider { }`); } - static handleCss() { + static handleCss() { this.getWebview().addEventListener('dom-ready', () => { this.getWebview().insertCSS(` html,body{ zoom:80%; font-size:14px; - overflow: hidden; - scrollbar-width: none; + scrollbar-width: thin; } .L3eUgb{ max-width:75%; margin:0 auto; } - @media (max-width:275px){ + @media (max-width:320px){ html,body{ zoom:70%; font-size:12px; } + .L3eUgb{ + max-width:70%; + margin:0 auto; + } + } + @media (max-width:275px){ .L3eUgb{ margin:0 auto 0 4rem; } } @media (max-width:220px){ .L3eUgb{ - margin:0 auto 0 0.5rem; + margin:0 auto 0 1.75rem; + } + } + @media (max-width:210px){ + .L3eUgb{ + margin:0 auto 0 0; + } + .om7nvf { + padding: 20px 0 !important; + } + .RNNXgb{ + width:0; + max-width:354px !important; } } `); From c7ed9a2edc8be0031d244bf553ebd1c8519b5375 Mon Sep 17 00:00:00 2001 From: Andhavarapu Balu <74148176+JustTheCoolest@users.noreply.github.com> Date: Fri, 12 Apr 2024 06:28:15 +0530 Subject: [PATCH 09/11] fixed redirect bug (only pending task: UI) --- src/providers/google.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/providers/google.js b/src/providers/google.js index a6b0b09..d4159ca 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -12,7 +12,10 @@ class Google extends Provider { input = JSON.stringify(input); console.log(webview.getURL(), this.url); if (!webview.getURL().startsWith(this.url)) { - webview.loadURL(this.url); + webview.loadURL(this.url) + .catch(e => { + console.log(e); + }); } webview.executeJavaScript(` var inputElement = document.querySelector('#APjFqb'); From 31c58c9b848ebf752329dca43cff039e6ddbc927 Mon Sep 17 00:00:00 2001 From: JustTheCoolest Date: Thu, 23 May 2024 20:30:17 +0530 Subject: [PATCH 10/11] used mobile agent to fix UI - broke handleSubmit --- src/providers/google.js | 43 +++-------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/src/providers/google.js b/src/providers/google.js index d4159ca..fef2822 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -18,7 +18,7 @@ class Google extends Provider { }); } webview.executeJavaScript(` - var inputElement = document.querySelector('#APjFqb'); + var inputElement = document.querySelector('#tsf > div:nth-child(1) > div.A7Yvie.Epl37 > div.zGVn2e > div.SDkEP > div > textarea'); inputElement.value = ${input}; `) } @@ -26,7 +26,7 @@ class Google extends Provider { static handleSubmit() { this.getWebview().executeJavaScript(` { - var btn = document.querySelector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.FPdoLc.lJ9FBc > center > input.gNO89b"); + var btn = document.querySelector("#tsf > div:nth-child(1) > div.A7Yvie.Epl37 > div.zGVn2e > button.Tg7LZd.search_button_suggest"); if (!btn) btn = document.querySelector('body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf.emcav > div.UUbT9.EyBRub > div.aajZCb > div.lJ9FBc > center > input.gNO89b'); if (!btn) btn = document.querySelector('#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > button'); if (btn) { @@ -40,47 +40,10 @@ class Google extends Provider { static handleCss() { this.getWebview().addEventListener('dom-ready', () => { this.getWebview().insertCSS(` - html,body{ - zoom:80%; - font-size:14px; - scrollbar-width: thin; - } - .L3eUgb{ - max-width:75%; - margin:0 auto; - } - @media (max-width:320px){ html,body{ zoom:70%; font-size:12px; } - .L3eUgb{ - max-width:70%; - margin:0 auto; - } - } - @media (max-width:275px){ - .L3eUgb{ - margin:0 auto 0 4rem; - } - } - @media (max-width:220px){ - .L3eUgb{ - margin:0 auto 0 1.75rem; - } - } - @media (max-width:210px){ - .L3eUgb{ - margin:0 auto 0 0; - } - .om7nvf { - padding: 20px 0 !important; - } - .RNNXgb{ - width:0; - max-width:354px !important; - } - } `); }); } @@ -104,7 +67,7 @@ class Google extends Provider { } static getUserAgent() { - return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'; + return 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36 Edg/125.0.0.0'; } static isEnabled() { From 3cce8c2680d8233143607c6d98ed0113c3aa1679 Mon Sep 17 00:00:00 2001 From: JustTheCoolest Date: Thu, 23 May 2024 22:08:02 +0530 Subject: [PATCH 11/11] fixed handleSubmit --- src/providers/google.js | 44 +- test_google.html | 7446 --------------------------------------- 2 files changed, 19 insertions(+), 7471 deletions(-) delete mode 100644 test_google.html diff --git a/src/providers/google.js b/src/providers/google.js index fef2822..de44fd4 100644 --- a/src/providers/google.js +++ b/src/providers/google.js @@ -26,44 +26,38 @@ class Google extends Provider { static handleSubmit() { this.getWebview().executeJavaScript(` { - var btn = document.querySelector("#tsf > div:nth-child(1) > div.A7Yvie.Epl37 > div.zGVn2e > button.Tg7LZd.search_button_suggest"); - if (!btn) btn = document.querySelector('body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf.emcav > div.UUbT9.EyBRub > div.aajZCb > div.lJ9FBc > center > input.gNO89b'); - if (!btn) btn = document.querySelector('#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > button'); - if (btn) { - btn.focus(); - btn.disabled = false; - btn.click(); - } + document.querySelector("form").submit(); }`) } static handleCss() { this.getWebview().addEventListener('dom-ready', () => { this.getWebview().insertCSS(` + @media (max-width:320px){ html,body{ - zoom:70%; - font-size:12px; + zoom:95%; } + } `); }); } static handleDarkMode(isDarkMode) { - if (isDarkMode) { - this.getWebview().insertCSS(` - body { - background-color: #1d1d1d !important; - filter: invert(100%) hue-rotate(180deg); - } - `); - } else { - this.getWebview().insertCSS(` - body { - background-color: #ffffff !important; - filter: none; - } - `); - } + // if (isDarkMode) { + // this.getWebview().insertCSS(` + // body { + // background-color: #1d1d1d !important; + // filter: invert(100%) hue-rotate(180deg); + // } + // `); + // } else { + // this.getWebview().insertCSS(` + // body { + // background-color: #ffffff !important; + // filter: none; + // } + // `); + // } } static getUserAgent() { diff --git a/test_google.html b/test_google.html deleted file mode 100644 index c779a18..0000000 --- a/test_google.html +++ /dev/null @@ -1,7446 +0,0 @@ - - - - - - - - - - Google - - - - - - - - - - - -
- -
- -
- Google -
-
-
- - - - -
-
-
- -
-
-
- -
- - -
-
-
- -
-
- -
- - - -
-
- - -
-
- -
- - - - - - - -
- -
- - - - - - - - - - - -
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
- -
- - -
-
-
- -
- -
-
- -
- -
-
- -
-
-
Google apps
-
Search Labs
-
-
-
Google Account
-
Balu Andhavarapu
-
balu.somenumbers@gmail.com
-
-
-
-
-
- - - - \ No newline at end of file