(function _main [] (API.browser.pageAction.onClicked.addListener ->[tab clickData] (API.browser.tabs.sendMessage tab.id (object type "requestSource" data []))) (API.browser.runtime.onMessage.addListener ->[:Message message sender sendResponse] (let [:Function sendResponse sendResponse] (case message ((object type "downloadPixabay" data [imageInfo]) // awaitLet the DownloadItem and make an object url with the source info (awaitLet [dlItemId (API.browser.downloads.download (object saveAs true url imageInfo.largeImageURL)) dlItems (API.browser.downloads.search (object id dlItemId))] (let [dlItem (first dlItems) fileName dlItem.filename txtFileName "$(Path.withoutDirectory (Path.withoutExtension fileName)).tsv" txtContent "pixabay.com\t${imageInfo.user}\t${imageInfo.pageURL} user id ${imageInfo.user_id}" 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"))))) ((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"))))) ((object type "downloadFreesound" data [filename creator fileUrl sourceUrl]) // awaitLet the DownloadItem and make an object url with the source info (awaitLet [dlItemId (API.browser.downloads.download (object 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 "freesound.org\t${creator}\t${sourceUrl} by https://freesound.org/people/${creator}" 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)))