Bookmarklet:
javascript:(function(a,p){function i(e){e.stopPropagation()};p[a]('keydown',i,!0);p[a]('keypress',i,!0);p[a]('keyup',i,!0);})('addEventListener',$('#wmd-input').parent()[0]);
User Script:
// ==UserScript==
// @name Cya WMD shortcuts
// @namespace Rob W
// @version 1.0
// @match https://stackoverflow.com/*
// @match https://*.stackoverflow.com/*
// @match https://superuser.com/*
// @match https://meta.superuser.com/*
// @match https://serverfault.com/*
// @match https://meta.serverfault.com/*
// @match https://askubuntu.com/*
// @match https://meta.askubuntu.com/*
// @match https://*.stackexchange.com/*
// @match https://stackapps.com/*
// @run-at document-end
// @grant none
// ==/UserScript==
(typeof unsafeWindow !== 'undefined' ? unsafeWindow : window).$(function() {
var p = document.getElementById('wmd-input');
if (!p) return;
p = p.parentNode;
function ignore(e){e.stopPropagation();}
p.addEventListener('keydown', ignore, true);
p.addEventListener('keypress', ignore, true);
p.addEventListener('keyup', ignore, true);
});
Technical details
- In the W3C event model, JavaScript events are fired in two ways:
- Capture (The events are fired, from the top of the document to the target)
- Bubble (The events bubble from the target to the top of the document).
- In
wmd.js
, the events are bound using addEventListener
, in the bubbling phase.
- The event is added to the parent node of the element, with the capturing flag. Inside the event listener,
event.stopPropagation();
is called, to stop the event from propagating further.
- As a result, all WMD shortcuts are disabled.
Chrome extension
- Create a directory, and store the following two files in it.
- Visit chrome://extensions/
- Enable Developer mode
- Click on the button Load unpacked extension....
- Select the directory from step 1.
manifest.json
{
"name": "Cya WMD shortcuts",
"manifest_version": 2,
"version": "1.0",
"content_scripts": [{
"js": ["contentscript.js"],
"matches": [
"https://stackoverflow.com/*",
"https://*.stackoverflow.com/*",
"https://superuser.com/*",
"https://meta.superuser.com/*",
"https://serverfault.com/*",
"https://meta.serverfault.com/*",
"https://askubuntu.com/*",
"https://meta.askubuntu.com/*",
"https://*.stackexchange.com/*",
"https://stackapps.com/*"
]
}]
}
contentscript.js
var p = document.getElementById('wmd-input');
if (p) {
p = p.parentNode;
var ignore = function(e){e.stopPropagation();};
p.addEventListener('keydown', ignore, true);
p.addEventListener('keypress', ignore, true);
p.addEventListener('keyup', ignore, true);
}
Heading
shortcut).Ctrl-B
for moving the cursor back is not "Emacs Voodoo" as suggested above, it's a standard keyboard command in macOS that works everywhere. Well, except for SO.Ctrl-B
does not work.Ctrl-N
,Ctrl-P
,Ctrl-B
,Ctrl-F
,Ctrl-A
, andCtrl-K
in macOS in all kinds of applications and on all kinds of websites in different browsers. For me these commands just work everywhere out of the box. Only on Stack OverflowCtrl-B
andCtrl-K
do not work because they remapped them without an option to disable that.