-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable prompt template on all urls (#7)
- Loading branch information
Showing
6 changed files
with
108 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { IPrompt } from '@rpidanny/llm-prompt-templates'; | ||
import { message } from 'antd'; | ||
|
||
import { BaseDom } from './base.dom'; | ||
|
||
export class GenericDom extends BaseDom { | ||
protected name = 'Generic'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
protected addCustomTrigger() {} | ||
|
||
protected usePrompt(prompt: IPrompt) { | ||
const clipboardItem = new ClipboardItem({ | ||
'text/plain': new Blob([prompt.content], { type: 'text/plain' }), | ||
}); | ||
navigator.clipboard.write([clipboardItem]); | ||
|
||
message.info(`${prompt.name} prompt copied to clipboard`); | ||
} | ||
} | ||
|
||
function init() { | ||
const genericDom = new GenericDom(); | ||
|
||
setTimeout(genericDom.init, 1000); | ||
} | ||
|
||
init(); |
12 changes: 2 additions & 10 deletions
12
apps/chrome-extension/src/pages/Content/llms/bard/bard.dom.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
import { BaseDom } from '../../base.dom'; | ||
import { ChatGPTDom } from '../chatgpt/chatgpt.dom'; | ||
|
||
export class BardDom extends BaseDom { | ||
export class BardDom extends ChatGPTDom { | ||
protected name = 'Bard'; | ||
protected textAreaSelector = 'div > textarea'; | ||
|
||
protected setText(text: string) { | ||
const textArea = this.getTextArea(); | ||
console.log('Setting text', text); | ||
textArea.focus(); | ||
textArea.value = text; | ||
textArea.style.height = textArea.scrollHeight + 'px'; | ||
} | ||
} |
31 changes: 28 additions & 3 deletions
31
apps/chrome-extension/src/pages/Content/llms/chatgpt/chatgpt.dom.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,39 @@ | ||
import { IPrompt } from '@rpidanny/llm-prompt-templates'; | ||
|
||
import { BaseDom } from '../../base.dom'; | ||
|
||
export class ChatGPTDom extends BaseDom { | ||
protected name = 'ChatGPT'; | ||
protected textAreaSelector = 'div.relative > textarea'; | ||
|
||
protected setText(text: string) { | ||
private getTextArea(): HTMLTextAreaElement { | ||
const textArea = document.querySelector<HTMLTextAreaElement>( | ||
this.textAreaSelector | ||
); | ||
|
||
if (!textArea) throw new Error('Could not find text area'); | ||
|
||
return textArea; | ||
} | ||
|
||
protected addCustomTrigger() { | ||
this.getTextArea().addEventListener('input', (event) => { | ||
const input = event.target as HTMLTextAreaElement; | ||
const text = input.value; | ||
|
||
if (text === '/templates') { | ||
this.showPrompts(); | ||
} else if (this.isPromptsViewOpen) { | ||
this.hidePrompts(); | ||
} | ||
}); | ||
} | ||
|
||
protected usePrompt(prompt: IPrompt) { | ||
const textArea = this.getTextArea(); | ||
console.log('Setting text', text); | ||
console.log('Setting text', prompt.content); | ||
textArea.focus(); | ||
textArea.value = text; | ||
textArea.value = prompt.content; | ||
textArea.style.height = textArea.scrollHeight + 'px'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters