1
\$\begingroup\$

When reviewing, I often find myself copying the source to open in an IDE locally. Maybe we could add a button to download the source snippets to help facilitate this?

\$\endgroup\$
5
  • \$\begingroup\$ To copy from a website to your editor? Or just to copy the code block? \$\endgroup\$
    – Peilonrayz Mod
    Commented Aug 24, 2016 at 17:43
  • \$\begingroup\$ @JoeWallis To download the snippet to a file with the correct extension. \$\endgroup\$
    – rookie
    Commented Aug 24, 2016 at 17:46
  • 1
    \$\begingroup\$ There have been regulars doing something like this already. If you give me a minute I'll make it an answer. \$\endgroup\$
    – Mast Mod
    Commented Aug 24, 2016 at 17:47
  • \$\begingroup\$ Possibly related: codereview.stackexchange.com/a/41210/31562 . I think the best bet would be to make a userscript for it, possibly one that provides a link or makes a request to some webservice that fetches the post and provides a downloadable file. I don't really expect Stack Exchange to provide a feature for this. \$\endgroup\$
    – Simon Forsberg Mod
    Commented Aug 24, 2016 at 17:47
  • \$\begingroup\$ The question got closed before I could finish my answer, see the answer on the linked question instead. As far as the request itself goes, I don't give it much chance. Sure, it would be great. But it would have to support quite some languages and we review the weirdest things here. It would be quite a heavy feature relevant for only one site. \$\endgroup\$
    – Mast Mod
    Commented Aug 25, 2016 at 10:46

1 Answer 1

2
\$\begingroup\$

I have the following code in a toolbar button's URL:

javascript: $('pre.prettyprint').not('button + *').each( function()  {     /* Thank you http://stackoverflow.com/a/2838358/7602 */    function selectCode(el, win)     {      win = win || window;      var doc = win.document, sel, range;      if (win.getSelection && doc.createRange)       {        sel = win.getSelection();        range = doc.createRange();        range.selectNodeContents(el);        sel.removeAllRanges();        sel.addRange(range);      }       else if (doc.body.createTextRange)       {        range = doc.body.createTextRange();        range.moveToElementText(el);        range.select();      }    }    var buttonText  = 'Select Code',        length      = buttonText.length,        codeBlock   = this,        $link       = $('<button type=\'button\'>' + buttonText + '</button>').click(function()        {          console.log( $(codeBlock).text().substring( length ) );          selectCode(codeBlock);        });    $(codeBlock).before( $link );  });void(0);

I cannot recall where I found it.

It then becomes a button on your Chrome toolbar that, when you press, adds "Select Code" to each code block in the question/answer......

enter image description here

\$\endgroup\$
1

Not the answer you're looking for? Browse other questions tagged .