barebones wikipedia sourcing
This commit is contained in:
@@ -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)))
|
||||
|
7
src/hollywoo_sourcer/WikipediaMain.hx
Normal file
7
src/hollywoo_sourcer/WikipediaMain.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package hollywoo_sourcer;
|
||||
|
||||
class WikipediaMain {
|
||||
static function main() {
|
||||
WikipediaMain_.main();
|
||||
}
|
||||
}
|
23
src/hollywoo_sourcer/WikipediaMain_.kiss
Normal file
23
src/hollywoo_sourcer/WikipediaMain_.kiss
Normal 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)))
|
Reference in New Issue
Block a user