Write on the margins of 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; citedUrls?: string[]; cacheBust?: boolean }): Annotation[];
15 activateOnPdf(data: { tabId: number; url: string }): { redirected: boolean };
16 createAnnotation(data: {
17 url: string;
18 text: string;
19 title?: string;
20 selector?: TextSelector;
21 tags?: string[];
22 }): {
23 success: boolean;
24 data?: Annotation;
25 error?: string;
26 };
27
28 createBookmark(data: { url: string; title?: string; tags?: string[] }): {
29 success: boolean;
30 data?: Bookmark;
31 error?: string;
32 };
33 getUserBookmarks(data: { did: string }): Bookmark[];
34
35 createHighlight(data: {
36 url: string;
37 title?: string;
38 selector: TextSelector;
39 color?: string;
40 tags?: string[];
41 }): {
42 success: boolean;
43 data?: Highlight;
44 error?: string;
45 };
46 getUserHighlights(data: { did: string }): Highlight[];
47
48 getUserCollections(data: { did: string }): Collection[];
49 addToCollection(data: { collectionUri: string; annotationUri: string }): {
50 success: boolean;
51 error?: string;
52 };
53 getItemCollections(data: { annotationUri: string }): string[];
54
55 deleteHighlight(data: { uri: string }): { success: boolean; error?: string };
56 convertHighlightToAnnotation(data: {
57 highlightUri: string;
58 url: string;
59 text: string;
60 title?: string;
61 selector?: TextSelector;
62 }): { success: boolean; error?: string };
63
64 getReplies(data: { uri: string }): Annotation[];
65 createReply(data: {
66 parentUri: string;
67 parentCid: string;
68 rootUri: string;
69 rootCid: string;
70 text: string;
71 }): { success: boolean; error?: string };
72
73 getOverlayEnabled(): boolean;
74
75 getUserTags(data: { did: string }): string[];
76 getTrendingTags(): string[];
77
78 openAppUrl(data: { path: string }): void;
79
80 updateBadge(data: { count: number; tabId?: number }): void;
81
82 cacheAnnotations(data: { url: string; annotations: Annotation[] }): void;
83 getCachedAnnotations(data: { url: string }): Annotation[] | null;
84}
85
86export const { sendMessage, onMessage } = defineExtensionMessaging<ProtocolMap>();