beginning annotation with typescript
This commit is contained in:
6
.devcontainer/devcontainer.json
Normal file
6
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"image": "mcr.microsoft.com/devcontainers/universal:2",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers-community/npm-features/typescript:1": {}
|
||||
}
|
||||
}
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
scripts/
|
||||
@@ -1,5 +1,12 @@
|
||||
class SearchLink {
|
||||
constructor(link_node) {
|
||||
|
||||
node: Element
|
||||
target: string
|
||||
url: URL
|
||||
checked: boolean
|
||||
result: any
|
||||
|
||||
constructor(link_node: Element) {
|
||||
this.node = link_node
|
||||
this.target = link_node.getAttribute("href")
|
||||
this.url = new URL(link_node.getAttribute("href"))
|
||||
@@ -10,7 +17,7 @@ class SearchLink {
|
||||
|
||||
class ResultLinks extends Map {
|
||||
// map domains to paths and their associated nodes
|
||||
set(domain, path, search_link) {
|
||||
setLink(domain: string, path: string, search_link: SearchLink) {
|
||||
if(!super.get(domain)) {
|
||||
const nested_map = new Map()
|
||||
nested_map.set(path, search_link)
|
||||
@@ -20,27 +27,27 @@ class ResultLinks extends Map {
|
||||
}
|
||||
}
|
||||
|
||||
setNode(link_node) {
|
||||
setNode(link_node: Element) {
|
||||
const search_link = new SearchLink(link_node)
|
||||
this.set(search_link.url.hostname, search_link.url.pathname, search_link)
|
||||
this.setLink(search_link.url.hostname, search_link.url.pathname, search_link)
|
||||
}
|
||||
|
||||
get(domain, path="/") {
|
||||
get(domain: string, path: string = "/") {
|
||||
return super.get(domain).get(path)
|
||||
}
|
||||
|
||||
getDomain(domain) {
|
||||
getDomain(domain: string) {
|
||||
return super.get(domain)
|
||||
}
|
||||
|
||||
getUrl(url) {
|
||||
getUrl(url: string) {
|
||||
const urlobj = new URL(url)
|
||||
return this.get(urlobj.hostname, urlobj.pathname)
|
||||
}
|
||||
|
||||
getSearchLinks() {
|
||||
// return an iterator over the nested SearchLink objects
|
||||
const domain_value_iterator = super.values()
|
||||
const domain_value_iterator = super.values() as MapIterator<Map<string, SearchLink>>
|
||||
const search_link_iterator = domain_value_iterator.flatMap((domain_map) => {
|
||||
return domain_map.values()
|
||||
})
|
||||
@@ -52,12 +59,12 @@ class ResultLinks extends Map {
|
||||
const ddg_result_selector = "a[data-testid=\"result-title-a\""
|
||||
const ddg_result_list_selector = "ol.react-results--main"
|
||||
|
||||
let result_list_node
|
||||
let result_list_node: Element
|
||||
let result_list_observer
|
||||
const page_links = new ResultLinks()
|
||||
|
||||
|
||||
function check_links(search_links) {
|
||||
function check_links(search_links: SearchLink[]) {
|
||||
// send a message to background script with a list of URLs to check
|
||||
const urls = search_links.map((search_link) => {
|
||||
search_link.checked = true
|
||||
@@ -116,7 +123,7 @@ function setup_result_observer() {
|
||||
}
|
||||
|
||||
async function wait_for_results() {
|
||||
results = new Promise(async (resolve) => {
|
||||
let results = new Promise(async (resolve) => {
|
||||
let node = document.querySelector(ddg_result_list_selector)
|
||||
while (!node) {
|
||||
await new Promise((resolve) => {setTimeout(()=>{resolve()}, 100)})
|
||||
@@ -1,5 +1,5 @@
|
||||
const API_URL = "https://api.slopfarmer.jack-case.pro"
|
||||
let access_token
|
||||
const API_URL: string = "https://api.slopfarmer.jack-case.pro"
|
||||
let access_token: string
|
||||
|
||||
const login_form = document.getElementById("login-form")
|
||||
if(login_form) {
|
||||
@@ -44,9 +44,9 @@ function on_install_handler() {
|
||||
setup_storage_db()
|
||||
}
|
||||
|
||||
async function get_slop_store(readwrite) {
|
||||
async function get_slop_store(readwrite: boolean) {
|
||||
|
||||
const slop_store_promise = new Promise((resolve, reject) => {
|
||||
const slop_store_promise: Promise<IDBObjectStore> = new Promise((resolve, reject) => {
|
||||
const db_request = window.indexedDB.open("SlopDB", 1)
|
||||
|
||||
db_request.onsuccess = (event) => {
|
||||
@@ -63,7 +63,7 @@ async function get_slop_store(readwrite) {
|
||||
return await slop_store_promise
|
||||
}
|
||||
|
||||
async function insert_slop(domain, path) {
|
||||
async function insert_slop(domain: string, path: string) {
|
||||
let db
|
||||
const db_request = window.indexedDB.open("SlopDB", 1)
|
||||
|
||||
@@ -90,7 +90,7 @@ async function insert_slop(domain, path) {
|
||||
|
||||
// persist to indexeddb
|
||||
const store_request = slop_store.put(result)
|
||||
store_request.onsuccess = (event) => {
|
||||
store_request.onsuccess = () => {
|
||||
console.log(domain, path, "stored")
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ async function insert_slop(domain, path) {
|
||||
fetch(request)
|
||||
}
|
||||
|
||||
async function check_local_slop(url) {
|
||||
async function check_local_slop(url: string) {
|
||||
const slop_url = new URL(url)
|
||||
const slop_store = await get_slop_store(false)
|
||||
const known_slop = new Promise((resolve, reject) => {
|
||||
@@ -136,16 +136,16 @@ async function check_local_slop(url) {
|
||||
return result
|
||||
}
|
||||
|
||||
async function check_remote_slop(urls) {
|
||||
async function check_remote_slop(urls: string[]) {
|
||||
const check_url = new URL("/check", API_URL)
|
||||
const request = new Request(check_url, {method: "POST", headers: { "Content-Type": "application/json", "Bearer": get_access_token() }, body: JSON.stringify({slop_urls: urls})})
|
||||
const response = await fetch(request)
|
||||
let domain_objects = await response.json()
|
||||
domain_objects.forEach((domain) => {insert_slop(domain.domain_name, "/")})
|
||||
domain_objects.forEach((domain: any) => {insert_slop(domain.domain_name, "/")})
|
||||
return domain_objects
|
||||
}
|
||||
|
||||
async function on_button_clicked_handler(tab) {
|
||||
async function on_button_clicked_handler(tab: Tab) {
|
||||
// insert the current tab's page into slop storage
|
||||
const tab_url = new URL(tab.url)
|
||||
|
||||
8
tsconfig.json
Normal file
8
tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"include": ["src/**/*"],
|
||||
"compilerOptions": {
|
||||
"outDir": "scripts",
|
||||
"noImplicitAny": true,
|
||||
"lib": ["ES2020", "DOM"]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user