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

Ctrl+S: save JSON instead of HTML content #62

Closed
vogelsgesang opened this issue May 9, 2014 · 11 comments
Closed

Ctrl+S: save JSON instead of HTML content #62

vogelsgesang opened this issue May 9, 2014 · 11 comments

Comments

@vogelsgesang
Copy link
Contributor

It would be great if I could save a JSON file by hitting the Ctrl+S shortcut.
Right now, this saves the rendered HTML. But I would like to save the original JSON file contents

@bhollis
Copy link
Owner

bhollis commented May 10, 2014

I agree, it'd be really nice, but I don't know how to make Firefox do that. A PR that added this feature would be great, though!

@vogelsgesang
Copy link
Contributor Author

Unfortunately, I don't know how to write FF extensions. In a normal web page I would use the following snippet:

   window.addEventListener("keydown", function(evt) {
      if(evt.key == "s" && evt.ctrlKey) {
        window.location = "data:application/octet-stream;base64,"
          + btoa("Content of the downloaded file");
        evt.preventDefault();
      }
    });

While this does not bring up the native save dialog of FF, it allows to save the file contents to disk.
But I have no idea if this code would work in Firefox extensions.

@nqv
Copy link
Contributor

nqv commented May 29, 2014

As a workaround, I just "View Page Source" and copy the original JSON content from there :)

@vogelsgesang
Copy link
Contributor Author

Thanks for the hint. Makes life much easier :)

@TrangPham
Copy link
Contributor

I haven't had experience with this either, but I found some useful resources if someone wants to tackle this issue:

"The file picker component, nsIFilePicker, can be used to open standard Open / Save dialogs"
https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#User_input_via_nsIFilePicker

"Use of OS.File is preferred. Only use these legacy interfaces if OS.File is not available to you."
https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/OSFile.jsm/OS.File_for_the_main_thread#Example.3A_Write_a_string_to_a_file

@bhollis bhollis added this to the JSONView 1.0 milestone May 28, 2015
@bhollis
Copy link
Owner

bhollis commented May 30, 2015

Any solution would have to work for the "File > Save" menu item as well as the Cmd-S shortcut.

@bhollis bhollis removed this from the JSONView 1.0 milestone May 31, 2015
@Alexsey
Copy link

Alexsey commented Jul 16, 2015

How about adding shortcut to toggle addon? With page auto update, so when add-on off - we see raw json, and when on - nice html view.

Also, as option, icon, like one from ff customize menu, could be added to toggle view mode

@bhollis
Copy link
Owner

bhollis commented Jul 16, 2015

That would be a different feature request than this, but it's also not the sort of thing I'd add to the extension.

@mdibaiee
Copy link

As far as I know it's not possible to alter "File -> Save"s functionality, my idea is to add a button/link somewhere in the page, or a button in the toolbar / urlbar which would feel more native. A contextmenu item would work, too.

Alternatively, we could add a custom shortcut for that something like Cmd + Shift + S, but I don't like this idea.

If you agree, I will work on it.

@TrangPham
Copy link
Contributor

@mdibaiee I think using cmd + shift + s could work really well as a solution

@bhollis
Copy link
Owner

bhollis commented May 24, 2016

This appears to have been fixed at the platform level in Firefox. Save now saves the original document.

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

6 participants