Skip to content

Commit

Permalink
fix: chat submit
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx committed Feb 20, 2025
1 parent aa56ca3 commit c6e656b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Learn more: [electronjs/doc](https://www.electronjs.org/docs/latest/api/extensio
<!-- EXTENSIONS_START -->
| Name | Version | Description |
| --- | --- | --- |
| [@noi/ask](https://github.com/lencx/Noi/tree/main/extensions/noi-ask) | 0.1.18 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/ask](https://github.com/lencx/Noi/tree/main/extensions/noi-ask) | 0.1.19 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/ask-custom](https://github.com/lencx/Noi/tree/main/extensions/noi-ask-custom) | 0.1.0 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/reset](https://github.com/lencx/Noi/tree/main/extensions/noi-reset) | 0.1.3 | Reset certain website styles to enhance compatibility with Noi. |
<!-- EXTENSIONS_END -->
Expand Down
4 changes: 2 additions & 2 deletions configs/noi.mode.cn.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Noi Mode",
"version": "0.1.10",
"version": "0.1.11",
"sync": "https://github.com/lencx/noi/blob/main/configs/noi.mode.cn.json",
"modes": [
{
Expand Down Expand Up @@ -103,7 +103,7 @@
"id": "noi:groq",
"parent": "noi@ai",
"text": "Groq",
"url": "https://groq.com"
"url": "https://chat.groq.com"
},
{
"id": "noi:lechatmistral",
Expand Down
4 changes: 2 additions & 2 deletions configs/noi.mode.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Noi Mode",
"version": "0.1.13",
"version": "0.1.14",
"sync": "https://github.com/lencx/noi/blob/main/configs/noi.mode.json",
"modes": [
{
Expand Down Expand Up @@ -109,7 +109,7 @@
"id": "noi:groq",
"parent": "noi@ai",
"text": "Groq",
"url": "https://groq.com"
"url": "https://chat.groq.com"
},
{
"id": "noi:lechatmistral",
Expand Down
2 changes: 1 addition & 1 deletion extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Learn more: [electronjs/doc](https://www.electronjs.org/docs/latest/api/extensio
<!-- EXTENSIONS_START -->
| Name | Version | Description |
| --- | --- | --- |
| [@noi/ask](https://github.com/lencx/Noi/tree/main/extensions/noi-ask) | 0.1.18 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/ask](https://github.com/lencx/Noi/tree/main/extensions/noi-ask) | 0.1.19 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/ask-custom](https://github.com/lencx/Noi/tree/main/extensions/noi-ask-custom) | 0.1.0 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/reset](https://github.com/lencx/Noi/tree/main/extensions/noi-reset) | 0.1.3 | Reset certain website styles to enhance compatibility with Noi. |
<!-- EXTENSIONS_END -->
67 changes: 27 additions & 40 deletions extensions/noi-ask/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class SoraAsk extends NoiAsk {
static url = 'https://sora.com';

static submit() {
const buttons = document.querySelectorAll('.surface-composer button');
const buttons = document.querySelectorAll('button[data-disabled]');
const lastButton = buttons[buttons.length - 1];
if (lastButton) this.autoClick(lastButton);
}
Expand All @@ -185,7 +185,7 @@ class PoeAsk extends NoiAsk {
static url = 'https://poe.com';

static submit() {
const btn = document.querySelectorAll('button[class*="ChatMessageSendButton_sendButton"]')[0];
const btn = document.querySelector('button[data-button-send]');
if (btn) this.autoClick(btn);
}
}
Expand All @@ -209,48 +209,24 @@ class CopilotAsk extends NoiAsk {
static url = 'https://copilot.microsoft.com';

static sync(message) {
// SERP Shadow DOM
const serpDOM = document.querySelector('.cib-serp-main');
// Action Bar Shadow DOM
const inputDOM = serpDOM.shadowRoot.querySelector('#cib-action-bar-main');
// Text Input Shadow DOM
const textInputDOM = inputDOM.shadowRoot.querySelector('cib-text-input');
// This inner cib-text-input Shadow DOM is not always present
const inputElement = textInputDOM ? textInputDOM.shadowRoot.querySelector('#searchbox') : inputDOM.shadowRoot.querySelector('#searchbox');
const inputElement = document.querySelector('#userInput');
if (inputElement) {
this.simulateUserInput(inputElement, message);
}
}

static autoFocus() {
const serpDOM = document.querySelector('.cib-serp-main');
const inputDOM = serpDOM.shadowRoot.querySelector('#cib-action-bar-main');
const textInputDOM = inputDOM.shadowRoot.querySelector('cib-text-input');
const inputElement = textInputDOM ? textInputDOM.shadowRoot.querySelector('#searchbox') : inputDOM.shadowRoot.querySelector('#searchbox');
if (inputElement) {
inputElement.focus();
const nativeTextareaSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value').set;
nativeTextareaSetter.call(inputElement, message);
const inputEvent = new InputEvent('input', {
bubbles: true,
cancelable: true,
});
inputElement.dispatchEvent(inputEvent);
}
// if (inputElement) {
// this.simulateUserInput(inputElement, message);
// }
}

static submit() {
try {
// Access SERP Shadow DOM
const serpDOM = document.querySelector('.cib-serp-main');
// Action Bar Shadow DOM
const actionDOM = serpDOM.shadowRoot.querySelector('#cib-action-bar-main');
// Submit Button
const submitButton = actionDOM.shadowRoot.querySelector('div.submit button');

if (submitButton) {
submitButton.click();
submitButton.focus();
setTimeout(() => {
submitButton.click();
}, 100)
}
} catch (e) {
console.error('Copilot submit error', e);
}
const btn = document.querySelector('button[aria-label="Submit message"]');
if (btn) this.autoClick(btn);
}
}

Expand Down Expand Up @@ -330,14 +306,24 @@ class YouAsk extends NoiAsk {

class GroqAsk extends NoiAsk {
static name = 'Groq';
static url = 'https://groq.com';
static url = 'https://chat.groq.com';

static submit() {
const btn = document.querySelector('form button[type="submit"]');
if (btn) btn.click();
}
}

class LeChatMistralAsk extends NoiAsk {
static name = 'LeChatMistral';
static url = 'https://chat.mistral.ai/chat';

static submit() {
const btn = document.querySelector('button[aria-label="Send question"]');
if (btn) btn.click();
}
}

class SunoAsk extends NoiAsk {
static name = 'Suno AI';
static url = 'https://suno.com';
Expand Down Expand Up @@ -453,6 +439,7 @@ window.NoiAsk = {
PerplexityAsk,
NotebooklmAsk,
GitHubCopilotAsk,
LeChatMistralAsk,
PiAsk,
GroqAsk,
PoeAsk,
Expand Down
5 changes: 3 additions & 2 deletions extensions/noi-ask/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "@noi/ask",
"version": "0.1.18",
"version": "0.1.19",
"homepage": "https://github.com/lencx/Noi/tree/main/extensions/noi-ask",
"description": "The best assistant for batch asking and quick typing of prompts.",
"content_scripts": [
Expand All @@ -16,7 +16,8 @@
"https://huggingface.co/chat/*",
"https://www.perplexity.ai/*",
"https://copilot.microsoft.com/*",
"https://groq.com/*",
"https://chat.groq.com/*",
"https://chat.mistral.ai/chat/*",
"https://pi.ai/talk/*",
"https://suno.com/*",
"https://notebooklm.google.com/*",
Expand Down
2 changes: 1 addition & 1 deletion extensions/noi.extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "@noi/ask",
"description": "The best assistant for batch asking and quick typing of prompts.",
"version": "0.1.18",
"version": "0.1.19",
"url": "https://github.com/lencx/Noi/tree/main/extensions/noi-ask",
"dirname": "noi-ask",
"disabled": false
Expand Down

0 comments on commit c6e656b

Please sign in to comment.