Skip to content

Commit

Permalink
Merge pull request #86 from HuiiBuh/features
Browse files Browse the repository at this point in the history
Refined the bulk download, changed the icon, added url to manifest
  • Loading branch information
HuiiBuh authored Apr 9, 2020
2 parents 167b17d + 75940d2 commit 72cdba7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 35 deletions.
36 changes: 24 additions & 12 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion firefox/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Binary file modified firefox/icons/instagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"content_scripts": [
{
"matches": [
"*://*.instagram.com/*"
"*://*.instagram.com/*",
"*://*.fbcdn.net/*"
],
"js": [
"js/Modal.js",
Expand Down
42 changes: 22 additions & 20 deletions firefox/ts/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

});

}
Expand Down
2 changes: 1 addition & 1 deletion firefox/ts/downloaders/BulkDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 72cdba7

Please sign in to comment.