get rid of page action, start working on browser action popup
This commit is contained in:
@@ -13,12 +13,6 @@
|
|||||||
"*://*.duckduckgo.com/*"
|
"*://*.duckduckgo.com/*"
|
||||||
],
|
],
|
||||||
|
|
||||||
"page_action": {
|
|
||||||
"default_icon": "icons/virus-slash.png",
|
|
||||||
"default_title": "report slop",
|
|
||||||
"show_matches": ["<all_urls>"]
|
|
||||||
},
|
|
||||||
|
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_icon": "icons/virus-slash.png",
|
"default_icon": "icons/virus-slash.png",
|
||||||
"default_title": "Slop Farmer",
|
"default_title": "Slop Farmer",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/firefox-webext-browser": "^143.0.0"
|
"@types/firefox-webext-browser": "^143.0.0",
|
||||||
|
"typescript": "^5.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form id="login-form">
|
<form id="login-form">
|
||||||
<label for="email" id="username">user:</label>
|
<label for="email" id="username">username</label>
|
||||||
<input type="text" name="username" required />
|
<input type="text" name="username" required />
|
||||||
<label for="password" id="password">password:</label>
|
<label for="password" id="password">password</label>
|
||||||
<input type="password" name="password" required />
|
<input type="password" name="password" required />
|
||||||
<button id="login-button">login</button>
|
<button id="login-button">login</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
29
src/browser-action.ts
Normal file
29
src/browser-action.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { API_URL } from "common"
|
||||||
|
|
||||||
|
const login_form = document.getElementById("login-form") as HTMLFormElement
|
||||||
|
const login_status = document.getElementById("login-status")
|
||||||
|
if (localStorage.getItem("accessToken")) {
|
||||||
|
login_status.setAttribute("style", "visibility: visible;")
|
||||||
|
}
|
||||||
|
login_form.addEventListener("submit", (event) => { event.preventDefault(); submit_login_form() })
|
||||||
|
|
||||||
|
async function submit_login_form() {
|
||||||
|
|
||||||
|
const login_url = new URL("/login", API_URL)
|
||||||
|
|
||||||
|
const request = new Request(login_url,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
body: new FormData(login_form)
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await fetch(request)
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const body = await response.json()
|
||||||
|
const token = body.access_token
|
||||||
|
localStorage.setItem("accessToken", token)
|
||||||
|
const status_el = document.getElementById("login-status")
|
||||||
|
status_el.setAttribute("style", "visibility: visible;")
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/common.ts
Normal file
1
src/common.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const API_URL: string = "https://api.slopfarmer.jack-case.pro"
|
||||||
@@ -1,15 +1,6 @@
|
|||||||
const API_URL: string = "https://api.slopfarmer.jack-case.pro"
|
import { API_URL } from "common"
|
||||||
let access_token: string
|
let access_token: string
|
||||||
|
|
||||||
const login_form = document.getElementById("login-form") as HTMLFormElement
|
|
||||||
if(login_form) {
|
|
||||||
const login_status = document.getElementById("login-status")
|
|
||||||
if (localStorage.getItem("accessToken")) {
|
|
||||||
login_status.setAttribute("style", "visibility: visible;")
|
|
||||||
}
|
|
||||||
login_form.addEventListener("submit", (event) => {event.preventDefault(); submit_login_form()})
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
* {"domain": "domain.tld",
|
* {"domain": "domain.tld",
|
||||||
@@ -220,32 +211,9 @@ function get_access_token() {
|
|||||||
return access_token
|
return access_token
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit_login_form() {
|
|
||||||
|
|
||||||
const login_url = new URL("/login", API_URL)
|
|
||||||
|
|
||||||
const request = new Request(login_url,
|
|
||||||
{
|
|
||||||
method: "POST",
|
|
||||||
body: new FormData(login_form)
|
|
||||||
})
|
|
||||||
|
|
||||||
const response = await fetch(request)
|
|
||||||
|
|
||||||
if(response.ok) {
|
|
||||||
const body = await response.json()
|
|
||||||
const token = body.access_token
|
|
||||||
localStorage.setItem("accessToken", token)
|
|
||||||
const status_el = document.getElementById("login-status")
|
|
||||||
status_el.setAttribute("style", "visibility: visible;")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!login_form) {
|
|
||||||
browser.runtime.onInstalled.addListener(on_install_handler)
|
browser.runtime.onInstalled.addListener(on_install_handler)
|
||||||
browser.runtime.onStartup.addListener(get_access_token)
|
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)
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"lib": ["ES7", "DOM"],
|
"lib": ["ES7", "DOM"],
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"target": "esnext"
|
"target": "esnext",
|
||||||
|
"baseUrl": "src/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,3 +6,8 @@
|
|||||||
version "143.0.0"
|
version "143.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/firefox-webext-browser/-/firefox-webext-browser-143.0.0.tgz#29413c9f393d4c4b5622d4a74182ff0219e98620"
|
resolved "https://registry.yarnpkg.com/@types/firefox-webext-browser/-/firefox-webext-browser-143.0.0.tgz#29413c9f393d4c4b5622d4a74182ff0219e98620"
|
||||||
integrity sha512-865dYKMOP0CllFyHmgXV4IQgVL51OSQQCwSoihQ17EwugePKFSAZRc0EI+y7Ly4q7j5KyURlA7LgRpFieO4JOw==
|
integrity sha512-865dYKMOP0CllFyHmgXV4IQgVL51OSQQCwSoihQ17EwugePKFSAZRc0EI+y7Ly4q7j5KyURlA7LgRpFieO4JOw==
|
||||||
|
|
||||||
|
typescript@^5.9.3:
|
||||||
|
version "5.9.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.9.3.tgz#5b4f59e15310ab17a216f5d6cf53ee476ede670f"
|
||||||
|
integrity sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==
|
||||||
|
|||||||
Reference in New Issue
Block a user