Download multiple images without asking in Chrome extension - javascript

I am currently creating a Chrome extension (which uses javascripts mainly) that allows users to scrape the images on a webpage and download them. I have finished the link scraping part, and the code will return an array like:
["http://example.com/image1.jpg","http://example.com/image2.jpg"]
But how do I download all of the links in ONE CLICK? I tried listing all photos on a new tab and let the users to Ctrl+S save the page. But this greatly affects the UI and I do not like it. I do not host webpage so server side script may not be working.. Any other solutions?

As far as I know, Chrome extensions technically can't save files to disk like Firefox.
The only way to do this is using NPAPI
Unfortunately, extensions using npapi will most likely not be accepted by the Web Store due to security problems. Of course it'll be okay if you use it for yourself or host the extension on your website.
You can install and examize the code of the following extensions, maybe you can even use the provided npapi too:
Screen Capture (by Google) https://chrome.google.com/webstore/detail/cpngackimfmofbokmjmljamhdncknpmg
Chrome Toolbox (by Google) https://chrome.google.com/webstore/detail/fjccknnhdnkbanjilpjddjhmkghmachn
Awesome Screenshot: Capture & Annotate https://chrome.google.com/webstore/detail/alelhddbbhepgpmgidjdcjakblofbmce
Download Asisstant (by Google) - got killed I guess.

Related

Control a PPTX file with Javascript offline

This is an odd use-case and I've tried to steer the users away from this, but I have a request to load locally stored PPT files in an HTML environment.
The idea is to view the PPT in an iframe so that I can "decorate" all around it. Users will be creating playlists, of sorts, so I need to add "next" and "previous" presnetation buttons, etc.
I have an online version of this working using the Office webapp link that many other posts have shared, but there is a concern for poor connectivity so they want it to be available offline.
My instinct was to shape this up as a PWA. I can make them use Chrome, so I have the FileSystem API "caching" the PPT files from the online source. However, I have no way to render the saved files!
Because it's offline, I can't use googledocs or continue to MS web office.
I don't know the AppCache feature well enough, but wondered if I can preload all of the docs in an iframe, will it cache those. My thought is that it won't, because the content is on microsoft (or Google's) site.
All users will have a legal copy of PPT on the computer, if that helps at all.
So far I have tried storing the files using the filesystem API in combination with the Chrome offline viewer extension and alternatively the Native Docs extension. The Chrome one will allow me to open a doc, but directly in edit mode. I need to simulate the behavior of a ppsx file, but neither extension works with ppsx files and I don't see documentation for an API that will allow me to "auto-play" the presentations.
Thanks for any ideas!
Wayne

Convert Chrome extension to bookmarklet

There are gazillions of tutorials on how to convert a bookmarklet (or any javascript) to a Chrome extension, but I need the vise versa procedure. I have some extensions, which I would like to have as bookmarklets. The idea behind this: I don't want these extensions as they constantly eat away my RAM. Instead, I want simply press a button and run a bookmarklet, if I need it.
An example is this extension, which simply toggles javascript on/off in the browser. This extension contains only one javascript file (not including icons, manifest.json, and signature file _metadata/verified_contents.json).
I tried to use this javascript as a bookmarklet, but doing so doesn't conduce me to success - javascript wasn't toggled. It seems, that I'm missing something substantial, but I don't know what. Could somebody point me to the right procedure of conversion Chrome extensions to bookmarklets?
Conversion to a bookmarklet is impossible for extensions that use privileged chrome API available only for Chrome apps and extensions, in this case chrome.contentSettings.javascript.set.
The root cause - memory hogging by an extension - can be resolved by switching from a persistent background page to an event page that is unloaded when an extension is not used.
You may nag the author of that extension to do so.
Unfortunately, most of the extension authors appear to be unaware.
Another possibility is to edit the extension's manifest.json manually by adding "persistent": false as shown in the event page docs (don't forget the comma), then load it locally. Some extensions will fail since switching to an event page may require reworking of code.

How to Launch a PDF from a Chrome Packaged App?

