opengameart sourcer
This commit is contained in:
@@ -17,6 +17,9 @@
|
|||||||
--js bin/freesound.js
|
--js bin/freesound.js
|
||||||
--next
|
--next
|
||||||
|
|
||||||
|
--main hollywoo_sourcer.OpenGameArtMain
|
||||||
|
--js bin/opengameart.js
|
||||||
|
--next
|
||||||
|
|
||||||
--main hollywoo_sourcer.Background
|
--main hollywoo_sourcer.Background
|
||||||
--js bin/background.js
|
--js bin/background.js
|
||||||
|
@@ -26,6 +26,12 @@
|
|||||||
"https://freesound.org/people/*/sounds/*/"
|
"https://freesound.org/people/*/sounds/*/"
|
||||||
],
|
],
|
||||||
"js": ["bin/browser-polyfill.js", "bin/freesound.js"]
|
"js": ["bin/browser-polyfill.js", "bin/freesound.js"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matches": [
|
||||||
|
"https://opengameart.org/content/*"
|
||||||
|
],
|
||||||
|
"js": ["bin/browser-polyfill.js", "bin/opengameart.js"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"background": {
|
"background": {
|
||||||
@@ -50,7 +56,8 @@
|
|||||||
"https://pixabay.com/*/*/",
|
"https://pixabay.com/*/*/",
|
||||||
"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/*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ import hollywoo_sourcer.Message;
|
|||||||
import haxe.io.Path;
|
import haxe.io.Path;
|
||||||
import js.html.File;
|
import js.html.File;
|
||||||
import js.html.URL;
|
import js.html.URL;
|
||||||
|
import js.lib.Promise;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class Background {
|
class Background {
|
||||||
|
@@ -49,5 +49,21 @@
|
|||||||
(catch [e] (sendResponse e))
|
(catch [e] (sendResponse e))
|
||||||
(API.browser.downloads.show txtDownloadId)
|
(API.browser.downloads.show txtDownloadId)
|
||||||
(sendResponse "done")))))
|
(sendResponse "done")))))
|
||||||
|
((object type "downloadOpenGameArt" data [fileUrls creditAttributionNotice sourceUrl])
|
||||||
|
// awaitLet the DownloadItem and make an object url with the source info
|
||||||
|
(awaitLet [&sync :Array<String> fileUrls fileUrls
|
||||||
|
dlItemIds (Promise.all (for fileUrl fileUrls (API.browser.downloads.download (object saveAs true url fileUrl))))
|
||||||
|
dlItemsAll (Promise.all (for dlItemId dlItemIds (API.browser.downloads.search (object id dlItemId))))]
|
||||||
|
(doFor dlItems dlItemsAll
|
||||||
|
(let [dlItem (first dlItems)
|
||||||
|
fileName dlItem.filename
|
||||||
|
txtFileName "$(Path.withoutDirectory (Path.withoutExtension fileName)).tsv"
|
||||||
|
txtContent "opengameart.org\t${creditAttributionNotice}\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/OpenGameArtMain.hx
Normal file
7
src/hollywoo_sourcer/OpenGameArtMain.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package hollywoo_sourcer;
|
||||||
|
|
||||||
|
class OpenGameArtMain {
|
||||||
|
static function main() {
|
||||||
|
OpenGameArtMain_.main();
|
||||||
|
}
|
||||||
|
}
|
29
src/hollywoo_sourcer/OpenGameArtMain_.kiss
Normal file
29
src/hollywoo_sourcer/OpenGameArtMain_.kiss
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
(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 [sourceUrl window.location.href
|
||||||
|
fieldLabelDivs (document.getElementsByClassName "field-label")
|
||||||
|
getCreditsHeadingDiv ->{
|
||||||
|
(doFor i (range fieldLabelDivs.length)
|
||||||
|
(when (= "Copyright/Attribution Notice: " .innerText (fieldLabelDivs.item i))
|
||||||
|
(return (fieldLabelDivs.item i))))
|
||||||
|
null
|
||||||
|
}
|
||||||
|
creditsHeadingDiv (getCreditsHeadingDiv)
|
||||||
|
creditsDiv (creditsHeadingDiv.parentElement.childNodes.item 1)
|
||||||
|
credit creditsDiv.innerText
|
||||||
|
fileSpans (document.getElementsByClassName "file")
|
||||||
|
fileUrls (for i (range fileSpans.length)
|
||||||
|
(Reflect.field (.item .childNodes (fileSpans.item i) 2) "href"))]
|
||||||
|
(awaitLet [response (API.browser.runtime.sendMessage (object type "downloadOpenGameArt" data [fileUrls credit sourceUrl]))]
|
||||||
|
(print response))))
|
||||||
|
(otherwise)))
|
Reference in New Issue
Block a user