You are browsing as a guest. Sign up (or log in) to start making projects!

2h 24m 47s logged

Devlog #1: Getting Started!

I have never made a Chrome Extension before, so I used a fair bit of AI to look up commands (I pieced it together myself though).

MultiCopy is going to be a Chrome Extension that you can use to copy and paste content with multiple shortcuts.
For example:

|--------| Copy -| Paste -| View -----|
|--------|-------|-------|------------|
| Slot 1 | Alt+Z | Alt+A | Ctrl+Alt+Z |
| Slot 2 | Alt+X | Alt+ S | Ctrl+Alt+X |
| Slot 3 | Alt+C | Alt + D | Ctrl+Alt+C |
etc.

Today, I managed to get the service worker successfully communicate with the injected script when I pressed the keyboard shortcut Alt+X. When the keyboard shortcut is pressed, the service worker communicates to the injected script by executing

const response = await chrome.tabs.sendMessage(tab.id, message)

and the injected script listens for it via

chrome.runtime.onMessage.addListener(() => {/*code*/})

So when the keyboard shortcut is pressed, the service worker sends an instruction to the injected script telling it to copy the current selected text. We do this with

const text = window.getSelection().toString()

This approach can’t copy images though, so I’ll have to make support for it later.

Then, we send a response back to the service worker:

sendResponse({ status:"success", text: [text] })

I haven’t added the storage logic yet, so now the service worker just logs the text to the console:

console.log(response.text)

Next I will add the copying logic, then I will add the pasting logic. The pasting logic will be a challenge because I have to find a way to paste it into the middle of text, but hopefully it will not be too much of a challenge.

0
17

Comments 0

No comments yet. Be the first!