File size: 560 Bytes
54331d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.action === 'analyze') {
    try {
      var data = {
        status: 'ok',
        title: document.title,
      url: window.location.href,
      headings: document.querySelectorAll('h1,h2,h3').length,
      links: document.querySelectorAll('a[href]').length,
      images: document.querySelectorAll('img').length
      };
      sendResponse(data);
    } catch (e) {
      sendResponse({ status: 'error', message: e.message });
    }
  }
  return true;
});