Margin is an open annotation layer for the internet. Powered by the AT Protocol. margin.at
extension web atproto comments
at main 37 lines 875 B view raw
1import { initContentScript } from '@/utils/overlay'; 2 3export default defineUnlistedScript(async () => { 4 await waitForPdfTextLayer(); 5 6 await initContentScript({ 7 onInvalidated: (cb: () => void) => { 8 window.addEventListener('beforeunload', cb); 9 }, 10 }); 11}); 12 13function waitForPdfTextLayer(): Promise<void> { 14 return new Promise((resolve) => { 15 if (document.querySelectorAll('.textLayer span').length > 0) { 16 resolve(); 17 return; 18 } 19 20 const observer = new MutationObserver(() => { 21 if (document.querySelectorAll('.textLayer span').length > 0) { 22 observer.disconnect(); 23 setTimeout(resolve, 500); 24 } 25 }); 26 27 observer.observe(document.body || document.documentElement, { 28 childList: true, 29 subtree: true, 30 }); 31 32 setTimeout(() => { 33 observer.disconnect(); 34 resolve(); 35 }, 10000); 36 }); 37}