About
This userscript adds keyboard shortcuts to StackExchange comments. The default ones are: Ctrl+B (bold), Ctrl+I (italic), Ctrl+K (code), and Ctrl+L (link). You can yourself extend this with more custom Ctrl + single_key shortcuts as required (Ctrl+U
can give UNICORNselectionUNICORN
;) ).
This extension works the same way as the actual StackExchange editor works:
such that pressing Ctrl+B with nothing selected inserts a placeholder (**strong text**
), while pressing Ctrl+B with existing bold text un-boldens it. Trailing whitespaces are also handled similarly.
For links, this uses the prompt()
dialog box. It automatically prepends http://
as a default, otherwise the inline Markdown links don't work.
The only difference from the SE editor is that this userscript uses the single underscore (_
) instead of the single asterisk (*
) for italics as a default. This is mainly to prevent clashes between bold and italics form (and their wrapping and unwrapping) when they are nested.
###Download
GitHub - Install link and View source
Platform
Tested on Chrome 66 (Tampermonkey) and Firefox 60 (Greasemonkey) on Windows 10
Notes:
- How to extend this with custom shortcuts?
- open the source with your local monkey and head over to around line 35 at the declaration
var WRAPPERS =
- each wrapper uses the format:
keycode: ["placeholder", "delimiter"]
which I think is fairly straightforward - so, for the above example, just do
85: ["unicornify!", "UNICORN"]
. Also, don't forget the comma to separate this from the previous wrapper! - you can get the keycode for your key via http://keycode.info
- This userscript differs from the previous one as:
- it didn't allow custom wrappers
- it didn't work the same way the SE editor does (specifically, you needed to press Ctrl+B twice, also it had no support for un-boldening)
- This userscript is currently a beta release, and will be updated as a formal release after a week's testing.
License
Do whatever you wish to do, just don't sell this for money (but may use it in a commercial software's code) or state that you made it yourself. Do post here an answer if you do something cool with this :D
Contribute
Post bugs or feature requests as answers below!