Browser extension that demonstrates the Web Annotation Discovery mechanism: subscribe to people’s annotation collections/‘feeds’, to see their notes on the web; and create & publish annotations yourself.

context-menu.ts 835 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { RpcClient } from 'webextension-rpc';
  2. import { contentScriptRpcServer } from '../content_script';
  3. async function handleAnnotateSelection(
  4. info: browser.contextMenus.OnClickData,
  5. tab: browser.tabs.Tab,
  6. ) {
  7. await new RpcClient<typeof contentScriptRpcServer>({ tabId: tab.id }).func(
  8. 'annotateSelection',
  9. )();
  10. }
  11. function onContextMenuClick(
  12. info: browser.contextMenus.OnClickData,
  13. tab?: browser.tabs.Tab,
  14. ) {
  15. if (!tab) return;
  16. switch (info.menuItemId) {
  17. case 'annotate-selection':
  18. handleAnnotateSelection(info, tab);
  19. break;
  20. }
  21. }
  22. async function init() {
  23. // Create context menu item
  24. browser.contextMenus.create({
  25. id: 'annotate-selection',
  26. title: 'Annotate selection',
  27. contexts: ['selection'],
  28. });
  29. browser.contextMenus.onClicked.addListener(onContextMenuClick);
  30. }
  31. init();