background page will automatically do an altcha challenge to get an access token

This commit is contained in:
Jack Case
2025-10-22 14:57:00 +00:00
parent c449c18a21
commit 0a62f61068
3 changed files with 24 additions and 3 deletions

View File

@@ -25,9 +25,7 @@
}, },
"background": { "background": {
"scripts": ["scripts/report-slop.js"], "page": "pages/background_page.html"
"persistent": false,
"type": "module"
}, },
"content_scripts": [ "content_scripts": [

View File

@@ -0,0 +1,13 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
<script async src="scripts/report-slop.js" type="module"></script>
<script async defer src="https://cdn.jsdelivr.net/gh/altcha-org/altcha/dist/altcha.min.js" type="module"></script>
<title>Slop Farmer</title>
</head>
<body>
<form action="" method="post">
<altcha-widget challengeurl="SERVER_URL/challenge" auto="onload"></altcha-widget>
</form>
</body>

View File

@@ -1,4 +1,5 @@
const API_URL = "http://localhost:8000" const API_URL = "http://localhost:8000"
let access_token
function setup_storage_db() { function setup_storage_db() {
/* create indexeddb object store to retain objects in the form of /* create indexeddb object store to retain objects in the form of
@@ -186,7 +187,16 @@ async function message_listener(message, sender) {
} }
} }
function get_access_token() {
access_token = localStorage.getItem("accessToken")
if (!access_token) {
// get an access token from the API
}
return access_token
}
browser.runtime.onInstalled.addListener(on_install_handler) browser.runtime.onInstalled.addListener(on_install_handler)
browser.runtime.onStartup.addListener(get_access_token)
browser.pageAction.onClicked.addListener(on_button_clicked_handler) browser.pageAction.onClicked.addListener(on_button_clicked_handler)
browser.webNavigation.onCommitted.addListener(update_page_action_icon) browser.webNavigation.onCommitted.addListener(update_page_action_icon)
browser.runtime.onMessage.addListener(message_listener) browser.runtime.onMessage.addListener(message_listener)