-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserp_scripts.js
26 lines (22 loc) · 889 Bytes
/
serp_scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function renderHeadings(headings, container) {
headings.forEach(heading => {
const li = document.createElement('li');
li.textContent = `${heading.level === 2 ? 'H2: ' : 'H3: '}${heading.text}`;
if (heading.children.length > 0) {
const ul = document.createElement('ul');
renderHeadings(heading.children, ul);
li.appendChild(ul);
}
container.appendChild(li);
});
}
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'displayHeadings') {
const container = document.getElementById('headings-list');
container.innerHTML = ''; // Clear previous entries
renderHeadings(message.data, container);
}
});
document.addEventListener('DOMContentLoaded', () => {
chrome.runtime.sendMessage({ action: 'requestHeadings' });
});