Skip to content

Commit

Permalink
Fix linting issues and refactor code for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Royal-lobster committed Mar 11, 2025
1 parent 1428f10 commit 3b26091
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 74 deletions.
52 changes: 26 additions & 26 deletions src/entrypoints/quick-menu.content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ import type { Settings } from '../../config/settings'
import initQuickMenu from './initQuickMenu'

export default defineContentScript({
matches: ['http://*/*', 'https://*/*','<all_urls>'],
matches: ['http://*/*', 'https://*/*', '<all_urls>'],
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)
}
})
}
})
},
})
})
3 changes: 1 addition & 2 deletions src/entrypoints/quick-menu.content/initQuickMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -34,4 +33,4 @@ const initQuickMenu = () => {
)
}

export default initQuickMenu;
export default initQuickMenu
1 change: 0 additions & 1 deletion src/entrypoints/quick-menu.content/listenContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ import { generatePromptInSidebar } from '../../lib/generatePromptInSidebar'
*
* We listen to this message and generate the prompt in the sidebar.
*/

2 changes: 1 addition & 1 deletion src/entrypoints/sidebar_bg.content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function setupMessageListeners(iframe: HTMLIFrameElement) {
}

export default defineContentScript({
matches: ['http://*/*', 'https://*/*','<all_urls>'],
matches: ['http://*/*', 'https://*/*', '<all_urls>'],
main() {
contentScriptLog('Sidebar')
const iframe = createSidebar()
Expand Down
12 changes: 6 additions & 6 deletions src/logs.tsx
Original file line number Diff line number Diff line change
@@ -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'))
}
76 changes: 38 additions & 38 deletions wxt.config.ts
Original file line number Diff line number Diff line change
@@ -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
},
},
});
})

0 comments on commit 3b26091

Please sign in to comment.