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

Added Google Search as a provider #296

Open
wants to merge 13 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
2 changes: 2 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,4 +41,5 @@ export const allProviders = [
LeptonLlama,
Vercel,
Smol,
Google,
];
2 changes: 1 addition & 1 deletion src/providers/claude2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
72 changes: 72 additions & 0 deletions src/providers/google.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const Provider = require('./provider');

class Google extends Provider {
static webviewId = 'webviewGOOGLE';
static fullName = 'Google Search';
static shortName = 'Google';

static url = 'https://www.google.com/';

static handleInput(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)
.catch(e => {
console.log(e);
});
}
webview.executeJavaScript(`
var inputElement = document.querySelector('#tsf > div:nth-child(1) > div.A7Yvie.Epl37 > div.zGVn2e > div.SDkEP > div > textarea');
inputElement.value = ${input};
`)
}

static handleSubmit() {
this.getWebview().executeJavaScript(`
{
document.querySelector("form").submit();
}`)
}

static handleCss() {
this.getWebview().addEventListener('dom-ready', () => {
this.getWebview().insertCSS(`
@media (max-width:320px){
html,body{
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;
// }
// `);
// }
}

static getUserAgent() {
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() {
return window.electron.electronStore.get(`${this.webviewId}Enabled`, true);
}
}

module.exports = Google;
5 changes: 4 additions & 1 deletion src/renderer/browserPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export function BrowserPane({
<DragDropContext onDragEnd={onDragEnd}>
<Droppable droppableId="droppable">
{(provided2, snapshot) => (
<div className="flex flex-col justify-between">
<div className="flex flex-col justify-between"
ref={provided2.innerRef} // Add this line
{...provided2.droppableProps} // And this line
>
<Menu as="div" className="relative inline-block text-left">
<div>
<Menu.Button className="inline-flex justify-center gap-x-1.5 rounded-md px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50">
Expand Down