dafont sourcer
This commit is contained in:
@@ -5,6 +5,10 @@
|
||||
-dce full
|
||||
--each
|
||||
|
||||
--main hollywoo_sourcer.DaFontMain
|
||||
--js bin/dafont.js
|
||||
--next
|
||||
|
||||
--main hollywoo_sourcer.OpenClipArtMain
|
||||
--js bin/openclipart.js
|
||||
--next
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"48": "icons/icon-48.png"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["https://www.dafont.com/*.font"],
|
||||
"js": ["bin/browser-polyfill.js", "bin/dafont.js"]
|
||||
},
|
||||
{
|
||||
"matches": ["https://openclipart.org/detail/*/*"],
|
||||
"js": ["bin/browser-polyfill.js", "bin/openclipart.js"]
|
||||
@@ -62,7 +66,8 @@
|
||||
"https://*.wikipedia.org/wiki/*",
|
||||
"https://freesound.org/people/*/sounds/*/",
|
||||
"https://opengameart.org/content/*",
|
||||
"https://openclipart.org/detail/*/*"
|
||||
"https://openclipart.org/detail/*/*",
|
||||
"https://www.dafont.com/*.font"
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
@@ -111,5 +111,19 @@
|
||||
(catch [e] (sendResponse e))
|
||||
(API.browser.downloads.show txtDownloadId)
|
||||
(sendResponse "done")))))
|
||||
((object type "downloadDaFont" data [filename creator fileUrl sourceUrl])
|
||||
// awaitLet the DownloadItem and make an object url with the source info
|
||||
(awaitLet [dlItemId (API.browser.downloads.download (object filename filename saveAs true url ~fileUrl))
|
||||
dlItems (API.browser.downloads.search (object id dlItemId))]
|
||||
(let [dlItem (first dlItems)
|
||||
fileName dlItem.filename
|
||||
txtFileName "$(Path.withoutDirectory (Path.withoutExtension fileName)).tsv"
|
||||
txtContent "dafont.com\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))
|
||||
true))
|
||||
|
||||
7
src/hollywoo_sourcer/DaFontMain.hx
Normal file
7
src/hollywoo_sourcer/DaFontMain.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package hollywoo_sourcer;
|
||||
|
||||
class DaFontMain {
|
||||
static function main() {
|
||||
DaFontMain_.main();
|
||||
}
|
||||
}
|
||||
20
src/hollywoo_sourcer/DaFontMain_.kiss
Normal file
20
src/hollywoo_sourcer/DaFontMain_.kiss
Normal file
@@ -0,0 +1,20 @@
|
||||
(import kiss_firefox.API)
|
||||
(import js.lib.Promise)
|
||||
(importAs js.html.XMLHttpRequest XHR)
|
||||
(import kiss_firefox.Message)
|
||||
(loadFrom "kiss-firefox" "src/kiss_firefox/ContentUtil.kiss")
|
||||
|
||||
(API.browser.runtime.onMessage.addListener
|
||||
->[:Message message sender sendResponse]
|
||||
(case message
|
||||
((object type "requestSource")
|
||||
(let [:String url window.location.href
|
||||
:kiss.List<String> parts (url.split "/")
|
||||
font (parts.pop) // font.font
|
||||
filename "$(StringTools.replace font ".font" "").zip"
|
||||
creator .innerHTML (document.querySelector ".lv1left > a:nth-child(2)")
|
||||
downloadLink (.item (document.getElementsByClassName "dl") 0)
|
||||
dlUrl .href downloadLink]
|
||||
(awaitLet [response (API.browser.runtime.sendMessage (object type "downloadDaFont" data [filename creator dlUrl url]))]
|
||||
(print response))))
|
||||
(otherwise)))
|
||||
Reference in New Issue
Block a user