我正在使用这个样板代码https://github.com/Jonghakseo/chrome-extension-boilerplate-react-vite。 用例是,如果用户单击与 Web 扩展关联的上下文菜单,它应该在当前网页上打开一个 JSX 模式。
背景.ts
import reloadOnUpdate from 'virtual:reload-on-update-in-background-script';
import 'webextension-polyfill';
reloadOnUpdate('pages/background');
/**
* Extension reloading is necessary because the browser automatically caches the css.
* If you do not use the css of the content script, please delete it.
*/
reloadOnUpdate('pages/content/style.scss');
chrome.runtime.onInstalled.addListener(() => {
console.log('onInstalled....');
chrome.contextMenus.create({
id: 'typelessPopup',
title: 'Add to typless',
contexts: ['selection'],
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
chrome.storage.local.set({ selectedText: info.selectionText });
});
});
console.log('background loaded', chrome);
根据样板代码我必须进行哪些代码更改?
要在当前页面上显示自定义模式作为对上下文菜单单击的反应,您需要
createRoot
函数来实现,在那里渲染你的模态并将根附加到页面。