From 3b26091bf130cc1075cb8df09009c2fb293832a9 Mon Sep 17 00:00:00 2001 From: Srujan Gurram Date: Tue, 11 Mar 2025 21:00:13 +0530 Subject: [PATCH] Fix linting issues and refactor code for better readability --- src/entrypoints/quick-menu.content/index.ts | 52 ++++++------- .../quick-menu.content/initQuickMenu.tsx | 3 +- .../quick-menu.content/listenContextMenu.tsx | 1 - src/entrypoints/sidebar_bg.content/index.ts | 2 +- src/logs.tsx | 12 +-- wxt.config.ts | 76 +++++++++---------- 6 files changed, 72 insertions(+), 74 deletions(-) diff --git a/src/entrypoints/quick-menu.content/index.ts b/src/entrypoints/quick-menu.content/index.ts index a9b2ffa4..7c81e7e2 100644 --- a/src/entrypoints/quick-menu.content/index.ts +++ b/src/entrypoints/quick-menu.content/index.ts @@ -5,36 +5,36 @@ import type { Settings } from '../../config/settings' import initQuickMenu from './initQuickMenu' export default defineContentScript({ - matches: ['http://*/*', 'https://*/*',''], + matches: ['http://*/*', 'https://*/*', ''], allFrames: true, main() { chrome.storage.sync.get(['SETTINGS'], (result) => { - const quickMenuSettings = result.SETTINGS?.quickMenu as Settings['quickMenu'] - if (quickMenuSettings) { - if (quickMenuSettings.enabled) { - if (quickMenuSettings.excludedSites.length === 0) initQuickMenu() - else { - const whitelister = new Whitelister( - quickMenuSettings.excludedSites || '*', - ) - const isExcluded = whitelister.verify(window.location.href) - if (!isExcluded) initQuickMenu() - } + const quickMenuSettings = result.SETTINGS + ?.quickMenu as Settings['quickMenu'] + if (quickMenuSettings) { + if (quickMenuSettings.enabled) { + if (quickMenuSettings.excludedSites.length === 0) initQuickMenu() + else { + const whitelister = new Whitelister( + quickMenuSettings.excludedSites || '*', + ) + const isExcluded = whitelister.verify(window.location.href) + if (!isExcluded) initQuickMenu() } - } else { - initQuickMenu() } - }) - chrome.runtime.onMessage.addListener(async (request) => { - const { payload } = request - const { selectedText, id } = payload || {} - if (selectedText && id) { - const prompt = (await findPrompt(id)).prompt - if (prompt) { - generatePromptInSidebar(prompt, selectedText) - } + } else { + initQuickMenu() + } + }) + chrome.runtime.onMessage.addListener(async (request) => { + const { payload } = request + const { selectedText, id } = payload || {} + if (selectedText && id) { + const prompt = (await findPrompt(id)).prompt + if (prompt) { + generatePromptInSidebar(prompt, selectedText) } - }) - + } + }) }, -}) \ No newline at end of file +}) diff --git a/src/entrypoints/quick-menu.content/initQuickMenu.tsx b/src/entrypoints/quick-menu.content/initQuickMenu.tsx index aefe648c..46f82941 100644 --- a/src/entrypoints/quick-menu.content/initQuickMenu.tsx +++ b/src/entrypoints/quick-menu.content/initQuickMenu.tsx @@ -3,7 +3,6 @@ import HighlightMenu from 'react-highlight-menu' import { createRoot } from 'react-dom/client' import { contentScriptLog } from '../../logs' - /** * Initializes the visual quick menu. (when the user selects text) * It is only initialized if the user has enabled it in the settings. @@ -34,4 +33,4 @@ const initQuickMenu = () => { ) } -export default initQuickMenu; \ No newline at end of file +export default initQuickMenu diff --git a/src/entrypoints/quick-menu.content/listenContextMenu.tsx b/src/entrypoints/quick-menu.content/listenContextMenu.tsx index 2a3454fa..f3d9302a 100644 --- a/src/entrypoints/quick-menu.content/listenContextMenu.tsx +++ b/src/entrypoints/quick-menu.content/listenContextMenu.tsx @@ -7,4 +7,3 @@ import { generatePromptInSidebar } from '../../lib/generatePromptInSidebar' * * We listen to this message and generate the prompt in the sidebar. */ - diff --git a/src/entrypoints/sidebar_bg.content/index.ts b/src/entrypoints/sidebar_bg.content/index.ts index f20acea0..e99c413d 100644 --- a/src/entrypoints/sidebar_bg.content/index.ts +++ b/src/entrypoints/sidebar_bg.content/index.ts @@ -67,7 +67,7 @@ function setupMessageListeners(iframe: HTMLIFrameElement) { } export default defineContentScript({ - matches: ['http://*/*', 'https://*/*',''], + matches: ['http://*/*', 'https://*/*', ''], main() { contentScriptLog('Sidebar') const iframe = createSidebar() diff --git a/src/logs.tsx b/src/logs.tsx index 7aa87f20..bb323c2d 100644 --- a/src/logs.tsx +++ b/src/logs.tsx @@ -1,12 +1,12 @@ const logoText = - " ____ _\n/ ___| _ _ _ __ ___(_) __ _\n\\___ \\| | | | '_ \\ / __| |/ _` |\n ___) | |_| | | | | (__| | (_| |\n|____/ \\__, |_| |_|\\___|_|\\__,_|\n |___/"; + " ____ _\n/ ___| _ _ _ __ ___(_) __ _\n\\___ \\| | | | '_ \\ / __| |/ _` |\n ___) | |_| | | | | (__| | (_| |\n|____/ \\__, |_| |_|\\___|_|\\__,_|\n |___/" -const msgText = (msg: string) => `\n${' '.repeat(14 - msg.length / 2)}[${msg}]`; +const msgText = (msg: string) => `\n${' '.repeat(14 - msg.length / 2)}[${msg}]` export const contentScriptLog = (item: string) => { - console.log(logoText, msgText(`${item} Script Loaded`)); -}; + console.log(logoText, msgText(`${item} Script Loaded`)) +} export const backgroundLog = () => { - console.log(logoText, msgText('Background Loaded')); -}; + console.log(logoText, msgText('Background Loaded')) +} diff --git a/wxt.config.ts b/wxt.config.ts index f2094f6d..de0832d6 100644 --- a/wxt.config.ts +++ b/wxt.config.ts @@ -1,67 +1,67 @@ -import { defineConfig, UserManifest } from "wxt"; +import { defineConfig, type UserManifest } from 'wxt' const generateManifest = () => { const manifest: UserManifest = { action: { - default_title: "Syncia - Open Sidebar", + default_title: 'Syncia - Open Sidebar', }, commands: { - "open-sidebar": { + 'open-sidebar': { suggested_key: { - default: "Ctrl+Shift+X", - mac: "Command+Shift+X", + default: 'Ctrl+Shift+X', + mac: 'Command+Shift+X', }, - description: "Open the sidebar", + description: 'Open the sidebar', }, }, - externally_connectable: { ids: ["*"] }, + externally_connectable: { ids: ['*'] }, icons: { - "16": "images/icon-16.png", - "32": "images/icon-32.png", - "48": "images/icon-48.png", - "128": "images/icon-128.png", + '16': 'images/icon-16.png', + '32': 'images/icon-32.png', + '48': 'images/icon-48.png', + '128': 'images/icon-128.png', }, permissions: [ - "storage", - "unlimitedStorage", - "contextMenus", - "tabs", - "activeTab", - "clipboardWrite", + 'storage', + 'unlimitedStorage', + 'contextMenus', + 'tabs', + 'activeTab', + 'clipboardWrite', ], - }; - if (import.meta.env.MANIFEST_VERSION != 2) { + } + if (import.meta.env.MANIFEST_VERSION !== 2) { manifest.web_accessible_resources = [ { - resources: ["sidebar.html", "images/robot.png", "options.html"], - matches: ["http://*/*", "https://*/*"], + resources: ['sidebar.html', 'images/robot.png', 'options.html'], + matches: ['http://*/*', 'https://*/*'], }, - ]; + ] } - return manifest; -}; + return manifest +} export default defineConfig({ - extensionApi: "webextension-polyfill", - srcDir: "src", + extensionApi: 'webextension-polyfill', + srcDir: 'src', manifest: generateManifest(), hooks: { - "build:manifestGenerated": (wxt, manifest) => { - const version = require("./package.json").version; - const [major, minor, patch, label = "0"] = version - .replace(/[^\d.-]+/g, "") - .split(/[.-]/); + 'build:manifestGenerated': (wxt, manifest) => { + const version = require('./package.json').version + const [major, minor, patch, label = '0'] = version + .replace(/[^\d.-]+/g, '') + .split(/[.-]/) manifest.name = - wxt.config.mode === "staging" - ? "[INTERNAL] Syncia" - : "Syncia - Power of ChatGPT on any website"; + wxt.config.mode === 'staging' + ? '[INTERNAL] Syncia' + : 'Syncia - Power of ChatGPT on any website' manifest.description = - "Syncia is a browser extension that allows you to use Open AI's GPT in any website."; - manifest.version = `${major}.${minor}.${patch}.${label}`; - manifest.version_name = version; + "Syncia is a browser extension that allows you to use Open AI's GPT in any website." + manifest.version = `${major}.${minor}.${patch}.${label}` + manifest.version_name = version }, }, -}); +})