Last active
December 25, 2018 15:50
-
-
Save blogmonomono/cec7adc18e1ecdc8a0345d89b5d62646 to your computer and use it in GitHub Desktop.
はてなブログの入力ショートカットを追加する拡張
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 はてなブログ記事作成画面でショートカットキーを追加する。 | |
// @namespace http://www.monomono-blog.com/ | |
// @version 1.3 | |
// @description はてなブログの記事作成画面でのショートカットを追加します。 | |
// @author @BlogMonoMono | |
// @match http://blog.hatena.ne.jp/*/*/edit* | |
// @match https://blog.hatena.ne.jp/*/*/edit* | |
// @grant none | |
// @require http://code.jquery.com/jquery-latest.js | |
// ==/UserScript== | |
/* | |
Command + Shift + L 箇条書きリストを作成/解除 | |
Command + Shift + O 番号月リストを作成/解除 | |
Command + K URLリンクを設定 | |
(Windowsの場合はCommandの代わりにCtrlキーで動作します) | |
*/ | |
var $ = window.jQuery; | |
$(function($){ | |
// はてなブログの記事編集欄 iframe#body_ifr でのキーイベントで判定する。 | |
$(document.getElementById('body_ifr').contentWindow.document).keydown(detectShortcutKey); | |
/** | |
* ショートカットキーが押されているかの判定をする。 | |
* | |
* @param e キーイベント | |
* @return キーイベントを伝えるかどうか | |
*/ | |
function detectShortcutKey(e){ | |
// 特殊キーの状態 | |
var shift = (e.shiftKey); | |
var ctrl = (e.ctrlKey); | |
var alt = (e.altKey); | |
var meta = (e.metaKey); // MacでのCommandキー | |
// 各キーコード | |
var keyCodeB = 66; | |
var keyCodeK = 75; | |
var keyCodeL = 76; | |
var keyCodeO = 79; | |
if((ctrl || meta) && shift && e.keyCode == keyCodeL){ | |
// command+shift+L で リストボタン | |
$("button.button-unorderedList.toolbar-button.tipsy-top").click(); | |
preventEvent(e); | |
return false; | |
}else if((ctrl || meta) && shift && e.keyCode == keyCodeO){ | |
// command+shift+O で リストボタン | |
$("button.button-orderedList.toolbar-button.tipsy-top").click(); | |
preventEvent(e); | |
return false; | |
} else if((ctrl || meta) && e.keyCode == keyCodeK){ | |
// command+K で リンクボタン | |
$("button.button-link.toolbar-button.tipsy-top").click(); | |
preventEvent(e); | |
return false; | |
} | |
return true; | |
} | |
/** | |
* キーイベントが伝搬されるのを防ぐ。 | |
*/ | |
function preventEvent(key_event){ | |
if (key_event.stopPropagation) { | |
key_event.stopPropagation(); | |
key_event.preventDefault(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment