wip refactoring
This commit is contained in:
@@ -3,11 +3,12 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
|
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
|
||||||
<!-- <script async defer src="https://cdn.jsdelivr.net/gh/altcha-org/altcha/dist/altcha.min.js" type="module"></script> -->
|
<!-- <script async defer src="https://cdn.jsdelivr.net/gh/altcha-org/altcha/dist/altcha.min.js" type="module"></script> -->
|
||||||
<script async src="/scripts/report-slop.js" type="module"></script>
|
<script async src="/scripts/action_popup.js" type="module"></script>
|
||||||
|
|
||||||
<title>Slop Farmer</title>
|
<title>Slop Farmer</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<h1>Log in to enable slop checking and reporting</h1>
|
||||||
<form id="login-form">
|
<form id="login-form">
|
||||||
<label for="email" id="username">username</label>
|
<label for="email" id="username">username</label>
|
||||||
<input type="text" name="username" required />
|
<input type="text" name="username" required />
|
||||||
@@ -16,4 +17,6 @@
|
|||||||
<button id="login-button">login</button>
|
<button id="login-button">login</button>
|
||||||
</form>
|
</form>
|
||||||
<h2 style="visibility: collapse;" id="login-status">You're logged in.</h2>
|
<h2 style="visibility: collapse;" id="login-status">You're logged in.</h2>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { API_URL } from "common"
|
import { API_URL, send_message_to_background } from "common"
|
||||||
|
|
||||||
const login_form = document.getElementById("login-form") as HTMLFormElement
|
const login_form = document.getElementById("login-form") as HTMLFormElement
|
||||||
const login_status = document.getElementById("login-status")
|
const login_status = document.getElementById("login-status")
|
||||||
@@ -22,8 +22,13 @@ async function submit_login_form() {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const body = await response.json()
|
const body = await response.json()
|
||||||
const token = body.access_token
|
const token = body.access_token
|
||||||
localStorage.setItem("accessToken", token)
|
|
||||||
|
await send_message_to_background({type: "login", token: token})
|
||||||
|
|
||||||
const status_el = document.getElementById("login-status")
|
const status_el = document.getElementById("login-status")
|
||||||
status_el.setAttribute("style", "visibility: visible;")
|
status_el.setAttribute("style", "visibility: visible;")
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
//bad login, update the form
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +1,6 @@
|
|||||||
export const API_URL: string = "https://api.slopfarmer.jack-case.pro"
|
export const API_URL: string = "https://api.slopfarmer.jack-case.pro"
|
||||||
|
|
||||||
|
export async function send_message_to_background(message: any): Promise<any> {
|
||||||
|
const response = await browser.runtime.sendMessage(message)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { send_message_to_background } from "common"
|
||||||
|
|
||||||
class SearchLink {
|
class SearchLink {
|
||||||
|
|
||||||
node: Element
|
node: Element
|
||||||
@@ -75,24 +77,26 @@ function check_links(search_links: SearchLink[]) {
|
|||||||
search_link.checked = true
|
search_link.checked = true
|
||||||
return search_link.target
|
return search_link.target
|
||||||
})
|
})
|
||||||
browser.runtime.sendMessage({type: "check", urls: urls})
|
|
||||||
|
send_message_to_background({type: "check", urls: urls})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function backend_message_listener(message: any) {
|
async function backend_message_listener(message: any) {
|
||||||
// handle slop reports returned from the background script
|
// handle slop reports returned from the background script
|
||||||
if(message.type === "check_result") {
|
switch(message.type) {
|
||||||
if (message.domain) {
|
case ("check-result"):
|
||||||
const paths = page_links.getDomain(message.domain)
|
if (message.domain) {
|
||||||
paths.forEach((search_link: SearchLink) => {
|
const paths = page_links.getDomain(message.domain)
|
||||||
search_link.node.setAttribute("style", "color: red;")
|
paths.forEach((search_link: SearchLink) => {
|
||||||
search_link.result = message.result
|
search_link.node.setAttribute("style", "color: red;")
|
||||||
})
|
search_link.result = message.result
|
||||||
} else if (message.url) {
|
})
|
||||||
const link = page_links.getUrl(message.url)
|
} else if (message.url) {
|
||||||
link.node.setAttribute("style", "color: red;")
|
const link = page_links.getUrl(message.url)
|
||||||
link.result = message.result
|
link.node.setAttribute("style", "color: red;")
|
||||||
}
|
link.result = message.result
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,13 @@ function setup_storage_db() {
|
|||||||
db_request.onsuccess = (event) => {
|
db_request.onsuccess = (event) => {
|
||||||
// create objectstore
|
// create objectstore
|
||||||
console.log(event)
|
console.log(event)
|
||||||
|
//@ts-ignore
|
||||||
db = event.target.result
|
db = event.target.result
|
||||||
}
|
}
|
||||||
|
|
||||||
db_request.onupgradeneeded = (event) => {
|
db_request.onupgradeneeded = (event) => {
|
||||||
console.log(event)
|
console.log(event)
|
||||||
|
//@ts-ignore
|
||||||
db = event.target.result
|
db = event.target.result
|
||||||
const slop_store = db.createObjectStore("slop", { keyPath: "domain" })
|
const slop_store = db.createObjectStore("slop", { keyPath: "domain" })
|
||||||
}
|
}
|
||||||
@@ -41,6 +43,7 @@ async function get_slop_store(readwrite: boolean) {
|
|||||||
const db_request = window.indexedDB.open("SlopDB", 1)
|
const db_request = window.indexedDB.open("SlopDB", 1)
|
||||||
|
|
||||||
db_request.onsuccess = (event) => {
|
db_request.onsuccess = (event) => {
|
||||||
|
//@ts-ignore
|
||||||
const db = event.target.result
|
const db = event.target.result
|
||||||
const transaction = db.transaction(["slop"], readwrite ? "readwrite" : undefined)
|
const transaction = db.transaction(["slop"], readwrite ? "readwrite" : undefined)
|
||||||
const slop_store = transaction.objectStore("slop")
|
const slop_store = transaction.objectStore("slop")
|
||||||
@@ -59,6 +62,7 @@ async function insert_slop(domain: string, path: string, report: boolean = true)
|
|||||||
const db_request = window.indexedDB.open("SlopDB", 1)
|
const db_request = window.indexedDB.open("SlopDB", 1)
|
||||||
|
|
||||||
db_request.onsuccess = (event) => {
|
db_request.onsuccess = (event) => {
|
||||||
|
//@ts-ignore
|
||||||
db = event.target.result
|
db = event.target.result
|
||||||
const transaction = db.transaction(["slop"], "readwrite")
|
const transaction = db.transaction(["slop"], "readwrite")
|
||||||
const slop_store = transaction.objectStore("slop")
|
const slop_store = transaction.objectStore("slop")
|
||||||
@@ -177,29 +181,37 @@ async function update_page_action_icon(details: browser.webNavigation._OnCommitt
|
|||||||
console.log(is_slop)
|
console.log(is_slop)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function message_listener(message: any, sender: any) {
|
async function message_listener(message: any, sender: any, send_response: Function) {
|
||||||
const tabid = sender.tab.id
|
const tabid = sender.tab.id
|
||||||
if (message.type === "check") {
|
switch (message.type) {
|
||||||
let check_promises = new Array()
|
|
||||||
let not_found_local = new Array()
|
|
||||||
|
|
||||||
message.urls.forEach((url: string) => {
|
case "check":
|
||||||
check_promises.push(check_local_slop(url).then(async (result) => {
|
let check_promises = new Array()
|
||||||
if (result.slop_domain) {
|
let not_found_local = new Array()
|
||||||
browser.tabs.sendMessage(tabid, { type: "check_result", url: url, result: result })
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
not_found_local.push(url)
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
await Promise.all(check_promises)
|
message.urls.forEach((url: string) => {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
let remote_slop = await check_remote_slop(not_found_local)
|
await Promise.all(check_promises)
|
||||||
remote_slop.forEach((result: any) => {
|
|
||||||
browser.tabs.sendMessage(tabid, { type: "check_result", domain: result.domain_name, result: result })
|
let remote_slop = await check_remote_slop(not_found_local)
|
||||||
})
|
remote_slop.forEach((result: any) => {
|
||||||
|
browser.tabs.sendMessage(tabid, { type: "check_result", domain: result.domain_name, result: result })
|
||||||
|
})
|
||||||
|
break
|
||||||
|
|
||||||
|
case "login":
|
||||||
|
localStorage.setItem("accessToken", message.token)
|
||||||
|
send_response(true)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user