Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified extension for saving images in chronological order #43

Closed
DimkaDim opened this issue Dec 21, 2018 · 2 comments
Closed

Modified extension for saving images in chronological order #43

DimkaDim opened this issue Dec 21, 2018 · 2 comments

Comments

@DimkaDim
Copy link

DimkaDim commented Dec 21, 2018

I have modified this extension to save images opened in tabs and rename them to full date/time down to milliseconds, so that sorting by filename would order them from oldest opened in browser to newest opened (in case your browser is set to open new tabs always directly to the right from current tab). I have attached the resulting extension to this post.

HOW TO INSTALL:
Download and unpack "hhcoikfhkkadkgklepjkfgafmjoggefh.zip" to folder, then load that folder in chrome://extensions/ page in developer mode in Chrome Dev, Chrome Canary, Cent browser or Slimjet (official release version of Chrome will be nagging you to disable customized unsigned extension).

FURTHER DETAILS:
I'm not a web developer, I don't know JS, HTML or Node.js and this was among my first attempts at modifying code of extension and among my first attempts on modifying JS code. However, I know how to program in C, so that helped. Therefore, the quality of code is pretty shitty, and I couldn't even figure out how to compile a package in Node.js from source code, so I had to torture myself and edit code directly in minified code of unpacked extension. That is why I didn't submit a code commit.

WHAT THIS THING DOES DIFFERENTLY COMPARED TO VANILLA EXTENSION:

  1. It always saves images in subfolder of Downloads folder, instead of saving directly in Downloads folder. This subfolder is named "Saved tabbed images". It is automatically created if it doesn’t exist.
  2. It saves images from tabs in the order tabs are ordered on tab bar, beginning from the rightmost tab with image, and ending on the leftmost tab with image. (Vanilla extension saves images asynchronously, so if you order them by date created (or modified) (even with millisecond precision), they will be sorted in random order.)
  3. Every saved image is renamed to full date/time ("24h" format) with millisecond precision, for example: "2018.12.21 18.58.21.145.png". Original filename as on website is truncated completely, only extension of filename is left, and converted to lowercase. As a result, sorting by filename will order images in the order you initially opened them in browser. That time in filename is the instant an image was added into chromium downloads stack (not the instant it was downloaded).
  4. There is no need to click "Close downloaded tabs" button, it gets clicked automatically 0,5 seconds after starting the process of going through tabs and adding images into chromium downloads stack. So, overall, just two clicks - one to open extension panel, another to hit "Download" button. In certain rare situations, this time (500 ms) might be insufficient to save all images, read further if there's a problem with that.

IF YOUR BROWSER IS NOT SET TO OPEN TABS DIRECTLY TO THE RIGHT FROM CURRENT TAB:
In file "*/js/index.js" delete or comment line
t.reverse(),
Delete only the occurrence of this text that is on a separate line, leave another occurrence untouched. That will make extension to cycle through tabs with images from left to right.

IF 500 ms DELAY UNTIL AUTOCLICKING "Close downloaded tabs" BUTTON LEAVES SOME TABS WITH IMAGES UNSAVED:
Generally, 500 ms delay should be enough to save more than even a hundred tabs with images, but from my observation, it may sometimes be insufficient with one of these factors:

  1. Using VPN
  2. Torrent is being downloaded
  3. More than 50 images are being saved

So, if that problem appears, change "500" in line
setTimeout(function(){e.onClickCloseDownloadedTabs()},500)
to something larger, like 800 or 1200, or even more. This delay is, unfortunately, a compromise between amount of images saved at once and quickness of the process of saving.

