Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save syoichi/2963498 to your computer and use it in GitHub Desktop.
Save syoichi/2963498 to your computer and use it in GitHub Desktop.
「Ctrl + H」などで実行されないように変更した。
// ==UserScript==
// @id Add HatenaB keybind
// @name Add HatenaB keybind
// @namespace http://b.hatena.ne.jp/saitamanodoruji
// @author saitamanodoruji
// @version 0.0.2
// @update 2012-06-21T11:38:32.981Z(GMT+09:00)
// @description はてなブックマークにショートカットキーを追加する。
// @include http://b.hatena.ne.jp/*
// @run-at document-end
// @priority 0
// @compatibility Firefox 13.0.1(Scriptish 0.1.7), Chrome 19.0.1084.56, Safari 5.1.7(NinjaKit 0.9.1) on Windows 7 Home Premium SP1 64bit
// @charset UTF-8
// ==/UserScript==
// keybind
// m: 「みんなのブックマーク」を開く
// h: 「すべて表示」をクリックする
/*jslint browser: true, maxlen: 110*/
/*global GM_openInTab*/
// Edition 2012-05-09
(function executeAddKeybind(win, doc) {
'use strict';
var anchor, click, clickViewAll, openBookmarkPage, executeCommand, commands;
anchor = doc.createElement('a');
click = doc.createEvent('MouseEvent');
clickViewAll = function clickViewAll() {
var viewAll;
viewAll = doc.querySelector(
':not(.show-all-comment) > .current-element ~ .entry-comment .toggle-show'
);
if (!viewAll) {
return;
}
viewAll.dispatchEvent(click);
};
openBookmarkPage = function openBookmarkPage() {
var entryLink, bookmarkPageURL, openInTab, mdlClick;
entryLink = doc.querySelector('.current-element > .entry-link');
if (!entryLink) {
return;
}
bookmarkPageURL = 'http://b.hatena.ne.jp/entry?mode=more&url=' + entryLink.href;
if (/Gecko\//.test(win.navigator.userAgent)) {
openInTab = GM_openInTab;
openInTab(bookmarkPageURL, true);
return;
}
mdlClick = doc.createEvent('MouseEvent');
anchor.href = bookmarkPageURL;
mdlClick.initMouseEvent('click', true, true, win, 1, 0, 0, 0, 0, false, false, false, false, 1, null);
anchor.dispatchEvent(mdlClick);
};
commands = {
'h': clickViewAll,
'm': openBookmarkPage
};
executeCommand = function executeCommand(evt) {
var command;
if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) {
return;
}
command = commands[String.fromCharCode(evt.which).toLowerCase()];
if (!command) {
return;
}
command();
};
click.initMouseEvent('click', true, true, win, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
win.addEventListener('keydown', executeCommand);
}(window, document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment