Skip to content

Commit

Permalink
Merge pull request #9 from rizeuscu/main
Browse files Browse the repository at this point in the history
Added extension fixes and updates
  • Loading branch information
zterek authored Jul 4, 2024
2 parents ff5f193 + 3410d3b commit bf32baa
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lakera",
"version": "0.1.4",
"version": "0.1.5",
"description": "Lakera - ChatGPT Data Leak Protection",
"scripts": {
"dev": "vite build --watch",
Expand Down
6 changes: 3 additions & 3 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Lakera - ChatGPT Data Leak Protection",
"description": "Lakera Chrome Extension provides a privacy guard that protects you against sharing sensitive information with ChatGPT.",
"version": "0.1.4",
"version": "0.1.5",
"action": {
"default_icon": "icon-19.png",
"default_popup": "src/popup/popup.html"
Expand All @@ -16,7 +16,7 @@
},
"content_scripts": [
{
"matches": ["https://chat.openai.com/*"],
"matches": ["https://chat.openai.com/*", "https://chatgpt.com/*"],
"js": ["src/content.js"]
}
],
Expand All @@ -26,7 +26,7 @@
"web_accessible_resources": [
{
"resources": ["icon-128.png"],
"matches": ["https://chat.openai.com/*"]
"matches": ["https://chat.openai.com/*", "https://chatgpt.com/*"]
}
],
"permissions": [
Expand Down
6 changes: 4 additions & 2 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function fetchDomElements (): Promise<PromptElements> {
'prompt-textarea'
) as HTMLTextAreaElement | null
const button: HTMLButtonElement | null =
textarea?.parentElement?.querySelector('button') ?? null
textarea?.parentElement?.parentElement?.querySelector(':scope > button') ?? null

if (textarea !== null && button !== null) {
return { textarea, button }
Expand Down Expand Up @@ -95,7 +95,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {

async function fetchButton (textarea: HTMLTextAreaElement | null): Promise<HTMLButtonElement> {
const button: HTMLButtonElement | null =
textarea?.parentElement?.querySelector('button') ?? null
textarea?.parentElement?.parentElement?.querySelector(':scope > button') ?? null

if (button !== null) {
return button
Expand All @@ -109,6 +109,7 @@ function addEventListenersToButton (textarea: HTMLTextAreaElement | null, button
button?.addEventListener('click', (event) => {
void (async () => {
if (event.isTrusted) {
event.stopPropagation()
event.preventDefault()
const proceed = await shouldProceed(textarea)
if (proceed) {
Expand Down Expand Up @@ -155,6 +156,7 @@ function addEventListeners (
button?.addEventListener('click', (event) => {
void (async () => {
if (event.isTrusted) {
event.stopPropagation()
event.preventDefault()
const proceed = await shouldProceed(textarea)
if (proceed) {
Expand Down
4 changes: 2 additions & 2 deletions src/popup/popup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TIMEOUT_ADD_CLASS, CHATGPT_URL } from './popup_config'
import { TIMEOUT_ADD_CLASS, CHAT_GPT_URLS } from './popup_config'

function addEventListenersToToggles (detectorToggles: NodeListOf<Element>): void {
for (const detector of detectorToggles) {
Expand All @@ -23,7 +23,7 @@ async function addTriggeredDetectorsToDom (): Promise<void> {
if (
tab.id !== undefined &&
tab.url !== undefined &&
tab.url.includes(CHATGPT_URL)
CHAT_GPT_URLS.some(CHAT_GPT_URL => tab.url?.includes(CHAT_GPT_URL))
) {
chrome.tabs.sendMessage(
tab.id,
Expand Down
2 changes: 1 addition & 1 deletion src/popup/popup_config.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const CHATGPT_URL = 'chat.openai.com'
export const CHAT_GPT_URLS = ['chat.openai.com', 'chatgpt.com']
export const TIMEOUT_ADD_CLASS = 1000

0 comments on commit bf32baa

Please sign in to comment.