barebones wikipedia sourcing
This commit is contained in:
@@ -7,6 +7,9 @@
|
|||||||
--main hollywoo_sourcer.PixabayMain
|
--main hollywoo_sourcer.PixabayMain
|
||||||
--js bin/pixabay.js
|
--js bin/pixabay.js
|
||||||
--next
|
--next
|
||||||
|
--main hollywoo_sourcer.WikipediaMain
|
||||||
|
--js bin/wikipedia.js
|
||||||
|
--next
|
||||||
--main hollywoo_sourcer.Background
|
--main hollywoo_sourcer.Background
|
||||||
--js bin/background.js
|
--js bin/background.js
|
||||||
-cmd cp node_modules/webextension-polyfill/dist/browser-polyfill.js* bin/ && zip -r hollywoo-sourcer.zip . -x *.git* -x *.hxml -x *.zip -x src/\* -x node_modules/\* -x libs/\* -x test.sh
|
-cmd cp node_modules/webextension-polyfill/dist/browser-polyfill.js* bin/ && zip -r hollywoo-sourcer.zip . -x *.git* -x *.hxml -x *.zip -x src/\* -x node_modules/\* -x libs/\* -x test.sh
|
@@ -13,6 +13,13 @@
|
|||||||
{
|
{
|
||||||
"matches": ["https://pixabay.com/*/*/"],
|
"matches": ["https://pixabay.com/*/*/"],
|
||||||
"js": ["bin/browser-polyfill.js", "bin/pixabay.js"]
|
"js": ["bin/browser-polyfill.js", "bin/pixabay.js"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matches": [
|
||||||
|
"https://*.wikipedia.org/wiki/File:*",
|
||||||
|
"https://*.wikipedia.org/wiki/*"
|
||||||
|
],
|
||||||
|
"js": ["bin/browser-polyfill.js", "bin/wikipedia.js"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"background": {
|
"background": {
|
||||||
@@ -34,7 +41,9 @@
|
|||||||
},
|
},
|
||||||
"default_title": "Source this asset",
|
"default_title": "Source this asset",
|
||||||
"show_matches": [
|
"show_matches": [
|
||||||
"https://pixabay.com/*/*/"
|
"https://pixabay.com/*/*/",
|
||||||
|
"https://*.wikipedia.org/wiki/File:*",
|
||||||
|
"https://*.wikipedia.org/wiki/*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -21,5 +21,19 @@
|
|||||||
(catch [e] (sendResponse e))
|
(catch [e] (sendResponse e))
|
||||||
(API.browser.downloads.show txtDownloadId)
|
(API.browser.downloads.show txtDownloadId)
|
||||||
(sendResponse "done")))))
|
(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))
|
(never otherwise))
|
||||||
true)))
|
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