Created
June 20, 2012 21:07
-
-
Save saitamanodoruji/2962226 to your computer and use it in GitHub Desktop.
Add HatenaB Keybind
This file contains hidden or 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== | |
// @id Add HatenaB Keybind | |
// @name Add HatenaB Keybind | |
// @version 0.0.1.1 | |
// @namespace http://b.hatena.ne.jp/saitamanodoruji | |
// @author saitamanodoruji | |
// @description はてなブックマークにショートカットキーを追加する | |
// @include http://b.hatena.ne.jp/* | |
// @run-at document-end | |
// ==/UserScript== | |
// keybind | |
// m: 「みんなのブックマーク」を開く | |
// h: 「すべて表示」をクリックする | |
(function executeAddKeybind(win, doc) { | |
var click = function(n) { | |
var e = doc.createEvent('MouseEvents'); | |
e.initMouseEvent( | |
'click', true, true, win, | |
1, 0, 0, 0, 0, false, false, false, false, 0, null | |
); | |
n.dispatchEvent(e); | |
}; | |
var execute = function(e) { | |
if ( e.altKey || e.ctrlKey || e.metaKey || e.shiftKey ) return; | |
if ( String.fromCharCode(e.charCode) == 'h' ) { | |
var trigger = doc.querySelector( | |
':not(.show-all-comment) > .current-element ~ ' + | |
'.entry-comment .toggle-show' | |
); | |
if (trigger) click(trigger); | |
} else if ( String.fromCharCode(e.charCode) == 'm') { | |
var url = doc.querySelector( | |
'.current-element .entry-link' | |
).href; | |
GM_openInTab( | |
'http://b.hatena.ne.jp/entry?mode=more&url=' + url, | |
true | |
); | |
} | |
} | |
doc.addEventListener('keypress', execute, false); | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment