Open fastaddons opened 3 years ago
There is another way. We can monitor selectionchange event: https://developer.mozilla.org/en-US/docs/Web/API/Document/selectionchange_event Then check active rules and apply them on the text to see if there is a match. If yes, update context menu. However I would have to revert the context menu:
Another solution would be NOT using context menu and instead show custom controls (somehow). For example, since all highlights are custom nodes, we could detect click and show small arrow next to it with custom context menu.
It would be nice if you could right click on the highlighted text and from the context menu choose option to delete this highlight. It would be easier than opening the popup.
Implementation: Well, this may be hard. There is some API for identifying clicked node in Firefox: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/onShown https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/onClicked https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/OnClickData
But it's missing in Chrome: https://stackoverflow.com/questions/7972455/chrome-extension-context-menu-onclickdata https://bugs.chromium.org/p/chromium/issues/detail?id=39507