report slop to server and check ddg search results
This commit is contained in:
@@ -8,6 +8,7 @@ const page_links = new Map()
|
|||||||
function check_links(links) {
|
function check_links(links) {
|
||||||
// send a message to background script with a list of URLs to check
|
// send a message to background script with a list of URLs to check
|
||||||
browser.runtime.sendMessage({type: "check", urls: links})
|
browser.runtime.sendMessage({type: "check", urls: links})
|
||||||
|
links.forEach((link) => {page_links.set(link, {checked: true})})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function message_listener(message) {
|
async function message_listener(message) {
|
||||||
@@ -23,12 +24,24 @@ function get_initial_links() {
|
|||||||
links.forEach((node) => {
|
links.forEach((node) => {
|
||||||
page_links.set(node.getAttribute("href"), undefined)
|
page_links.set(node.getAttribute("href"), undefined)
|
||||||
})
|
})
|
||||||
|
const link_targets = page_links.keys().toArray()
|
||||||
console.log(link_targets)
|
console.log(link_targets)
|
||||||
check_links(page_links.keys())
|
check_links(link_targets)
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_links() {
|
function update_links() {
|
||||||
// the result list has updated, add new links and check them
|
// 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() {
|
function setup_result_observer() {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ async function get_slop_store(readwrite) {
|
|||||||
return await slop_store_promise
|
return await slop_store_promise
|
||||||
}
|
}
|
||||||
|
|
||||||
function insert_slop(domain, path) {
|
async function insert_slop(domain, path) {
|
||||||
let db
|
let db
|
||||||
const db_request = window.indexedDB.open("SlopDB", 1)
|
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) {
|
async function check_local_slop(url) {
|
||||||
@@ -175,7 +179,7 @@ async function message_listener(message, sender) {
|
|||||||
|
|
||||||
await Promise.all(check_promises)
|
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) => {
|
remote_slop.forEach((result) => {
|
||||||
browser.tabs.sendMessage(tabid, { type: "check_result", url: result.url, result: result })
|
browser.tabs.sendMessage(tabid, { type: "check_result", url: result.url, result: result })
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user