My chrome packaged app contains a PDF, and I would like to let the user view it. If I open it in the current frame I get the error "Chrome PDF Viewer is not Allowed".
Frankly, the chrome PDF viewer is pretty awful, so I'd rather let the user view it in their PDF viewer of choice anyway. If I disable the chrome PDF plugin (just as an experiment) and I try to open the PDF using chrome.app.window.open, it "downloads" the PDF, and then the user could open it. But this has two issues:
I can't realistically make the user go to chrome://plugins and do that disable
There isn't any browser window, so the user has no idea the download happened
Any suggestions? Opening PDFs that are embedded in my app is kind of a must-have feature for this app.
I've looked at this extensively, and have come to the conclusion that there's no way to get a Chrome App to open a PDF that's local. I, too, have tried data URIs.
I don't think the issue is the PDF support in the window, as it's still Chrome, or the size of the PDFs. Rather, I think it's just an engineering problem, one that might get solved someday.
As for me, I build the PDF in my Chrome App. Since I can't display it, and there's no server to upload it to, I write it to a file of the user's choosing and let the user deal with it on his/her own.
I've got this working, but whether it is a solution for you depends a lot on your use case. The solution has three parts:
Use pdfjs to do the actual rendering.
To get this running in a packaged app, you'd need to do some violence to the internationalization support. And even after you do that, you'll find that some PDFs refuse to load for no apparent reason whatsoever. So don't bother trying to make pdfjs work in a packaged app. Just:
Put your entire app into a <webview> with a persist partition, and use a HTML5 cache manifest to get all your files available for offline viewing.
Yeah, yeah, I know that cache manifests are not cool anymore. But if you can list all your files for use in a packaged app, then you are doing the one case where cache manifests actually work great.
Then use a packaged app to distribute a tiny wrapper around your page with the webview in it.
You'll also get the benefit that you don't have to rewrite your app to live within the draconian packaged app rules (eval, sync xhr, 2GB limit, etc.).
You can see a working example at m.kaon.com/c/ka (visit with Chrome to get the desktop app; if you visit that with Firefox, you'll get access to a hosted app that is using the same tricks). PDFs are down in the bottom "Why Choose Kaon" section.

How do you open a file folder through a link on website in Firefox and Chrome?

I'm working on a web application that needs to have a link which opens a documents folder from a file server. The folder can be opened either in a new browser tab or new window, or using the computer's default file browser program (i.e. Windows Explorer). This javascript should do the trick:
window.open('file://///fileserver.companyname/public/Documents/','_blank);
and this html should also work:
Open Documents
but these both only work in Internet Explorer, and our users always use Firefox and Chrome. Apparently the default security settings for Firefox and Chrome don't let you open a "file://" when the request is called from an "http://" website.
I've seen several references to this page: Links to local pages do not work which describes why you can't open files from webpages using Firefox and offers a few workarounds. Unfortunately, it only offers two options: install a plug-in on each browser instance, or create a user preferences file for each browser instance. Neither of these options are acceptable because we have too many users. The company I work for is not willing to apply anything to each machine which needs to access this link. Aside from that, I tried both plug-ins and the preferences file anyway, and the only one that worked for me was the IE Tab plug-in. I think the reason LocalLinks didn't work is because I'm trying to open a folder, not a file.
This stackoverflow question described similar options for Chrome: Can Google Chrome open local links? but again, the LocalLinks plug-in didn't work for me and plug-ins aren't acceptable anyway.
I also found a website that suggested to use a command line argument top open files in Chrome (http://www.askyb.com/chrome/open-local-file-in-google-chrome/) and one that showed how to apply the argument automatically (https://askubuntu.com/questions/160245/making-google-chrome-option-allow-file-access-from-files-permanent), but if I read it correctly it still involves applying changes to every computer accessing our website.
Is there any way to open a file folder in both Firefox and Chrome entirely programmatically i.e. within my web application C# or Javascript code without installing a plug-in or adding a preferences file to individual computers? I cannot alter any of these business requirements.
Sidenote: We are using C# with MVC 4. I would prefer to open the folder using a Controller Action in C# (because I'd like to create the folder before opening it if it doesn't exist yet), but javascript or html on the client side is acceptable. For Internet Explorer, I can create that javascript in the C# code by wrapping it in the JavaScript( ... ) function built into MVC C# Controllers. When testing IE Tabs in Firefox and Chrome, I had to define it as an href link, not a function that opens a window, or IE Tabs wouldn't recognize it as a link. But neither of these were acceptable workarounds for our business needs.
The request was dropped before I could come up with a feasible solution, but in case anyone else is still struggling with this problem I will describe workaround that would not require any workstation customization.
They don't technically need to use the built-in file explorer to open a folder. Instead, a creative way to display the information the business wanted without breaking any browser security rules would be to iterate though the files without opening the file explorer and then display a list of folders/files in a browser window.
Using Directory.EnumerateDirectories(filepath) and Directory.EnumerateFiles(filepath) you can get a list of folders and files to display. When the user clicks one of the folders, call these methods again to get the next level of folders and filenames. When the user clicks a file, download/open it. These methods return the folder and file names as lists of strings, so you would just need to render the lists with custom icons in the browser. (The methods are from C#'s System.IO library.)
here is the simple html code:
<input type="file" webkitdirectory>
but the problem with this code is that it works only on google!

What is the best way to trigger a download of a safari extension?

I have a Safari extension that I built that is properly packaged as a .safariextz. I want to trigger a download of the extension via javascript.
Currently, I am just using window.replace and pointing it to the extension URL. This causes a download, but the user must find the download and then start the installation process which pops the confirmation dialog.
Any ideas about simpler (for the user) ways of doing this install process that are started by Javascript?
I was amazed because Chrome and Firefox both have a much better install process for the user. I was hoping for something similar.
There's a safari.installExtension(id, url) API. Take a look at extensions.apple.com, in their extensions.js file. It's nicely commented and clear, which is surprising and the API works as expected. The id is your extension namespace followed by your developer certificate ID and the URL can be the url on your own server.
Edit: This function only seems to be available when ON the extensions.apple.com site. trying other ideas.

Categories