diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6197b8b..1659b4e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,15 +3,11 @@ - - - - + + + + - - - - \ No newline at end of file diff --git a/firefox/build.sh b/firefox/build.sh index 1cee2aa..1c7fb86 100755 --- a/firefox/build.sh +++ b/firefox/build.sh @@ -29,5 +29,5 @@ hash addons-linter > /dev/null || (rm -rf _dist && echo 'You have to install the # Lint the addon echo '' -addons-linter _dist/firefox.zip || (rm -rf _dist && echo 'There was an error in the addon. The build was deleted.') +addons-linter _dist/firefox.zip diff --git a/firefox/icons/instagram.png b/firefox/icons/instagram.png index 0b496b2..b75441c 100644 Binary files a/firefox/icons/instagram.png and b/firefox/icons/instagram.png differ diff --git a/firefox/manifest.json b/firefox/manifest.json index 643591d..9f03b57 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -23,7 +23,8 @@ "content_scripts": [ { "matches": [ - "*://*.instagram.com/*" + "*://*.instagram.com/*", + "*://*.fbcdn.net/*" ], "js": [ "js/Modal.js", diff --git a/firefox/ts/background.ts b/firefox/ts/background.ts index b6a2656..52ef4c6 100644 --- a/firefox/ts/background.ts +++ b/firefox/ts/background.ts @@ -12,12 +12,8 @@ browser.runtime.onMessage.addListener((message: DownloadMessage) => { }); function downloadSingleImage(message: DownloadMessage): void { - let imageName: string; // Get the image id - if (message.type !== ContentType.bulk) { - imageName = getImageId(message.imageURL[0]); - } - + let imageName = getImageId(message.imageURL[0]); imageName = message.accountName + '_' + imageName; // @ts-ignore @@ -28,30 +24,36 @@ function downloadSingleImage(message: DownloadMessage): void { } - -function downloadBulk(urlList: string[]): void { +function downloadBulk(urls: string[]): void { // @ts-ignore - const zip: JSZip = new JSZip(); + const zip = new JSZip(); let count = 0; - urlList.forEach((url: string) => { + urls.forEach((url: string) => { // loading a file and add it in a zip file // @ts-ignore - JSZipUtils.getBinaryContent(url, (err, data) => { + const oReq = new XMLHttpRequest(); + oReq.open('GET', url, true); + oReq.responseType = 'blob'; - let filename: string = url.split('?')[0]; - filename = filename.split('/').pop(); + oReq.onload = async () => { + const blob = oReq.response; + zip.file(getImageId(url), blob, {binary: true}); - zip.file(filename, data, {binary: true}); - count++; - if (count === urlList.length) { - zip.generateAsync({type: 'blob'}).then(async (content: Blob) => { - const kindaUrl: string = window.URL.createObjectURL(content); - // @ts-ignore - const opened = await browser.tabs.create({url: kindaUrl}); + ++count; + if (count === urls.length) { + const downloadZIP = await zip.generateAsync({type: 'blob'}); + const kindaUrl = window.URL.createObjectURL(downloadZIP); + // @ts-ignore + browser.downloads.download({ + url: kindaUrl, + filename: 'bulk_download.zip', }); } - }); + }; + + oReq.send(); + }); } diff --git a/firefox/ts/downloaders/BulkDownloader.ts b/firefox/ts/downloaders/BulkDownloader.ts index fcfcbed..dd877a5 100644 --- a/firefox/ts/downloaders/BulkDownloader.ts +++ b/firefox/ts/downloaders/BulkDownloader.ts @@ -2,8 +2,8 @@ // TODO stop every downloader // TODO show collected image -// TODO show info modal at the beginning // TODO start downloader only if needed (remove add change event subscription) +// TODO Bulk downloader if not subscribed class BulkDownloader extends Downloader { private static modal: Modal;