Skip to content

Commit

Permalink
feat: inject
Browse files Browse the repository at this point in the history
  • Loading branch information
lybenson committed Jan 16, 2024
1 parent d031d52 commit 3f7053e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/content_script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ const head = document.head || document.documentElement
head.insertBefore(script, head.children[0])
head.removeChild(script)

interface RequestArguments {
readonly method: string
readonly params?: readonly unknown[] | object
}

chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.color) {
// console.log('Receive color = ' + msg.color)
Expand Down
19 changes: 19 additions & 0 deletions src/inject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
type EventName =
| 'connect'
| 'disconnect'
| 'chainChanged'
| 'accountsChanged'
| 'message'

interface RequestArguments {
readonly method: string
readonly params?: readonly unknown[] | object
}

window.easy = {
request: (args: RequestArguments) => {
console.log(args.method)
chrome.runtime.sendMessage(args)
},
on: (event: EventName, callback: Function) => {
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.event === event) {
callback(message)
}
})
}
}

0 comments on commit 3f7053e

Please sign in to comment.