WHAT SIMILAR TOOL EXISTED BEFORE THIS:
In preQuantum Firefox there was an add-on "Bazzacuda Image Saver Plus". Because all old add-ons were deleted from AMO, I've attached modified version of this add-on to this post as well, in case anyone wants it.
If you, for example, download Firefox version 42 (or any up to version 56, but it is more difficult to install unsigned add-ons in later versions) and install Bazzacuda from this file, in its options:

  1. Check flags "Rename duplicate images" and "Rename images even if their names don’t duplicate"
  2. By clicking "Set" button, paste this new "Rename pattern":
    &YYYY;.&MM;.ⅅ-&hh;.&mm;.&ss;,&ms; &filename;&[;(&dupnum;)&];
    After that, just a single click on Bazzacuda add-on button does pretty much the same thing as this modification (also going through tabs from rightmost to leftmost - this is what I've modified, and this is why the attached Bazzacuda add-on is unsigned by Mozilla).

WHY THIS IS THE BEST THINKABLE WAY TO SAVE IMAGES OFF THE INTERNET:
You control which images will get saved from a page by middle-clicking them.
You can preview images in full size in browser before they will be saved.
You fully control the order, in which images are shown in image viewers and file explorers after saving them, by opening them in browser in order you want them saved, and if needed, by rearranging opened tabs in required order.

SOME NOTABLE TECHNICAL DETAILS OF IMPLEMENTATION, AND HOW THIS CAN BE MADE BETTER:
This is probably not interesting to anybody, I'm writing this in case anybody wants to implement these modifications better than I am capable of, and, of course, by using original source code instead of minified code which I used.

The only file I modified is "*/js/index.js". Others are untouched.

In original extension, onDeterminingFilename event handler ( https://developer.chrome.com/extensions/downloads#event-onDeterminingFilename ) is when naming of file (path) happens. It is an unsuitable place for renaming if we want files to be chronologically named, because there is no way to insert 1 ms pause between renaming events (it's asynchronously called) and because the order it is called in is usually not the order the file was put in downloads stack. The suitable place is downloads.download() method ( https://developer.chrome.com/extensions/downloads#method-download ). I used renaming in downloads.download() method in my modification, works perfectly.

To ensure that all filenames are unique, I inserted a 1 ms pause after each instant the image gets put into downloads stack, so that filenames are at least 1 millisecond apart.

I've tried to make this extension to close saved tabs and its panel after all images are put into downloads stack, instead of after predefined amount of time (500 ms), but these attempts were not successful (because I don't know anything about how all this stuff works:) ).
I also wanted not to open the extension panel at all, I wanted just a single click on the extension's button to save images (like Bazzacuda did), but, again, I have no idea how to do this.

Nevertheless, even as is, this modification works great, it has proven to be very useful to me in batch saving images from Tumblr, which has just died:)

hhcoikfhkkadkgklepjkfgafmjoggefh.zip
bazzacuda_image_saver_plus-0.65-fx.zip

@kevinsqi
Copy link
Owner

Whoa, you modified the minified source? That's nuts (but impressive) haha. I think there may be some ideas like timestamping files that may be usable. Auto-downloading after 500ms isn't ideal, though, in my opinion, just because I much prefer explicit actions over timed behavior.

Unfortunately, I'm too busy these days to make enhancements to the extension myself. I hope to get back to it eventually, but in the meantime you can feel free to fork and publish your own version of the extension if you'd like. I'd recommend trying to build the extension and use the source code, though. The README should guide you through that. Good luck!

@DimkaDim
Copy link
Author

DimkaDim commented Jan 6, 2019

Thank you for encouragement!

You probably meant "Auto-closing downloaded tabs after 500ms isn't ideal" - yeah, ideally there should be an option in settings for everything, but I don't know web technologies at all. I tried to minimize amount of clicks and I just couldn't think then of a way to autoclose downloaded tabs other than calling corresponding button handler after some delay. Now that I think of it, I could have tried closing tabs right after saving them in loop.

I too would have spent a bit more time than I'd like to, rewriting the unminified code, learning how to fork on github, how to build in node.js (i had unsuccessful attempt with a different extenion already), so since it works well already, I'll leave it as is for the time being.

Anyway, thanks for very useful extension, there was no other equivalent to Bazzacuda on Chrome Web Store, and I could barely find this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants