chore: add clipper extension package (#2281)

This commit is contained in:
Aman Harwara
2023-04-11 22:14:02 +05:30
committed by GitHub
parent 0b0466c9fa
commit 4f5e634685
214 changed files with 3163 additions and 355 deletions

View File

@@ -0,0 +1,32 @@
import { runtime, action, browserAction, windows, storage } from 'webextension-polyfill'
import { RuntimeMessage, RuntimeMessageTypes } from '../types/message'
const isFirefox = navigator.userAgent.indexOf('Firefox/') !== -1
const openPopupAndClipSelection = async (payload: { title: string; content: string }) => {
await storage.local.set({ clip: payload })
if (isFirefox) {
const popupURL = await browserAction.getPopup({})
await windows.create({
type: 'detached_panel',
url: popupURL,
width: 350,
height: 450,
})
return
}
const openPopup = runtime.getManifest().manifest_version === 3 ? action.openPopup : browserAction.openPopup
void openPopup()
}
runtime.onMessage.addListener((message: RuntimeMessage) => {
if (message.type === RuntimeMessageTypes.OpenPopupWithSelection) {
if (!message.payload) {
return
}
void openPopupAndClipSelection(message.payload)
}
})