Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Royal-lobster committed Nov 26, 2023
1 parent 4acc746 commit 802219e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 7 additions & 1 deletion manifest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ export default defineManifest(async (env) => ({
'48': 'images/icon-48.png',
'128': 'images/icon-128.png',
},
permissions: ['storage', 'unlimitedStorage', 'contextMenus', 'tabs', "activeTab"],
permissions: [
'storage',
'unlimitedStorage',
'contextMenus',
'tabs',
'activeTab',
],
background: {
service_worker: 'src/pages/background/index.ts',
},
Expand Down
12 changes: 7 additions & 5 deletions src/lib/getScreenshotImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const getScreenshotImage = async (): Promise<Blob> => {
document.body.removeChild(snipeRegion)
document.body.removeChild(snipeSelection)
await new Promise((resolve) => setTimeout(resolve, 100)) // Wait for the DOM to update

// Ensure that the coordinates are defined before using them
if (
typeof startX === 'undefined' ||
Expand All @@ -90,9 +90,9 @@ export const getScreenshotImage = async (): Promise<Blob> => {
const screenshot = await new Promise<string>((resolve) => {
chrome.runtime.sendMessage({ action: 'captureVisibleTab' }, (dataUrl) => {
console.log({ dataUrl })
resolve(dataUrl);
});
});
resolve(dataUrl)
})
})

// Create a canvas element and draw the screenshot on it
const canvas: HTMLCanvasElement = document.createElement('canvas')
Expand All @@ -103,7 +103,9 @@ export const getScreenshotImage = async (): Promise<Blob> => {
image.src = screenshot

// Wait for the image to load
await new Promise((resolve) => {image.onload = resolve})
await new Promise((resolve) => {
image.onload = resolve
})

// Crop the screenshot to the user's selection
ctx.drawImage(
Expand Down
12 changes: 6 additions & 6 deletions src/pages/background/sidebar/captureScreenListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
export const captureScreenListener = async () => {
chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
if (request.action === "captureVisibleTab") {
if (request.action === 'captureVisibleTab') {
chrome.tabs.captureVisibleTab((dataUrl) => {
sendResponse(dataUrl);
});
return true; // This will keep the message channel open until `sendResponse` is called.
sendResponse(dataUrl)
})
return true // This will keep the message channel open until `sendResponse` is called.
}
});
};
})
}
2 changes: 1 addition & 1 deletion src/pages/background/sidebar/sidebarToggleListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const sidebarToggleListeners = () => {
if (message.action === 'generate') {
message.prompt
}
if(message.action === 'close-sidebar'){
if (message.action === 'close-sidebar') {
sendResponse({ action: 'close-sidebar' })
}
})
Expand Down

0 comments on commit 802219e

Please sign in to comment.