RussCoder / djvujs

DjVu.js is a program library for working with .djvu files online without any connection with the server. DjVu.js Viewer is a widget that allows viewing .djvu files right in the browser and can be easily embedded into any web page.
https://djvu.js.org/
Other
183 stars 36 forks source link

how to associate filetype DJVU properly? #13

Closed dimyme closed 5 years ago

dimyme commented 5 years ago

https://github.com/dimyme/djvujs/wiki/associate-.djvu-filetype

I tried to open a djvu-file directly, but it seems to be imposs even with add-on. see link please. also filed as https://github.com/Rob--W/open-in-browser/issues/55

RussCoder commented 5 years ago

Hello, @dimyme !

As far as I understand you want to open djvus just via clicking on links. And you try to do it combining the DjVu.js Viewer and the open-in-browser extension.

However, I should mention, that currently my extension can't open local djvu files when they are opened via browser directly. In other words, I didn't find any API which allows to intercept the opening of a file in a browser, so the only way to open a local file via the viewer is to open it from the viewer page or to drag and drop it on the viewer page.

As I got it, the open-in-browser extension just modifies the behavior of a browser so that a file is opened by the browser and not saved, but as I have said the DjVu.js Viewer can do nothing in this case.

However, if you just want to open links in the browser you can use an additional "Open with DjVu.js Viewer" option in the context menu which pops up when you right-click a link. Do you know about this option? Isn't it enough for you?

dimyme commented 5 years ago

What I meant was: I can click on .htm files in a file-explorer (KDE Dolphin) which starts Firefox, since Firefox is associated with the file-type "HTML". But without the API you mention it seems not possible. Seems like ffox can only open HTML and .xpi files and maybe a few more, but , say, no *.epub asf..

Accordingly, it might be possible to open other file types, such as DjVu , the same way as HTML files themselves. But that runs into a ffox-dialog : "with what shall I open the file?" and ffox cannot just open it and display the djvu using your ffox add-on.

Otherwise, your add-on works fine, so I can see DJVU files, if ffox is ALREADY open. But that is too many clicks to do it that way all the time. This is what file associations are for.

If I right-click on http://djvu.org/docs/2001_efficient_compression.djvu I now can see the option by DJVU-viewer which you mention. (could not see it initially) Thanks for the elucidations. Great viewer of yours ! Too bad ffox cannot be told to open files directly, which its add-ons can indeed process :-(

dimyme commented 5 years ago

I updated the wiki a little. seems that this firefox issue won't fix anytime soon.

RussCoder commented 5 years ago

Hello, @dimyme !

Actually I managed to implement the feature, but for Google Chrome only (I have updated the extension there - v.0.2.5.0). Firefox doesn't commit a web request (and doesn't fire a corresponding event, which can be listened to) when a local file is opened, while Chrome does a request to a local file, and it can be intercepted.

Although, Firefox fires another event (navigation event) and I can detect that a file is opened, but I can neither intercept it, nor cancel it, nor get the file itself.

You can read here that it's not allowed to get local files in Firefox by URLs: https://discourse.mozilla.org/t/opening-links-to-local-files-file/16449/4

In case of Chrome one should enable the option that allows to an extension to access local files too, but there is at least the option, while in Firefox there is no such an option at all.

All in all, the issue should be closed, since I see no options how to implement it for Firefox.