Skip to content

Instantly share code, notes, and snippets.

@tondol
Last active December 14, 2015 03:49
Show Gist options
  • Save tondol/5024104 to your computer and use it in GitHub Desktop.
Save tondol/5024104 to your computer and use it in GitHub Desktop.
dashboardのショートカットキーをカスタマイズする
// ==UserScript==
// @name tumblr_hook.user.js
// @namespace http://tondol.com
// @description dashboardのショートカットキーをカスタマイズする
// @include http://www.tumblr.com/dashboard
// @include http://www.tumblr.com/dashboard/*
// @version 0.1
// ==/UserScript==
// 参考:
// http://jsbin.com/awenaq/4
// http://subtech.g.hatena.ne.jp/secondlife/20091228/1262001989
var executeBrowserContext = function(f) {
var code = f.toString();
var script = document.createElement("script");
script.textContent = '(' + code + ')();';
document.body.appendChild(script);
};
executeBrowserContext(function() {
var useHooking = function(e) {
// E, R
return e.which == 69 || e.which == 82;
};
var createEvent = function(charCode, optionKey) {
var e = document.createEvent('KeyboardEvent');
Object.defineProperty(e, 'charCode', {
get: function() { return charCode; }
});
Object.defineProperty(e, 'shiftKey', {
get: function() { return optionKey; }
});
Object.defineProperty(e, 'altKey', {
get: function() { return optionKey; }
});
return e;
};
var createNewEvent = function(e) {
// E, R
if (e.which == 69 || e.which == 82) {
return createEvent(e.which, !(e.altKey || e.shiftKey));
} else {
return e;
}
};
document.addEventListener('keydown', function(e) {
if (useHooking(e)) {
e.stopPropagation();
Tumblr.KeyCommands.keydown(createNewEvent(e));
}
}, true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment