barebones wikipedia sourcing

This commit is contained in:
2023-06-07 09:51:00 -06:00
parent 8fb91bef5f
commit 76285c1633
5 changed files with 57 additions and 1 deletions

View File

@@ -21,5 +21,19 @@
(catch [e] (sendResponse e))
(API.browser.downloads.show txtDownloadId)
(sendResponse "done")))))
((object type "downloadWikipedia" data [filename src fromUrl])
// awaitLet the DownloadItem and make an object url with the source info
(awaitLet [dlItemId (API.browser.downloads.download (object saveAs true url src))
dlItems (API.browser.downloads.search (object id dlItemId))]
(let [dlItem (first dlItems)
fileName dlItem.filename
txtFileName "$(Path.withoutDirectory (Path.withoutExtension fileName)).tsv"
txtContent "wikipedia.org\t\t${fromUrl}"
file (new File [txtContent] txtFileName)
txtUrl (URL.createObjectURL file)]
(awaitLet [txtDownloadId (API.browser.downloads.download (object url txtUrl filename txtFileName))]
(catch [e] (sendResponse e))
(API.browser.downloads.show txtDownloadId)
(sendResponse "done")))))
(never otherwise))
true)))

View File

@@ -0,0 +1,7 @@
package hollywoo_sourcer;
class WikipediaMain {
static function main() {
WikipediaMain_.main();
}
}

View File

@@ -0,0 +1,23 @@
(import kiss_firefox.API)
(import js.lib.Promise)
(importAs js.html.XMLHttpRequest XHR)
(import hollywoo_sourcer.Message)
(var :Dynamic document js.Lib.global.document)
(var :Dynamic window js.Lib.global.window)
(API.browser.runtime.onMessage.addListener
->[:Message message sender sendResponse]
(case message
((object type "requestSource")
(let [:String url window.location.href
parts (url.split ":")
filename (parts.pop)
imgTags (document.getElementsByTagName "img")]
(doFor idx (range imgTags.length)
(let [imgTag (imgTags.item idx)
src (imgTag.getAttribute "src")]
(when (StringTools.contains src filename)
(awaitLet [response (API.browser.runtime.sendMessage (object type "downloadWikipedia" data [filename "https:${src}" url]))]
(print response))
(break))))))
(otherwise)))