working on imports, maybe not worth it for the content script, it can't be an es module

This commit is contained in:
Jack Case
2025-11-06 01:38:17 +00:00
parent 83bc5190a7
commit 8cc0f3aa64
6 changed files with 25 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
import { API_URL, send_message_to_background } from "common"
import { API_URL, send_message_to_background } from "./common.js"
const login_form = document.getElementById("login-form") as HTMLFormElement
const login_status = document.getElementById("login-status")

View File

@@ -1,4 +1,4 @@
import { send_message_to_background } from "common"
let common: any
class SearchLink {
@@ -78,7 +78,7 @@ function check_links(search_links: SearchLink[]) {
return search_link.target
})
send_message_to_background({type: "check", urls: urls})
common.send_message_to_background({type: "check", urls: urls})
}
async function backend_message_listener(message: any) {
@@ -156,12 +156,17 @@ async function onload_handler() {
setup_result_observer()
}
// listen for messages from the background script
browser.runtime.onMessage.addListener(backend_message_listener)
import("./common.js").then((module) => {
common = module
// listen for messages from the background script
browser.runtime.onMessage.addListener(backend_message_listener)
// initialize state on document load
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", onload_handler)
} else {
wait_for_results().then(onload_handler)
}
})
// initialize state on document load
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", onload_handler)
} else {
wait_for_results().then(onload_handler)
}

View File

@@ -1,4 +1,4 @@
import { API_URL } from "common"
import { API_URL } from "./common.js"
let access_token: string
function setup_storage_db() {
@@ -182,10 +182,10 @@ async function update_page_action_icon(details: browser.webNavigation._OnCommitt
}
async function message_listener(message: any, sender: any, send_response: Function) {
const tabid = sender.tab.id
switch (message.type) {
case "check":
const tabid = sender.tab.id
let check_promises = new Array()
let not_found_local = new Array()
@@ -226,6 +226,5 @@ function get_access_token() {
browser.runtime.onInstalled.addListener(on_install_handler)
browser.runtime.onStartup.addListener(get_access_token)
browser.pageAction.onClicked.addListener(on_button_clicked_handler)
browser.webNavigation.onCommitted.addListener(update_page_action_icon)
browser.runtime.onMessage.addListener(message_listener)