Skip to content

Instantly share code, notes, and snippets.

@mooz
Created February 19, 2010 13:43
Show Gist options
  • Save mooz/308705 to your computer and use it in GitHub Desktop.
Save mooz/308705 to your computer and use it in GitHub Desktop.
// ========================== KeySnail Init File =========================== //
// この領域は, GUI により設定ファイルを生成した際にも引き継がれます
// 特殊キー, キーバインド定義, フック, ブラックリスト以外のコードは, この中に書くようにして下さい
// ========================================================================= //
//{{%PRESERVE%
userscript.addLoadPath("~/programming/js");
// Prompt settings {{ ======================================================= //
prompt.rows = 15;
prompt.useMigemo = true;
prompt.migemoMinWordLength = 3;
prompt.displayDelayTime = 200;
prompt.setActionKey("selector", "?", "prompt-display-keymap-help");
// }} ======================================================================= //
// Misc {{ ================================================================== //
// keyboard macro
macro.sleepTime = 50;
// kill ring
command.kill.killRingMax = 15;
command.kill.textLengthMax = -1;
// }} ======================================================================= //
// Dabbrev {{ =============================================================== //
plugins.options["dabbrev.next_key"] = "C-j";
plugins.options["dabbrev.prev_key"] = "C-k";
plugins.options["dabbrev.candidates"] = [
"stillpedant",
"stillpedant@gmail.com"
];
// }} ======================================================================= //
// KKK {{ =================================================================== //
plugins.options["kkk.sites"] = ["^http://([0-9a-zA-Z]+\\.)?github\\.com/"];
// }} ======================================================================= //
// Yatck {{ ================================================================= //
plugins.options["twitter_client.timeline_count_every_updates"] = 20;
plugins.options["twitter_client.log_level"] = 0;
plugins.options["twitter_client.popup_new_statuses"] = false;
plugins.options["twitter_client.keymap"] = {
"C-z" : "prompt-toggle-edit-mode",
"SPC" : "prompt-next-page",
"b" : "prompt-previous-page",
"j" : "prompt-next-completion",
"k" : "prompt-previous-completion",
"g" : "prompt-beginning-of-candidates",
"G" : "prompt-end-of-candidates",
"q" : "prompt-cancel",
// local
"t" : "tweet",
"r" : "reply",
"R" : "retweet",
"D" : "delete-tweet",
"f" : "add-to-favorite",
"v" : "display-entire-message",
"V" : "view-in-twitter",
"c" : "copy-tweet",
"i" : "copy-user-id",
"s" : "show-target-status",
"@" : "show-mentions",
"/" : "search-word",
"o" : "open-url,n",
">" : "select-next-filter",
"<" : "select-previous-filter"
};
plugins.options["twitter_client.tweet_keymap"] = {
"C-RET" : "prompt-decide",
"RET" : ""
};
// }} ======================================================================= //
// Bmany {{ ================================================================= //
plugins.options["bmany.default_open_type"] = "tab";
plugins.options["bmany.keymap"] = {
"O" : "open-background-tab,cn"
};
// }} ======================================================================= //
// K2Emacs {{ =============================================================== //
// sync with keysnails editor
plugins.options["K2Emacs.editor"] = util.getUnicharPref("extensions.keysnail.userscript.editor");
// }} ======================================================================= //
// Prefer LDRize {{ ========================================================= //
plugins.options["prefer_ldrize.keymap"] = {
"j" : null,
"k" : null,
"p" : null,
"v" : null,
"o" : null
};
plugins.options["prefer_ldrize.black_list"] = [
"www\\.youtube\\.com/watch.*",
"(www|tw|es|de|)\\.nicovideo\\.jp/watch/.*"
];
// }} ======================================================================= //
// Site local keymap {{ ===================================================== //
var local = {};
plugins.options["remap_pages.local_keymap"] = local;
function fake(k, i, type) function () { key.feed(k, i, type); };
function pass(k, i, type) [k, fake(k, i, type)];
function ignore(k) [k, null];
local["^https?://mail.google.com/mail/"] = [
pass(['g', 'i'], 3),
pass(['g', 's'], 3),
pass(['g', 't'], 3),
pass(['g', 'd'], 3),
pass(['g', 'a'], 3),
pass(['g', 'b'], 3),
pass(['g', 'c'], 3),
pass(['g', 'k'], 3),
// thread list
pass(['*', 'a'], 3),
pass(['*', 'n'], 3),
pass(['*', 'r'], 3),
pass(['*', 'u'], 3),
pass(['*', 's'], 3),
pass(['*', 't'], 3),
// navigation
['u', null],
['k', null],
['j', null],
['k', null],
['o', null],
['p', null],
['n', null],
// application
['c', null],
['/', null],
['q', null],
['?', null],
// manipulation
['x', null],
['s', null],
['y', null],
['e', null],
['m', null],
['!', null],
['#', null],
['r', null],
['R', null],
['a', null],
['A', null],
['f', null],
['F', null],
['N', null],
pass(['<tab>', 'RET'], 3),
['ESC', null],
[']', null],
['[', null],
['z', null],
['.', null],
['I', null],
['U', null],
['C-s', null],
['T', null]
];
local["^http://www.google.(co.jp|com)/reader/view/"] = [
// jump
pass(["g", "h"]),
pass(["g", "a"]),
pass(["g", "s"]),
pass(["g", "S"]),
pass(["g", "u"]),
pass(["g", "t"]),
pass(["g", "T"]),
pass(["g", "d"]),
pass(["g", "f"]),
pass(["g", "F"]),
pass(["g", "c"]),
pass(["g", "C"]),
pass(["g", "e"]),
pass(["g", "p"]),
// navigation
["j", null],
["k", null],
["n", null],
["p", null],
["N", null],
["P", null],
["X", null],
["o", null],
// item
["s", null],
["L", null],
// ["t", null],
// ["e", null],
["S", null],
["d", null],
["v", null],
["o", null],
["c", null],
["C", null],
["m", null],
["A", null],
["T", null],
// application
["u", null],
["1", null],
["2", null],
["/", null],
["a", null],
["=", null],
["-", null],
// reblog
["r", function () {
let link = content.document.querySelector("#current-entry a.entry-title-link");
if (link && plugins.kungfloo)
plugins.kungfloo.reblog(link, false, false, ["FFFFOUND", "Flickr", "Tumblr"]);
}]
];
local["^http://www.youtube.com/watch"] = [
["p" , function () { key.feed("M-p"); }],
["q" , function () { key.feed("M-q"); }],
["9" , null],
["0" , null],
["m" , function () { key.feed("M-m"); }],
["," , null],
["." , null],
["<" , null],
[">" , null]
];
local["^http://(www|tw|es|de|).nicovideo.jp/watch/*"] = [
["i", function (ev, arg) { ext.exec("nicoinfo", arg); }],
["p", function (ev, arg) { ext.exec("nicopause", arg); }],
["m", function (ev, arg) { ext.exec("nicomute", arg); }],
["r", function (ev, arg) { ext.exec("nicorepeat", arg); }],
["z", function (ev, arg) { ext.exec("nicosize", arg); }],
["h", function (ev, arg) { ext.exec("nicommentvisible", arg); }],
[".", function (ev, arg) { ext.exec("nicoseekForward", 10); }],
[",", function (ev, arg) { ext.exec("nicoseekBackward", 10); }],
["0", function (ev, arg) { ext.exec("nicovolumeIncrement", 20); }],
["9", function (ev, arg) { ext.exec("nicovolumeDecrement", 20); }],
["-", function (ev, arg) { ext.exec("nicovolume", 100); }]
];
// }} ======================================================================= //
// Unfuck your enemies {{ =================================================== //
plugins.options["unfuck_your_enemies.site_info"] = {
"http://github\\.com/[^/]+/[^/]+/raw/.+/([^?]+)": {
xpi: ["application/x-xpinstall", "attachment"]
},
"http://[^\.]+\\.googlecode\\.com/issues/attachment?(?:.*&name|name)=([^&]+)": {
js : ["text/plain", "inline"]
},
"http://[^\.]+\\.googlecode\\.com/files/([^?]+)": {
js : "text/plain"
}
};
// }} ======================================================================= //
// HoK {{ =================================================================== //
plugins.options["hok.user_keymap"] = {};
plugins.options["hok.user_keymap"]["C-m"] = "Enter";
plugins.options["hok.local_queries"] = [
["^http://www\\.google\\.(co\\.jp|com)/reader/view/",
"*.unselectable, *.link, *.section-button"],
["^http://b\\.hatena\\.ne\\.jp/entry/",
"span.hatena-star-add-button, li#pin-header img, span#colorselecter"],
["^http://www.google.co.jp/ig",
"*.subject, *.thread"]
];
// }} ======================================================================= //
// Tanything {{ ============================================================= //
plugins.options["tanything_opt.keymap"] = {
"C-z" : "prompt-toggle-edit-mode", //ローカルキーバインドモードを抜けて編集モードに移行
"SPC" : "prompt-next-page",
"b" : "prompt-previous-page", //前のページに移動
"j" : "prompt-next-completion", //次のアイテムに移動
"k" : "prompt-previous-completion", //前のアイテム移動
"g" : "prompt-beginning-of-candidates", //最初のアイテムに移動
"G" : "prompt-end-of-candidates", //最後のアイテムに移動
"q" : "prompt-cancel", //プロンプトを消す
//
"o" : "localOpen", //選択したタブを開く
"d" : "localClose", //選択したタブを閉じる
"K" : "localLeftclose",
"J" : "localRightclose",
"*" : "localAllclose",
"D" : "localDomainclose",
"c" : "localClipUT", //選択したタブのタイトルとURLをHTMLタグつきでコピー
"C" : "localClipU", //選択したタブのURLをHTMLタグつきでコピー
"e" : "localMovetoend", //選択したタブを末尾に移動
"a" : "localMovetostart", //選択したタブを先頭に移動
"B" : "localAddBokmark"
};
// }} ======================================================================= //
// Exts {{ ================================================================== //
function followRel(doc, pattern) {
let link = doc.querySelector(util.format('a[rel~="%s"]', pattern));
plugins.hok.followLink(link, plugins.hok.CURRENT_TAB);
}
ext.add("follow-next-link", function () { followRel(content.document, "next"); }, "follow next link");
ext.add("follow-prev-link", function () { followRel(content.document, "prev"); }, "follow previous link");
ext.add("hatena-bookmark-popular-entries", function () {
let head = (content.location.href.match("([a-z]+://[^/]+)/?") || {0:null})[0];
if (head)
openUILinkIn("http://b.hatena.ne.jp/entrylist?sort=count&url=" + encodeURIComponent(head), "tab");
}, "このサイトのはてなブックマーク人気エントリーを一覧表示");
ext.add("source", function () {
let plugins = util.readDirectory(userscript.pluginDir, true)
.filter(function (file) !(file.leafName.match("^_.+\\.ks\\.js$") ||
!file.leafName.match("\\.ks\\.js$") ||
file.isDirectory()));
prompt.selector(
{
message : "reload plugin:",
collection : plugins.map(function (f) f.leafName),
callback : function (i) { if (i >= 0) userscript.loadPlugin(plugins[i]); }
});
}, "Load specified plugin");
(function () {
function props(obj) [k for ([k, v] in new Iterator(obj)) if (typeof k === "string")];
// old, new
function diff(o, n) {
return {
added : n.filter(function (e1) o.every(function (e2) e1 !== e2)),
removed : o.filter(function (e1) n.every(function (e2) e1 !== e2))
};
}
const name = "window-members";
ext.add("garbage-finder-store", function () {
let member = props(window);
persist.preserve(member, name);
}, "Garbage Finder - Store");
ext.add("garbage-finder-check", function () {
let oldMember = persist.restore(name);
let result = diff(oldMember, props(window));
util.message("Added:\n" + result.added.join("\n"));
util.message("Removed:\n" + result.removed.join("\n"));
}, "Garbage Finder - Check");
})();
ext.add("xul-test", function () {
function createDataURI(aXML) {
const header = 'data:text/xml;charset=utf-8,';
return header + encodeURIComponent(aXML.toString()).replace(/(\r|\n)/g, "");
}
var test = '<?xml version="1.0"?>'
+ '<?xml-stylesheet href="chrome://global/skin" type="text/css"?>'
+ '<dialog id="hoge-huga" title="Hoge Huga"'
+ ' xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"'
+ ' xmlns:html="http://www.w3.org/1999/xhtml" buttons="accept,cancel">'
+ '<vbox flex="1">'
+ '<description>てすと</description>'
+ '<listbox flex="1">'
+ '<listitem label="Ruby"/>'
+ '<listitem label="Emerald"/>'
+ '<listitem label="Sapphire" selected="true"/>'
+ '<listitem label="Diamond"/>'
+ '</listbox>'
+ '</vbox>'
+ '</dialog>';
window.openDialog(createDataURI(test), "hogehuga", "chrome,titlebar,centerscreen,resizable", "hoge-huga");
}, "XUL TEST");
ext.add("list-closed-tabs", function () {
const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
var closedTabs = [[tab.image || fav, tab.title] for each (tab in json.decode(ss.getClosedTabData(window)))];
if (!closedTabs.length)
return void display.echoStatusBar("最近閉じたタブが見つかりませんでした", 2000);
prompt.selector(
{
message : "select tab to undo:",
collection : closedTabs,
flags : [ICON | IGNORE, 0],
callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
});
}, "List closed tabs");
ext.add("show-all-history", function() {
PlacesCommandHook.showPlacesOrganizer('History');
}, "show-all-history");
ext.add("addon-manager", function() {
gBrowser.loadURI('chrome://mozapps/content/extensions/extensions.xul');
}, "addon-manager");
ext.add("manage-password", function() {
window.open('chrome://passwordmgr/content/passwordManager.xul', 'Toolkit:PasswordManager', 'chrome,resizable=yes');
}, "manage-password");
ext.add("open-keysnail-plugin-manager", function() {
KeySnail.UserScript.openPluginManager();
}, "open-keysnail-plugin-manager");
ext.add("change-locale-to-english", function () {
util.setUnicharPref("general.useragent.locale", "en-US");
}, "英語へ切り替え");
ext.add("change-locale-to-japanese", function () {
util.setUnicharPref("general.useragent.locale", "ja");
}, "日本語へ切り替え");
ext.add("open-init-file-wizard", function () {
userscript.openDialog();
}, "初期化ファイル作成ウィザード");
ext.add("download-statusbar-clear", function () { db_clearAll(); }, "Download Statusbar をクリア");
ext.add("change-style-sheet", function () {
style.toggle(style.local("img { display:none; }", window.content.location.href), style.XHTML);
}, "Stylish!");
ext.add("generate-plugin-table", function () {
function getEn(aNodes) {
if (typeof aNodes == "string")
return aNodes;
var length = aNodes.length();
if (length == 0)
return "";
var text = aNodes[0].text();
return text.length ? text : "";
}
var defaultIconURL = "http://github.com/mooz/keysnail/raw/master/skin/classic/keysnail/script.png";
for each (var plugin in plugins.context)
{
var info = plugin.PLUGIN_INFO;
if (!info)
continue;
var iconURL = getEn(info.iconURL) || defaultIconURL;
var updateURL = getEn(info.updateURL);
var pluginName = getEn(info.name);
var pluginDescription = getEn(info.description);
var authorHomePageURL = getEn(info.author.@homepage);
var authorName = getEn(info.author);
var table =
<tr>
<td><img src={iconURL} /></td>
<td><a href={updateURL}>{pluginName}</a></td>
<td>{pluginDescription}</td>
<td><a href={authorHomePageURL}>{authorName}</a></td>
</tr>;
util.message(table);
}
}, "プラグインリストのテーブルを生成");
ext.add("growl", function () {
var length = Math.round(200 * Math.random());
plugins.lib.xulGrowl.update(
{title: "こんにちはこんにちは!",
message: Array(length).join("j"),
link: "http://www.google.co.jp/"});
}, "notify");
ext.add("toggle-autopagerize", function (ev, arg) {
plugins.hok.followLink(
content.document.querySelector('div#autopagerize_help > div > a.autopagerize_link')
);
}, M({ja: "Autopagerize の ON / OFF 切り替え",
en: "Toggle Autopagerize status"}));
// }} ======================================================================= //
//}}%PRESERVE%
// ========================================================================= //
// ========================= Special key settings ========================== //
key.quitKey = "C-g";
key.helpKey = "<f1>";
key.escapeKey = "C-q";
key.macroStartKey = "<f3>";
key.macroEndKey = "<f4>";
key.universalArgumentKey = "C-u";
key.negativeArgument1Key = "";
key.negativeArgument2Key = "C-M--";
key.negativeArgument3Key = "M--";
key.suspendKey = "<f2>";
// ================================= Hooks ================================= //
hook.setHook('KeyBoardQuit', function (aEvent) {
if (key.currentKeySequence.length) {
return;
}
command.closeFindBar();
var marked = command.marked(aEvent);
if (util.isCaretEnabled()) {
if (marked) {
command.resetMark(aEvent);
} else {
if ("blur" in aEvent.target) {
aEvent.target.blur();
}
gBrowser.focus();
_content.focus();
}
} else {
goDoCommand("cmd_selectNone");
}
if (KeySnail.windowType === "navigator:browser" && !marked) {
key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
}
});
// ============================= Key bindings ============================== //
key.setGlobalKey('C-i', function (ev) {
if (ev.target === document.getElementById("keysnail-prompt-textbox")) {
ev.target.dispatchEvent(key.stringToKeyEvent("C-i", true));
}
}, 'Tame C-i');
key.setGlobalKey(['C-x', 'b'], function (aEvent, aArg) {
var tabs = gBrowser.mTabContainer.childNodes;
var collection = [];
for (var i = 0; i < tabs.length; ++i) {
collection.push([tabs[i].image, tabs[i].label, tabs[i].linkedBrowser.contentDocument.URL]);
}
prompt.selector({
message: "pattern:",
callback: function (aIndex) {
if (aIndex >= 0) {
gBrowser.mTabContainer.selectedIndex = aIndex;
}
},
collection: collection,
header: ["Title", "URL"],
flags: [ICON | IGNORE, 0, 0]
});
}, '現在開いているタブ一覧を表示 & ジャンプ');
key.setGlobalKey(['C-x', 'g'], function () {
command.focusToById("searchbar");
}, '検索バーへフォーカス', true);
key.setGlobalKey(['C-x', 'K'], function (ev) {
closeWindow(true);
}, 'ウィンドウを閉じる');
key.setGlobalKey(['C-x', 'n'], function (ev) {
ev.originalTarget.dispatchEvent(key.stringToKeyEvent("C-n", true));
}, 'ウィンドウを開く');
key.setGlobalKey(['C-x', 'C-c'], function (ev) {
ev.originalTarget.dispatchEvent(key.stringToKeyEvent("C-q", true));
}, 'Firefox を終了');
key.setGlobalKey(['C-x', 'C-w'], function () {
saveDocument(window.content.document);
}, 'ファイルを保存');
key.setGlobalKey(['C-x', 'C-f'], function () {
BrowserOpenFileWindow();
}, 'ファイルを開く');
key.setGlobalKey(['C-x', '1'], function (aEvent) {
window.loadURI(aEvent.target.ownerDocument.location.href);
}, '現在のフレームだけを表示');
key.setGlobalKey(['C-x', '0'], function (ev, arg) {
SplitBrowser.activeBrowserCloseWindow();
}, '現在のフレームを閉じる');
key.setGlobalKey(['C-x', '2'], function (ev, arg) {
SplitBrowser.addSubBrowser(window.content.location.href, SplitBrowser.activeSubBrowser, SplitBrowser.POSITION_BOTTOM);
}, 'フレームを横に分割');
key.setGlobalKey(['C-x', '3'], function (ev, arg) {
SplitBrowser.addSubBrowser(window.content.location.href, SplitBrowser.activeSubBrowser, SplitBrowser.POSITION_RIGHT);
}, 'フレームを縦に分割');
key.setGlobalKey(['C-x', 'o'], function (aEvent, aArg) {
command.focusOtherFrame(aArg);
}, '次のフレームを選択', true);
key.setGlobalKey(['C-x', 'z'], function (aEvent, aArg) {
var savedLastFunc = key.lastFunc;
if (!savedLastFunc) {
return;
}
hook.hookList.PostCommand = [function (hookarg) {
key.lastFunc = savedLastFunc;
delete hook.hookList.PostCommand;
}];
key.lastFunc(aEvent, aArg);
}, 'ひとつ前のコマンドを繰り返す');
key.setGlobalKey(['C-x', ';'], function (ev, arg) {
ext.exec("list-hateb-items", arg);
}, 'はてなブックマークのアイテムを一覧表示', true);
key.setGlobalKey(['C-x', 'k'], function (ev) {
document.dispatchEvent(key.stringToKeyEvent("C-w", true));
}, 'タブ / ウィンドウを閉じる');
key.setGlobalKey(['C-x', 'r', 'l'], function (ev, arg) {
ext.exec("bmany-list-all-bookmarks", arg, ev);
}, 'ブクマ一覧', true);
key.setGlobalKey(['C-x', 'r', 'SPC'], function (ev, arg) {
ext.exec("scrollet-set-mark", arg, ev);
}, 'Scrollet - マークをセット');
key.setGlobalKey(['C-x', 'r', 'j'], function (ev, arg) {
ext.exec("scrollet-jump-to-mark", arg, ev);
}, 'Scrollet - マークへジャンプ');
key.setGlobalKey(['C-c', 'b'], function (ev, arg) {
var elem = document.commandDispatcher.focusedElement;
if (elem) {
elem.blur();
}
gBrowser.focus();
_content.focus();
}, 'コンテンツにフォーカス', true);
key.setGlobalKey(['C-c', 'C-f'], function (ev, arg) {
var toolbox = document.getElementById("navigator-toolbox");
toolbox.hidden = !toolbox.hidden;
if (arg || !toolbox.hidden) {
var statusbar = document.getElementById("status-bar");
statusbar.hidden = toolbox.hidden;
}
}, '擬似フルスクリーン状態の切り替え', true);
key.setGlobalKey(['C-c', 'C-c', 'C-v'], function () {
toJavaScriptConsole();
}, 'Javascript コンソールを表示');
key.setGlobalKey(['C-c', 'C-c', 'C-c'], function () {
command.clearConsole();
}, 'Javascript コンソールの表示をクリア');
key.setGlobalKey(['C-c', 'c', 'h'], function () {
var tabs = gBrowser.mTabContainer.childNodes;
for (var i = tabs.length - 1; tabs[i] != gBrowser.mCurrentTab; i--) {}
for (i--; i >= 0; i--) {
gBrowser.removeTab(tabs[i]);
}
}, '左側のタブを全て閉じる', true);
key.setGlobalKey(['C-c', 'c', 'l'], function () {
var tabs = gBrowser.mTabContainer.childNodes;
for (var i = tabs.length - 1; tabs[i] != gBrowser.selectedTab; i--) {
gBrowser.removeTab(tabs[i]);
}
}, '右側のタブを全て閉じる', true);
key.setGlobalKey(['C-c', 'C-n', 'C-t'], function (ev, arg) {
noscriptOverlay.allowPage(true);
}, 'NoScript - ページを一時許可');
key.setGlobalKey(['C-c', 't'], function (ev, arg) {
ext.exec("twitter-client-tweet", arg);
}, 'つぶやく', true);
key.setGlobalKey(['C-c', 'T'], function (ev, arg) {
ext.exec("twitter-client-tweet-this-page", arg);
}, 'このページのタイトルと URL を使ってつぶやく', true);
key.setGlobalKey(['C-c', 's'], function (aEvent, aArg) {
ext.exec("twitter-client-search-word", aArg);
}, 'Twitter 検索', true);
key.setGlobalKey(['C-c', 'p'], function (ev, arg) {
var p = document.getElementById("keysnail-prompt");
if (p.hidden) {
return;
}
document.getElementById("keysnail-prompt-textbox").focus();
}, 'プロンプトへフォーカス');
key.setGlobalKey('C-M-l', function () {
gBrowser.mTabContainer.advanceSelectedTab(1, true);
}, 'ひとつ右のタブへ');
key.setGlobalKey('C-M-h', function () {
gBrowser.mTabContainer.advanceSelectedTab(-1, true);
}, 'ひとつ左のタブへ');
key.setGlobalKey('C-M-r', function () {
userscript.reload();
}, '設定ファイルを再読み込み');
key.setGlobalKey(['<f1>', 'b'], function () {
key.listKeyBindings();
}, 'キーバインド一覧を表示');
key.setGlobalKey(['<f1>', 'F'], function () {
openHelpLink("firefox-help");
}, 'Firefox のヘルプを表示');
key.setGlobalKey('C-m', function (aEvent) {
key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_RETURN, true, "keypress");
key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_RETURN, true, "keydown");
}, 'リターンコードを生成');
key.setGlobalKey('C-j', function (aEvent, arg) {
ext.exec("bmany-list-toolbar-bookmarks");
}, 'ブックマークツールバーのアイテムを開く', true);
key.setGlobalKey('M-w', function (aEvent) {
command.copyRegion(aEvent);
}, '選択中のテキストをコピー');
key.setGlobalKey('C-s', function (aEvent) {
command.iSearchForwardKs(aEvent);
}, 'インクリメンタル検索');
key.setGlobalKey('C-r', function (ev) {
command.iSearchBackwardKs(ev);
}, '逆方向インクリメンタル検索');
key.setGlobalKey('C-M-p', function (ev, arg) {
KeySnail.openPreference();
}, '設定ダイアログを開く', true);
key.setGlobalKey('C-M-t', function (aEvent, aArg) {
var defaultIcon = "chrome://keysnail/skin/icon16.png";
var collection = [[tab.image || defaultIcon, tab.label, tab.linkedBrowser.contentDocument.URL] for (tab in Array.prototype.slice.call(gBrowser.mTabs, 1))];
prompt.selector({
message: "select tab:",
callback: function (aIndex) {
if (aIndex >= 0) {
gBrowser.mTabContainer.selectedIndex = aIndex;
}
},
collection: collection,
header: ["Tab", "URL"],
style: [null, "color:#00268d;"],
flags: [ICON | IGNORE, 0, 0]
});
}, '現在開いているタブ一覧を表示 & ジャンプ');
key.setGlobalKey('C-:', function (aEvent, aArg) {
ext.exec("prefer-ldrize-toggle-status", aArg);
}, 'LDRize 優先状態の切り替え', true);
key.setGlobalKey('C-9', function (ev, arg) {
ext.exec("hogehoge");
}, 'Text', true);
key.setGlobalKey('C-;', function (ev, arg) {
ext.exec("site-local-keymap-toggle-status", arg, ev);
}, 'サイトローカル・キーマップの有効状態を切り替え', true);
key.setGlobalKey('C-0', function (ev, arg) {
var length = Math.round(10 * Math.random());
plugins.lib.xulGrowl.update({
title: "Hello!",
message: Array(length).join("Hello!"),
link: "http://www.google.co.jp/"
});
}, 'Growl', true);
key.setGlobalKey('M-:', function (ev, arg) {
command.interpreter(ev, arg);
}, 'Eval', true);
key.setGlobalKey('M-x', function (aEvent, aArg) {
ext.select(aArg, aEvent);
}, 'エクステ一覧');
key.setViewKey('C-a', function (ev, arg) {
ext.exec("tanything", arg);
}, 'タブを一覧表示', true);
key.setViewKey('s', function (ev, arg) {
var engines = util.suggest.getEngines();
var suggestEngines = [util.suggest.ss.getEngineByName("Google")];
var collection = engines.map((function (engine)[(engine.iconURI || {
spec: ""
}).spec, engine.name, engine.description]));
prompt.selector({
message: "engine:",
collection: collection,
flags: [ICON | IGNORE, 0, 0],
header: ["Name", "Description"],
keymap: {
s: "prompt-decide",
j: "prompt-next-completion",
k: "prompt-previous-completion"
},
callback: function (i) {
if (i >= 0) {
util.suggest.searchWithSuggest(engines[i], suggestEngines, "tab");
}
}
});
}, 'Search With Suggest', true);
key.setViewKey('>', function (ev, arg) {
var url = content.location.href;
var pattern = /(.*)([0-9]+)([^0-9]*)$/;
var digit = url.match(pattern);
if (digit[1] && digit[2]) {
let next = +digit[2] + (arg ? arg : 1);
content.location.href = digit[1] + next + (digit[3] || "");
}
}, 'Increment last digit in the URL');
key.setViewKey('<', function (ev, arg) {
var url = content.location.href;
var pattern = /(.*)([0-9]+)([^0-9]*)$/;
var digit = url.match(pattern);
if (digit[1] && digit[2]) {
let next = +digit[2] - (arg ? arg : 1);
content.location.href = digit[1] + next + (digit[3] || "");
}
}, 'Decrement last digit in the URL');
key.setViewKey('c', function (ev, arg) {
ext.exec("list-hateb-comments", arg);
}, 'はてなブックマークのコメントを一覧表示', true);
key.setViewKey('a', function (ev, arg) {
ext.exec("hateb-bookmark-this-page");
}, 'このページをはてなブックマークに追加', true);
key.setViewKey('C-e', function (aEvent, aArg) {
ext.exec("hok-start-continuous-mode", aArg);
}, 'リンクを連続して開く Hit a Hint を開始', true);
key.setViewKey('H', function () {
if (gBrowser.mCurrentTab.previousSibling) {
gBrowser.moveTabTo(gBrowser.mCurrentTab, gBrowser.mCurrentTab._tPos - 1);
} else {
gBrowser.moveTabTo(gBrowser.mCurrentTab, gBrowser.mTabContainer.childNodes.length - 1);
}
}, '選択中のタブを右へ移動');
key.setViewKey('L', function () {
if (gBrowser.mCurrentTab.nextSibling) {
gBrowser.moveTabTo(gBrowser.mCurrentTab, gBrowser.mCurrentTab._tPos + 1);
} else {
gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
}
}, '選択中のタブを左へ移動');
key.setViewKey('C-n', function (aEvent) {
key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_DOWN, true);
}, '一行スクロールダウン');
key.setViewKey('C-p', function (aEvent) {
key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_UP, true);
}, '一行スクロールアップ');
key.setViewKey('i', function (ev, arg) {
util.setBoolPref("accessibility.browsewithcaret", true);
}, 'キャレットモード', true);
key.setViewKey('j', function () {
goDoCommand("cmd_scrollLineDown");
}, '一行スクロールダウン');
key.setViewKey('k', function () {
goDoCommand("cmd_scrollLineUp");
}, '一行スクロールアップ');
key.setViewKey([['b'], ['M-v']], function () {
goDoCommand("cmd_scrollPageUp");
}, '一画面分スクロールアップ');
key.setViewKey('C-v', function (ev, arg) {
goDoCommand("cmd_scrollPageDown");
}, '一画面スクロールダウン');
key.setViewKey([['g', 'g'], ['M-<']], function () {
goDoCommand("cmd_scrollTop");
}, 'ページ先頭へ移動');
key.setViewKey(['g', 'u'], function () {
var uri = gBrowser.currentURI;
if (uri.path == "/") {
return;
}
var pathList = uri.path.split("/");
if (!pathList.pop()) {
pathList.pop();
}
loadURI(uri.prePath + pathList.join("/") + ("/"));
}, '一つ上のディレクトリへ移動');
key.setViewKey(['g', 'h'], function (ev, arg) {
BrowserGoHome(ev);
}, 'ホームへ移動');
key.setViewKey(['g', 'U'], function () {
var uri = window._content.location.href;
if (uri == null) {
return;
}
var root = uri.match(/^[a-z]+:\/\/[^/]+\//);
if (root) {
loadURI(root, null, null);
}
}, 'ルートディレクトリへ移動', true);
key.setViewKey([['G'], ['M->']], function () {
goDoCommand("cmd_scrollBottom");
}, 'ページ末尾へ移動');
key.setViewKey('R', function (aEvent) {
BrowserReload();
}, '更新');
key.setViewKey('B', function (aEvent) {
BrowserBack();
}, '戻る');
key.setViewKey('F', function (aEvent) {
BrowserForward();
}, '進む');
key.setViewKey('l', function () {
gBrowser.mTabContainer.advanceSelectedTab(1, true);
}, 'ひとつ右のタブへ');
key.setViewKey('h', function () {
gBrowser.mTabContainer.advanceSelectedTab(-1, true);
}, 'ひとつ左のタブへ');
key.setViewKey(['C-x', 'h'], function () {
goDoCommand("cmd_selectAll");
}, 'すべて選択');
key.setViewKey('M-n', function () {
command.walkInputElement(command.elementsRetrieverButton, true, true);
}, '次のボタンへフォーカスを当てる');
key.setViewKey('M-p', function () {
command.walkInputElement(command.elementsRetrieverButton, false, true);
}, '前のボタンへフォーカスを当てる');
key.setViewKey('f', function () {
command.focusElement(command.elementsRetrieverTextarea, 0);
}, '最初のインプットエリアへフォーカス', true);
key.setViewKey(['d', 'b'], function () {
userscript.openPluginManager();
}, 'プラグインマネージャを開く', true);
key.setViewKey('T', function (ev, arg) {
ext.exec("twitter-client-display-timeline", arg);
}, 'Yet Another Twitter Client KeySnail', true);
key.setViewKey('e', function (aEvent, aArg) {
ext.exec("hok-start-foreground-mode", aArg);
}, 'Hit a Hint を開始', true);
key.setViewKey('E', function (aEvent, aArg) {
ext.exec("hok-start-background-mode", aArg);
}, 'リンクをバックグラウンドで開く Hit a Hint を開始', true);
key.setViewKey(';', function (aEvent, aArg) {
ext.exec("hok-start-extended-mode", aArg);
}, 'HoK - 拡張ヒントモード', true);
key.setViewKey(['u', 'c'], function () {
ext.exec("list-closed-tabs");
}, 'List closed tabs');
key.setViewKey(['u', 't'], function () {
undoCloseTab();
}, 'Undo closed tab');
key.setViewKey('%', function (ev, arg) {
ext.exec("scrollet-scroll-percent", arg);
}, '前置引数で指定した割合までページをスクロール');
key.setViewKey([']', ']'], function (ev, arg) {
ext.exec("follow-next-link", arg, ev);
}, 'follow next link', true);
key.setViewKey(['[', '['], function (ev, arg) {
ext.exec("follow-prev-link", arg, ev);
}, 'follow previous link', true);
key.setViewKey('C-h', function () {}, 'Kill C-h');
key.setViewKey(':', function () { shell.input(); }, "Command System");
key.setViewKey('t', function (ev, arg) { shell.input("tabopen "); }, "Open tab");
key.setViewKey('o', function (ev, arg) {
shell.input("open ");
}, "Open");
key.setViewKey('s', function (ev, arg) {
shell.input("tabopen google ");
}, "Google word");
key.setEditKey([['M-<down>'], ['M-<up>']], function (ev, arg) {
var select = ev.originalTarget;
if (select.localName.toLowerCase() !== "select") {
return;
}
var options = Array.slice(select.childNodes).filter((function (e)(e.localName || "") === "option"));
prompt.selector({
message: "select:",
collection: options.map((function (e) e.textContent)),
initialIndex: select.selectedIndex || 0,
callback: function (i) {
select.selectedIndex = i;
}
});
}, "Select option");
key.setEditKey(['C-x', 'l'], function (aEvent) {
command.recenter(aEvent);
}, 'キャレット位置までスクロール (Recenter)');
key.setEditKey([['C-x', 'u'], ['C-_']], function (aEvent) {
display.echoStatusBar("Undo!", 2000);
goDoCommand("cmd_undo");
goDoCommand("cmd_selectNone");
}, 'アンドゥ');
key.setEditKey(['C-x', 'r', 'd'], function (aEvent, aArg) {
command.replaceRectangle(aEvent.originalTarget, "", false, !aArg);
}, '矩形削除', true);
key.setEditKey(['C-x', 'r', 't'], function (aEvent) {
var input = aEvent.originalTarget;
prompt.read("String rectangle:", function (aStr) {
command.replaceRectangle(input, aStr);
});
}, '矩形置換', true);
key.setEditKey(['C-x', 'r', 'o'], function (aEvent) {
command.openRectangle(aEvent.originalTarget);
}, '矩形行空け', true);
key.setEditKey(['C-x', 'r', 'k'], function (aEvent, aArg) {
command.kill.buffer = command.killRectangle(aEvent.originalTarget, !aArg);
}, '矩形切り取り', true);
key.setEditKey(['C-x', 'r', 'y'], function (aEvent) {
command.yankRectangle(aEvent.originalTarget, command.kill.buffer);
}, '矩形貼り付け', true);
key.setEditKey(['C-x', 'h'], function (aEvent) {
command.selectAll(aEvent);
}, '全て選択');
key.setEditKey([['C-SPC'], ['C-@']], function (aEvent) {
command.setMark(aEvent);
}, 'マークをセット');
key.setEditKey('C-o', function (aEvent) {
command.openLine(aEvent);
}, '行を開く (open line)');
key.setEditKey('C-\\', function () {
display.echoStatusBar("Redo!", 2000);
goDoCommand("cmd_redo");
}, 'リドゥ');
key.setEditKey('C-a', function (aEvent) {
command.beginLine(aEvent);
}, '行頭へ移動');
key.setEditKey('C-e', function (aEvent) {
command.endLine(aEvent);
}, '行末へ');
key.setEditKey('C-f', function (aEvent) {
command.nextChar(aEvent);
}, '一文字右へ移動');
key.setEditKey('C-b', function (aEvent) {
command.previousChar(aEvent);
}, '一文字左へ移動');
key.setEditKey('M-f', function (aEvent) {
command.nextWord(aEvent);
}, '一単語右へ移動');
key.setEditKey('M-b', function (aEvent) {
command.previousWord(aEvent);
}, '一単語左へ移動');
key.setEditKey('C-n', function (aEvent) {
command.nextLine(aEvent);
}, '一行下へ');
key.setEditKey('C-p', function (aEvent) {
command.previousLine(aEvent);
}, '一行上へ');
key.setEditKey('C-v', function (aEvent) {
command.pageDown(aEvent);
}, '一画面分下へ');
key.setEditKey('M-v', function (aEvent) {
command.pageUp(aEvent);
}, '一画面分上へ');
key.setEditKey('M-<', function (aEvent) {
command.moveTop(aEvent);
}, 'テキストエリア先頭へ');
key.setEditKey('M->', function (aEvent) {
command.moveBottom(aEvent);
}, 'テキストエリア末尾へ');
key.setEditKey('C-d', function () {
goDoCommand("cmd_deleteCharForward");
}, '次の一文字削除');
key.setEditKey('C-h', function () {
goDoCommand("cmd_deleteCharBackward");
}, '前の一文字を削除');
key.setEditKey('M-d', function (ev) {
command.deleteForwardWord(ev);
}, '次の一単語を削除');
key.setEditKey([['C-<backspace>'], ['M-<delete>']], function (ev) {
command.deleteBackwardWord(ev);
}, '前の一単語を削除');
key.setEditKey('M-u', function (ev, arg) {
command.wordCommand(ev, arg, command.upcaseForwardWord, command.upcaseBackwardWord);
}, '次の一単語を全て大文字に (Upper case)', true);
key.setEditKey('M-l', function (ev, arg) {
command.wordCommand(ev, arg, command.downcaseForwardWord, command.downcaseBackwardWord);
}, '次の一単語を全て小文字に (Lower case)', true);
key.setEditKey('M-c', function (ev, arg) {
command.wordCommand(ev, arg, command.capitalizeForwardWord, command.capitalizeBackwardWord);
}, '次の一単語をキャピタライズ', true);
key.setEditKey('C-k', function (aEvent) {
command.killLine(aEvent);
}, 'カーソルから行末までを切り取り');
key.setEditKey('C-y', command.yank, '貼り付け');
key.setEditKey('M-y', command.yankPop, '以前にコピーしたテキストを順に貼り付け');
key.setEditKey('C-M-y', function (aEvent) {
if (!command.kill.ring.length) {
return;
}
let(ct = command.getClipboardText())(!command.kill.ring.length || ct != command.kill.ring[0]) && command.pushKillRing(ct);
prompt.selector({
message: "Paste:",
collection: command.kill.ring,
callback: function (i) {
if (i >= 0) {
key.insertText(command.kill.ring[i]);
}
}
});
}, '以前にコピーしたテキスト一覧から選択して貼り付け');
key.setEditKey('C-w', function (aEvent) {
goDoCommand("cmd_copy");
goDoCommand("cmd_delete");
command.resetMark(aEvent);
}, 'リージョンをカット');
key.setEditKey('M-n', function () {
command.walkInputElement(command.elementsRetrieverTextarea, true, true);
}, '次のテキストエリアへフォーカス');
key.setEditKey('M-p', function () {
command.walkInputElement(command.elementsRetrieverTextarea, false, true);
}, '前のテキストエリアへフォーカス');
key.setEditKey(['C-c', 'e'], function (ev, arg) {
ext.exec("edit_text", arg);
}, '外部エディタで編集', true);
key.setEditKey('C-M-v', function (ev, arg) {
Clipple.pasteMultiple(ev);
}, 'Clipple - 貼り付け', true);
key.setCaretKey('H', function () {
if (gBrowser.mCurrentTab.previousSibling) {
gBrowser.moveTabTo(gBrowser.mCurrentTab, gBrowser.mCurrentTab._tPos - 1);
} else {
gBrowser.moveTabTo(gBrowser.mCurrentTab, gBrowser.mTabContainer.childNodes.length - 1);
}
}, '選択中のタブを右へ移動');
key.setCaretKey('L', function () {
if (gBrowser.mCurrentTab.nextSibling) {
gBrowser.moveTabTo(gBrowser.mCurrentTab, gBrowser.mCurrentTab._tPos + 1);
} else {
gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
}
}, '選択中のタブを左へ移動');
key.setCaretKey([['C-n'], ['j']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectLineNext") : goDoCommand("cmd_scrollLineDown");
}, '一行下へ');
key.setCaretKey([['C-p'], ['k']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectLinePrevious") : goDoCommand("cmd_scrollLineUp");
}, '一行上へ');
key.setCaretKey([['C-f'], ['l']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectCharNext") : goDoCommand("cmd_scrollRight");
}, '一文字右へ移動');
key.setCaretKey([['C-b'], ['h'], ['C-h']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectCharPrevious") : goDoCommand("cmd_scrollLeft");
}, '一文字左へ移動');
key.setCaretKey('>', function () {
goDoCommand("cmd_scrollRight");
}, '右へスクロール');
key.setCaretKey('.', function () {
util.getSelectionController().scrollHorizontal(false);
}, 'ページを右へスクロール');
key.setCaretKey('<', function () {
goDoCommand("cmd_scrollLeft");
}, '左へスクロール');
key.setCaretKey(',', function () {
util.getSelectionController().scrollHorizontal(true);
}, 'ページを左へスクロール');
key.setCaretKey([['b'], ['M-v']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectPagePrevious") : goDoCommand("cmd_movePageUp");
}, '一画面分上へ');
key.setCaretKey([['C-v'], ['SPC']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectPageNext") : goDoCommand("cmd_movePageDown");
}, '一画面分下へ');
key.setCaretKey([['g'], ['M-<']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectTop") : goDoCommand("cmd_scrollTop");
}, 'ページ先頭へ移動');
key.setCaretKey([['G'], ['M->']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectBottom") : goDoCommand("cmd_scrollBottom");
}, 'ページ末尾へ移動');
key.setCaretKey('R', function (aEvent) {
BrowserReload();
}, '更新');
key.setCaretKey('B', function (aEvent) {
BrowserBack();
}, '戻る');
key.setCaretKey('F', function (aEvent) {
BrowserForward();
}, '進む');
key.setCaretKey(['C-x', 'h'], function () {
goDoCommand("cmd_selectAll");
}, 'すべて選択');
key.setCaretKey('M-n', function () {
command.walkInputElement(command.elementsRetrieverButton, true, true);
}, '次のボタンへフォーカスを当てる');
key.setCaretKey('M-p', function () {
command.walkInputElement(command.elementsRetrieverButton, false, true);
}, '前のボタンへフォーカスを当てる');
key.setCaretKey('f', function () {
command.focusElement(command.elementsRetrieverTextarea, 0);
}, '最初のインプットエリアへフォーカス', true);
key.setCaretKey([['C-SPC'], ['C-@']], function (aEvent) {
command.setMark(aEvent);
}, 'マークをセット');
key.setCaretKey([['C-a'], ['^']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectBeginLine") : goDoCommand("cmd_beginLine");
}, '行頭へ移動');
key.setCaretKey([['C-e'], ['$']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectEndLine") : goDoCommand("cmd_endLine");
}, '行末へ移動');
key.setCaretKey([['M-f'], ['w']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectWordNext") : goDoCommand("cmd_wordNext");
}, '一単語右へ移動');
key.setCaretKey([['M-b'], ['W']], function (aEvent) {
aEvent.target.ksMarked ? goDoCommand("cmd_selectWordPrevious") : goDoCommand("cmd_wordPrevious");
}, '一単語左へ移動');
key.setCaretKey('J', function (ev) {
util.getSelectionController().scrollLine(true);
}, '画面を一行分下へスクロール');
key.setCaretKey('K', function () {
util.getSelectionController().scrollLine(false);
}, '画面を一行分上へスクロール');
key.setCaretKey('z', function (aEvent) {
command.recenter(aEvent);
}, 'カーソル位置へスクロール');
key.setCaretKey('e', function (aEvent, aArg) {
ext.exec("hok-start-foreground-mode", aArg);
}, 'Hit a Hint を開始', true);
key.setCaretKey('E', function (aEvent, aArg) {
ext.exec("hok-start-background-mode", aArg);
}, 'リンクをバックグラウンドで開く Hit a Hint を開始', true);
key.setCaretKey(';', function (aEvent, aArg) {
ext.exec("hok-start-extended-mode", aArg);
}, 'HoK - 拡張ヒントモード', true);
key.setCaretKey('s', function (ev, arg) {
ext.exec("swap-caret", arg, ev);
}, 'キャレットを交換', true);
key.setCaretKey('i', function (ev, arg) {
util.setBoolPref("accessibility.browsewithcaret", false);
}, 'キャレットモードを抜ける', true);
key.setViewKey(['d', 'd'], function (ev) {
BrowserCloseTabOrWindow();
}, 'タブ / ウィンドウを閉じる');
key.defineKey([key.modes.VIEW, key.modes.CARET], 'r', function (ev, arg) {
ext.exec("kungfloo-reblog", arg, ev);
}, 'kungfloo - Reblog', true);
key.setEditKey('M-@', function (ev) {
ext.exec("dmacro-exec");
}, 'Dynamic macro');
key.setEditKey(plugins.options["dabbrev.next_key"], function (ev, arg) {
ext.exec("dabbrev-expand", arg, ev);
}, "Expand previous word \"dynamically\".");
key.setViewKey(['C-x', 'b'], function (ev, arg) { ext.exec("tanything", arg); }, 'タブを一覧表示', true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment