OpenClipArt sourcer
This commit is contained in:
@@ -5,6 +5,10 @@
|
|||||||
-dce full
|
-dce full
|
||||||
--each
|
--each
|
||||||
|
|
||||||
|
--main hollywoo_sourcer.OpenClipArtMain
|
||||||
|
--js bin/openclipart.js
|
||||||
|
--next
|
||||||
|
|
||||||
--main hollywoo_sourcer.PixabayMain
|
--main hollywoo_sourcer.PixabayMain
|
||||||
--js bin/pixabay.js
|
--js bin/pixabay.js
|
||||||
--next
|
--next
|
||||||
|
@@ -10,6 +10,10 @@
|
|||||||
"48": "icons/icon-48.png"
|
"48": "icons/icon-48.png"
|
||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": ["https://openclipart.org/detail/*/*"],
|
||||||
|
"js": ["bin/browser-polyfill.js", "bin/openclipart.js"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"matches": ["https://pixabay.com/*/*/"],
|
"matches": ["https://pixabay.com/*/*/"],
|
||||||
"js": ["bin/browser-polyfill.js", "bin/pixabay.js"]
|
"js": ["bin/browser-polyfill.js", "bin/pixabay.js"]
|
||||||
@@ -57,7 +61,8 @@
|
|||||||
"https://*.wikipedia.org/wiki/File:*",
|
"https://*.wikipedia.org/wiki/File:*",
|
||||||
"https://*.wikipedia.org/wiki/*",
|
"https://*.wikipedia.org/wiki/*",
|
||||||
"https://freesound.org/people/*/sounds/*/",
|
"https://freesound.org/people/*/sounds/*/",
|
||||||
"https://opengameart.org/content/*"
|
"https://opengameart.org/content/*",
|
||||||
|
"https://openclipart.org/detail/*/*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
(API.browser.tabs.sendMessage
|
(API.browser.tabs.sendMessage
|
||||||
tab.id (object type "requestSource" data [])))
|
tab.id (object type "requestSource" data [])))
|
||||||
|
|
||||||
(API.browser.runtime.onMessage.addListener ->[:Message message sender sendResponse]
|
(API.browser.runtime.onMessage.addListener ->[:Message message sender sendResponse]
|
||||||
(let [:Function sendResponse sendResponse]
|
(let [:Function sendResponse sendResponse]
|
||||||
(case message
|
(case message
|
||||||
((object type "downloadPixabay" data [imageInfo])
|
((object type "downloadPixabay" data [imageInfo])
|
||||||
@@ -65,5 +65,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 "downloadOpenClipArt" data [sourceUrl filename creator fileUrl])
|
||||||
|
// awaitLet the DownloadItem and make an object url with the source info
|
||||||
|
(awaitLet [dlItemId (API.browser.downloads.download (object saveAs true url fileUrl filename "${filename}.png"))
|
||||||
|
dlItems (API.browser.downloads.search (object id dlItemId))]
|
||||||
|
(let [dlItem (first dlItems)
|
||||||
|
fileName dlItem.filename
|
||||||
|
txtFileName "$(Path.withoutDirectory (Path.withoutExtension fileName)).tsv"
|
||||||
|
txtContent "openclipart.org\t${creator}\t${sourceUrl}"
|
||||||
|
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/OpenClipArtMain.hx
Normal file
7
src/hollywoo_sourcer/OpenClipArtMain.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package hollywoo_sourcer;
|
||||||
|
|
||||||
|
class OpenClipArtMain {
|
||||||
|
static function main() {
|
||||||
|
OpenClipArtMain_.main();
|
||||||
|
}
|
||||||
|
}
|
21
src/hollywoo_sourcer/OpenClipArtMain_.kiss
Normal file
21
src/hollywoo_sourcer/OpenClipArtMain_.kiss
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
(import kiss_firefox.API)
|
||||||
|
(import js.lib.Promise)
|
||||||
|
(importAs js.html.XMLHttpRequest XHR)
|
||||||
|
(import js.html.HTMLCollection)
|
||||||
|
(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 [url window.location.href
|
||||||
|
title .innerHTML (.item (document.getElementsByTagName "h2") 0)
|
||||||
|
links (document.getElementsByTagName "a")
|
||||||
|
links (for idx (range links.length) (links.item idx))
|
||||||
|
artist .innerHTML (first (filter links ->[:Dynamic link] (StringTools.contains link.href "/artist/")))
|
||||||
|
fileUrl .href (first (filter links ->[:Dynamic link] (= link.innerHTML "Large")))]
|
||||||
|
(awaitLet [response (API.browser.runtime.sendMessage (object type "downloadOpenClipArt" data [url title artist fileUrl]))]
|
||||||
|
(print response))))
|
||||||
|
(otherwise)))
|
Reference in New Issue
Block a user