Margin is an open annotation layer for the internet. Powered by the AT Protocol.
margin.at
extension
web
atproto
comments
1import { defineExtensionMessaging } from '@webext-core/messaging';
2import type {
3 MarginSession,
4 Annotation,
5 Bookmark,
6 Highlight,
7 Collection,
8 TextSelector,
9} from './types';
10
11interface ProtocolMap {
12 checkSession(): MarginSession;
13
14 getAnnotations(data: { url: string }): Annotation[];
15 createAnnotation(data: { url: string; text: string; title?: string; selector?: TextSelector }): {
16 success: boolean;
17 data?: Annotation;
18 error?: string;
19 };
20
21 createBookmark(data: { url: string; title?: string }): {
22 success: boolean;
23 data?: Bookmark;
24 error?: string;
25 };
26 getUserBookmarks(data: { did: string }): Bookmark[];
27
28 createHighlight(data: { url: string; title?: string; selector: TextSelector; color?: string }): {
29 success: boolean;
30 data?: Highlight;
31 error?: string;
32 };
33 getUserHighlights(data: { did: string }): Highlight[];
34
35 getUserCollections(data: { did: string }): Collection[];
36 addToCollection(data: { collectionUri: string; annotationUri: string }): {
37 success: boolean;
38 error?: string;
39 };
40 getItemCollections(data: { annotationUri: string }): string[];
41
42 getReplies(data: { uri: string }): Annotation[];
43 createReply(data: {
44 parentUri: string;
45 parentCid: string;
46 rootUri: string;
47 rootCid: string;
48 text: string;
49 }): { success: boolean; error?: string };
50
51 getOverlayEnabled(): boolean;
52
53 openAppUrl(data: { path: string }): void;
54
55 updateBadge(data: { count: number; tabId?: number }): void;
56
57 cacheAnnotations(data: { url: string; annotations: Annotation[] }): void;
58 getCachedAnnotations(data: { url: string }): Annotation[] | null;
59}
60
61export const { sendMessage, onMessage } = defineExtensionMessaging<ProtocolMap>();