From d730c46d8bba74f417cffc5f259ebdc4f051f837 Mon Sep 17 00:00:00 2001 From: Jack Case Date: Wed, 22 Oct 2025 14:20:11 +0000 Subject: [PATCH] add some helpful comments --- scripts/hide-slop.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/hide-slop.js b/scripts/hide-slop.js index 864231b..7bf99fb 100644 --- a/scripts/hide-slop.js +++ b/scripts/hide-slop.js @@ -21,6 +21,7 @@ function check_links(links) { } async function message_listener(message) { + // handle slop reports returned from the background script if(message.type === "check_result") { console.log(message.url, message.result) page_links.get(message.url).result = message.result @@ -28,7 +29,7 @@ async function message_listener(message) { } function get_initial_links() { - //get links + // get links from initial page load const links = document.querySelectorAll(ddg_result_selector) links.forEach((node) => { const link = new SearchLink(node) @@ -54,21 +55,24 @@ function update_links() { } function setup_result_observer() { + // observe changes in the result list to respond to newly loaded results const config = { childList: true } result_list_observer = new MutationObserver(update_links) result_list_observer.observe(result_list_node, config) } function onload_handler() { - // get results ol node + // get results ol node to observe result_list_node = document.querySelector(ddg_result_list_selector) get_initial_links() setup_result_observer() } +// listen for messages from the background script browser.runtime.onMessage.addListener(message_listener) +// initialize state on document load if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", onload_handler) } else {