Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged] Feature/firefox #83

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For general introductions, see https://Maskbook.com/
#### Non-famous libraries we are using

- `@holoflows/kit` - A toolkit for extension developing
- `anchrome` - Use it to detect links in the text
- `anchorme` - Use it to detect links in the text
- `construct-style-sheets-polyfill` - A polyfill for a web api
- `elliptic` - A crypto library, we use it to encrypt and decrypt
- `gun` - A decentralized graph databasem we use it to sync user's shared crypto key
Expand Down
10 changes: 5 additions & 5 deletions src/extension/injected-script/addEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export interface CustomEvents {

const hacks: { [key in keyof CustomEvents & keyof DocumentEventMap]: (...params: CustomEvents[key]) => Event } = {
paste(text) {
const transfer = new DataTransfer()
transfer.setData('text/plain', text)
const e = new ClipboardEvent('paste', { clipboardData: transfer })
const e = new ClipboardEvent('paste', { clipboardData: new DataTransfer() })
e.clipboardData!.setData('text/plain', text)
// ! Why?
return getEvent(e, { defaultPrevented: false, preventDefault() {} })
},
Expand All @@ -46,8 +45,9 @@ export interface CustomEvents {
}
;(Object.keys(hacks) as (keyof DocumentEventMap)[]).concat(['keyup', 'input']).forEach(hijack)
const invokeCustomEvent: EventListenerOrEventListenerObject = e => {
const ev = e as CustomEvent<[keyof CustomEvents, CustomEvents[keyof CustomEvents]]>
const [eventName, param] = ev.detail
const ev = e as CustomEvent<string>
const [eventName, param]: [keyof CustomEvents, CustomEvents[keyof CustomEvents]] = JSON.parse(ev.detail)

for (const f of store[eventName] || []) {
try {
const hack = hacks[eventName]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function getUrl(path: string, fallback: string = '') {
* @param x parameters
*/
export function dispatchCustomEvents<T extends keyof CustomEvents>(event: T, ...x: CustomEvents[T]) {
document.dispatchEvent(new CustomEvent(CustomEventId, { detail: [event, x] }))
document.dispatchEvent(new CustomEvent(CustomEventId, { detail: JSON.stringify([event, x]) }))
}
Object.assign(window, { dispatchCustomEvents })
/**
Expand Down