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

Prevent downloading image by clicking on view image #261

Open
skyfighteer opened this issue Jul 24, 2022 · 5 comments
Open

Prevent downloading image by clicking on view image #261

skyfighteer opened this issue Jul 24, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@skyfighteer
Copy link

skyfighteer commented Jul 24, 2022

Example image:

https://www.google.com/search?q=images&tbm=isch&ved=2ahUKEwijwZP6gpL5AhWtPOwKHWSMDekQ2-cCegQIABAA&oq=images&gs_lcp=CgNpbWcQAzIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQ6BAgAEENQvAVYsgdgsAloAHAAeACAAZgBiAH2BZIBAzQuM5gBAKABAaoBC2d3cy13aXotaW1nwAEB&sclient=img&ei=s33dYuObAa35sAfkmLbIDg&bih=920&biw=959&rlz=1C1GCEA_enHU985HU985&hl=en#imgrc=2nDXavJs9DoKTM

When you click on the button, it downloads the image. I would suggest using a regex like this one, then replacing the href.
let regex = /(\&dl)(.*?)(?=&)/; // "&dl" + everything after it just before another "&"

@ner00
Copy link
Contributor

ner00 commented Jul 24, 2022

This will probably have an adverse effect at some point, but if this is implemented I think might as well try a more general approach where you just capture the url until the first argument, using (^.*)(?=\?)

This would make
https://images.pexels.com/photos/674010/pexels-photo-674010.jpeg?cs=srgb&dl=pexels-anjana-c-674010.jpg&fm=jpg
into
https://images.pexels.com/photos/674010/pexels-photo-674010.jpeg

Although there are probably cases where genuine images are linked using arguments like image key or id, and so my suggestion would screw those. The other approach is too specific and would only fix one website at a time, and that would get out of hand pretty quickly.

@ner00
Copy link
Contributor

ner00 commented Jul 24, 2022

Here's another quick example where a general approach would be favorable:

https://www.google.com/search?q=images&tbm=isch&ved=2ahUKEwijwZP6gpL5AhWtPOwKHWSMDekQ2-cCegQIABAA&oq=images&gs_lcp=CgNpbWcQAzIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQyBQgAEIAEMgUIABCABDIFCAAQgAQ6BAgAEENQvAVYsgdgsAloAHAAeACAAZgBiAH2BZIBAzQuM5gBAKABAaoBC2d3cy13aXotaW1nwAEB&sclient=img&ei=s33dYuObAa35sAfkmLbIDg&bih=920&biw=959&rlz=1C1GCEA_enHU985HU985&hl=en#imgrc=n5hAWsQ-sgKo_M

Currently this will show you a downsized image when clicking the "View Image" button, due to the url arguments:
https://images.unsplash.com/photo-1453728013993-6d66e9c9123a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8bGVuc3xlbnwwfHwwfHw%3D&w=1000&q=80
when removing the arguments you get the full resolution image:
https://images.unsplash.com/photo-1453728013993-6d66e9c9123a

@skyfighteer
Copy link
Author

skyfighteer commented Jul 24, 2022

The last one you showed is indeed a tricky one. I don't think there is a method that would cover multiple sites, since the transformation of the link is fairly substantial here:

https://burst.shopify.com/photos/person-holds-a-book-over-a-stack-and-turns-the-page/download
https://burst.shopifycdn.com/photos/person-holds-a-book-over-a-stack-and-turns-the-page.jpg

@ner00
Copy link
Contributor

ner00 commented Jul 24, 2022

Yeah, and I wouldn't worry much about it, all I'm saying is that it isn't possible to cover all bases but the issue you raised is a good one and we should try to maximize the functionality for a diversity of cases without compromising the worst case: direct download of the image.

@bijij bijij added the enhancement New feature or request label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants