From 8cea8a778573622b8dca9e76f4e091233cc89e53 Mon Sep 17 00:00:00 2001 From: Jack Case Date: Tue, 21 Oct 2025 19:45:11 -0400 Subject: [PATCH] report slop to server and check ddg search results --- scripts/hide-slop.js | 15 ++++++++++++++- scripts/report-slop.js | 8 ++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/hide-slop.js b/scripts/hide-slop.js index ea59153..b6a8314 100644 --- a/scripts/hide-slop.js +++ b/scripts/hide-slop.js @@ -8,6 +8,7 @@ const page_links = new Map() function check_links(links) { // send a message to background script with a list of URLs to check browser.runtime.sendMessage({type: "check", urls: links}) + links.forEach((link) => {page_links.set(link, {checked: true})}) } async function message_listener(message) { @@ -23,12 +24,24 @@ function get_initial_links() { links.forEach((node) => { page_links.set(node.getAttribute("href"), undefined) }) + const link_targets = page_links.keys().toArray() console.log(link_targets) - check_links(page_links.keys()) + check_links(link_targets) } function update_links() { // the result list has updated, add new links and check them + const links = document.querySelectorAll(ddg_result_selector) + links.forEach((node) => { + let url = node.getAttribute("href") + if (page_links.has(url)) return + page_links.set(url, undefined) + }) + const link_arr = page_links.keys().filter((key) => { + return !(page_links.get(key)) + }).toArray() + + check_links(link_arr) } function setup_result_observer() { diff --git a/scripts/report-slop.js b/scripts/report-slop.js index 59c4601..9e8329d 100644 --- a/scripts/report-slop.js +++ b/scripts/report-slop.js @@ -50,7 +50,7 @@ async function get_slop_store(readwrite) { return await slop_store_promise } -function insert_slop(domain, path) { +async function insert_slop(domain, path) { let db const db_request = window.indexedDB.open("SlopDB", 1) @@ -82,6 +82,10 @@ function insert_slop(domain, path) { } } } + + const report_url = new URL("/report", API_URL) + const request = new Request(report_url, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({slop_urls: [new URL(path, "http://"+domain).toString()]})}) + fetch(request) } async function check_local_slop(url) { @@ -175,7 +179,7 @@ async function message_listener(message, sender) { await Promise.all(check_promises) - remote_slop = await check_remote_slop(not_found_local) + let remote_slop = await check_remote_slop(not_found_local) remote_slop.forEach((result) => { browser.tabs.sendMessage(tabid, { type: "check_result", url: result.url, result: result }) })