chore: noi ask

This commit is contained in:
lencx
2024-01-21 21:39:35 +08:00
parent e12983d630
commit 81963c12d5
8 changed files with 134 additions and 8 deletions

View File

@@ -1 +1 @@
# Noi Ask
# @noi/ask

View File

@@ -1,3 +1,10 @@
/**
* NoiAsk: Batch send messages to AI Chat.
*
* This file is a modified version of the GodMode.
* ref: https://github.com/smol-ai/GodMode/tree/main/src/providers
*/
class NoiAsk {
static sync(message) {
const inputElement = document.querySelector(`textarea`);
@@ -12,6 +19,16 @@ class NoiAsk {
}
}
static simulateUserInput(element, text) {
const inputEvent = new InputEvent('input', {
bubbles: true,
cancelable: true,
});
element.focus();
element.value = text;
element.dispatchEvent(inputEvent);
}
static autoClick(btn) {
btn.focus();
btn.disabled = false;
@@ -123,6 +140,63 @@ class PerplexityAsk extends NoiAsk {
}
}
class CopilotAsk extends NoiAsk {
static name = 'Copilot';
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');
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);
}
}
}
class PiAsk extends NoiAsk {
static name = 'Pi';
static url = 'https://pi.ai/talk';
static submit() {
const inputElement = document.querySelector('textarea[placeholder="Talk with Pi"]');
if (inputElement) {
const event = new KeyboardEvent('keydown', {
key: 'Enter',
view: window,
bubbles: true
});
inputElement.dispatchEvent(event);
}
}
}
window.NoiAsk = {
OpenAIAsk,
PoeAsk,
@@ -130,4 +204,6 @@ window.NoiAsk = {
BardAsk,
HuggingChatAsk,
PerplexityAsk,
CopilotAsk,
PiAsk,
};

View File

@@ -11,7 +11,9 @@
"https://poe.com/*",
"https://claude.ai/*",
"https://huggingface.co/chat/*",
"https://www.perplexity.ai/*"
"https://www.perplexity.ai/*",
"https://copilot.microsoft.com/*",
"https://pi.ai/talk/*"
],
"js": ["main.js"],
"run_at": "document_end",

View File

@@ -1 +1 @@
# Noi Export - ChatGPT
# @noi/export-chatgpt

View File

@@ -0,0 +1 @@
# @noi/reset

View File

@@ -0,0 +1,14 @@
// fix: sidebar not clickable
function removeAppRegion() {
const allElements = document.querySelectorAll('*');
for (let element of allElements) {
const style = window.getComputedStyle(element);
if (style.webkitAppRegion === 'drag' || style.webkitAppRegion === 'no-drag') {
element.style.webkitAppRegion = 'initial';
// console.log('Removed -webkit-app-region from:', element);
}
}
}
setTimeout(removeAppRegion, 3000);

View File

@@ -0,0 +1,16 @@
{
"manifest_version": 3,
"name": "@noi/reset",
"version": "0.1.0",
"homepage": "https://github.com/lencx/Noi/tree/main/extensions/noi-reset",
"content_scripts": [
{
"matches": [
"https://vscode.dev/*"
],
"js": ["main.js"],
"run_at": "document_end",
"world": "MAIN"
}
]
}