Last active
April 14, 2021 00:33
Star
You must be signed in to star a gist
Keyboard shortcuts for GitHub markdown editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GitHub Markdown shortcuts | |
// @namespace ThomasLevesque | |
// @include https://github.com/* | |
// @include https://gist.github.com/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
var shortcuts = [ | |
{ keyCode: 75, command: "code" }, // Ctrl+K | |
{ keyCode: 76, command: "link" }, // Ctrl+L | |
]; | |
function findToolbarForTextArea(textArea) { | |
var div = textArea.parents(".previewable-comment-form").first(); | |
return div.find(".toolbar-commenting").first(); | |
} | |
function findToolbarButtonForTextArea(textArea, buttonName) { | |
var toolbar = findToolbarForTextArea(textArea); | |
return toolbar.find("button[data-ga-click='Markdown Toolbar, click, " + buttonName + "']").first(); | |
} | |
function clickToolbarButton(textArea, buttonName) { | |
var button = findToolbarButtonForTextArea(textArea, buttonName); | |
button.click(); | |
} | |
function processShortcut(textArea, e) { | |
if (e.ctrlKey) { | |
for each (var s in shortcuts) { | |
if (e.keyCode == s.keyCode) { | |
clickToolbarButton(textArea, s.command); | |
e.stopImmediatePropagation(); | |
e.preventDefault(); | |
break; | |
} | |
} | |
} | |
} | |
function setupShortcuts() { | |
$(".comment-form-textarea").unbind(); | |
$(".comment-form-textarea").keydown(function(e) { | |
processShortcut($(this), e); | |
}); | |
} | |
function handleSetupShortcut(e) | |
{ | |
if (e.ctrlKey && e.altKey && e.keyCode == 83) { | |
setupShortcuts(); | |
e.stopImmediatePropagation(); | |
e.preventDefault(); | |
} | |
} | |
$(document).ready(function(){ | |
$(document).keydown(handleSetupShortcut); | |
setTimeout(setupShortcuts, 1000); | |
}); |
@darkwater4213 yes, but these shortcuts are for "code" (ctrl+k) and "link" (ctrl+l)
To be honest, I'm not sure this still works...
Okay, then. Thanks for responding anyways!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By "shortcuts" do you mean things like Ctrl+i for
_ _
and Ctrl+b for** **
, or something else?