plugging away at API access for checking

This commit is contained in:
Jack Case
2025-10-20 16:44:37 +00:00
parent fc8d0218c7
commit 8f9cb2c20a

View File

@@ -84,7 +84,7 @@ function insert_slop(domain, path) {
} }
} }
async function check_slop(url) { async function check_local_slop(url) {
const slop_url = new URL(url) const slop_url = new URL(url)
const slop_store = await get_slop_store(false) const slop_store = await get_slop_store(false)
const known_slop = new Promise((resolve, reject) => { const known_slop = new Promise((resolve, reject) => {
@@ -111,6 +111,12 @@ async function check_slop(url) {
return result return result
} }
async function check_remote_slop(urls) {
const check_url = new URL("check", API_URL)
const request = new Request(check_url, {method: "POST", body: JSON.stringify({slop_urls: urls})})
const response = await fetch(request)
}
async function on_button_clicked_handler(tab) { async function on_button_clicked_handler(tab) {
// insert the current tab's page into slop storage // insert the current tab's page into slop storage
const tab_url = new URL(tab.url) const tab_url = new URL(tab.url)
@@ -125,7 +131,7 @@ async function update_page_action_icon(details) {
if(details.frameId != 0) { if(details.frameId != 0) {
return return
} }
const is_slop = await check_slop(details.url) const is_slop = await check_local_slop(details.url)
if(is_slop.slop_path) { if(is_slop.slop_path) {
browser.pageAction.setIcon({ browser.pageAction.setIcon({
path: "icons/virus_red.png", path: "icons/virus_red.png",
@@ -147,14 +153,27 @@ async function update_page_action_icon(details) {
console.log(is_slop) console.log(is_slop)
} }
async function message_listener(message) { async function message_listener(message, sender) {
const tabid = sender.tab.id
if (message.type === "check") { if (message.type === "check") {
let check_promises = new Array() let check_promises = new Array()
message.urls.foreach((url) => { let not_found_local = new Array()
check_promises.push(check_slop(url).then((result) => {
browser.tabs.sendMessage({type: "check_result", url: url, result: result}) message.urls.forEach((url) => {
check_promises.push(check_local_slop(url).then(async (result) => {
if (result.slop_domain) {
browser.tabs.sendMessage(tabid, { type: "check_result", url: url, result: result })
}
else {
not_found_local.push(url)
}
})) }))
}) })
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 })
})
} }
} }