You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

732 lines
29 KiB

  1. // ========================== KeySnail Init File =========================== //
  2. // この領域は, GUI により設定ファイルを生成した際にも引き継がれます
  3. // 特殊キー, キーバインド定義, フック, ブラックリスト以外のコードは, この中に書くようにして下さい
  4. // ========================================================================= //
  5. //{{%PRESERVE%
  6. // prompt.rows = 12;
  7. // prompt.useMigemo = false;
  8. // prompt.migemoMinWordLength = 2;
  9. // prompt.displayDelayTime = 300;
  10. // command.kill.killRingMax = 15;
  11. // command.kill.textLengthMax = 8192;
  12. //////////////////////////////////////
  13. //// sitelocalkeymap
  14. var local = {};
  15. plugins.options["site_local_keymap.local_keymap"] = local;
  16. function fake(k, i) function () { key.feed(k, i); };
  17. function pass(k, i) [k, fake(k, i)];
  18. function ignore(k, i) [k, null];
  19. // ext.add("ext-name", function () {}, "ext description");
  20. // style.register("");
  21. // local["^http://"] = [['a', function(ev, arg){}],];
  22. ///////////////////////////////////////////
  23. //// firefox
  24. // style.register("#bookmarksPanel > hbox,#history-panel > hbox {display: none !important;} //#urlbar-container{max-width: 500px !important;}");
  25. ///////////////////////////////////
  26. //search engine
  27. plugins.options["search-url-list"] = [
  28. ["bing","http://bing.com/search?q=%q"],
  29. ["yatwitter search","http://yats-data.com/yats/search?query=%q"],
  30. ["twitter search","http://search.twitter.com/search?q=%q&lang=all"],
  31. ["tospy", "http://topsy.com/s?allow_lang=ja&q=%q"],
  32. ["2ch","http://2ch-ranking.net/search.php?q=%q&imp=and&order=time"],
  33. ["I\'m feelig lucky!","http://www.google.co.jp/search?q=%q&btnI=kudos"],
  34. ["uncyclopedia","http://ja.uncyclopedia.info/wiki/%q"],
  35. ["wikipedia","http://ja.wikipedia.org/wiki/%q"],
  36. ["nicovideo.jp","http://www.nicovideo.jp/search/%q"],
  37. ["alc","http://eow.alc.co.jp/%q/UTF-8/"],
  38. ["google map","http://maps.google.co.jp/maps?hl=ja&q=%q&um=1&ie=UTF-8&sa=N&tab=wl"],
  39. ["weblio","http://www.weblio.jp/content_find?query=%q"],
  40. ["shoutcast","http://www.shoutcast.com/Internet-Radio/%q"],
  41. ["10sr.posterous.com","http://www.google.com/search?q=%q&ie=UTF-8&oe=UTF-8&hl=ja&domains=10sr.posterous.com&sitesearch=10sr.posterous.com"],
  42. ["delicious 10sr","http://delicious.com/10sr?addtag=%q&setcount=50&opennew=1"],
  43. ["open raw","%r"],
  44. ];
  45. plugins.options["my-keysnail-bookmarks"] = [
  46. "twitter.com",
  47. ];
  48. // sitelocal keymap
  49. //////////////////////////////////////////
  50. // 2ch chaika
  51. local["^http://127.0.0.1:8823/thread/"] = [
  52. ['k', function (ev, arg) {
  53. curl = window.content.location.href;
  54. kurl = curl.replace(/http:.*thread\/(.*\/).*/, "chaika://post/$1");
  55. window.content.location.href = kurl;
  56. }
  57. ],
  58. ];
  59. local["^http://w2.p2.2ch.net/p2/read.php"] = [
  60. ['k', function (ev, arg) {
  61. var url = window.content.location.href;
  62. var pt = /host=(.*?)&bbs=(.*?)&key=(.*?)&ls=/ ;
  63. var result = url.match(pt);
  64. var k = format("chaika://post/http://%s/test/read.cgi/%s/%s/", result[1], result[2], result[3]);
  65. window.content.location.href = k;
  66. }
  67. ],
  68. ];
  69. /////////////////////////////////////////
  70. // feedly
  71. local["^http://www.feedly.com/"] = [
  72. ['d', null],
  73. ['j', null],
  74. ['k', null],
  75. ['n', null],
  76. ['p', null],
  77. ['o', null],
  78. ['b', null],
  79. ['S', null],
  80. ['s', null],
  81. ['?', null],
  82. ['r', null],
  83. ['g', null],
  84. // ['x', function (ev, arg) {ev.target.dispatchEvent(key.stringToKeyEvent("g", true));}],
  85. ['l', function (ev, arg) {window.content.location.href = "http://www.feedly.com/home#latest";}],
  86. [['t', 'p'], function (ev, arg) {ev.target.dispatchEvent(key.stringToKeyEvent("t", true));}],
  87. [['t', 'w'], function (ev, arg) {ext.exec("twitter-client-tweet", arg, ev);}],
  88. ];
  89. /////////////////////////////////////////
  90. //nicovideo
  91. local["http://(www|tw|es|de|)\.nicovideo\.jp\/(watch|playlist)/*"] = [
  92. ["i", function (ev, arg) { ext.exec("nicoinfo", arg); }],
  93. ["p", function (ev, arg) { ext.exec("nicopause", arg); }],
  94. ["o", function (ev, arg) { ext.exec("nicommentvisible", arg); }],
  95. ["m", function (ev, arg) { ext.exec("nicomute", arg); }],
  96. [".", function (ev, arg) { ext.exec("nicovolumeIncrement", arg); }],
  97. [",", function (ev, arg) { ext.exec("nicovolumeDecrement", arg); }],
  98. ['f', function (ev, arg) {
  99. curl = window.content.location.href;
  100. kurl = curl.replace(/nicovideo.jp/, "nicovideofire.jp");
  101. window.content.location.href = kurl;
  102. }
  103. ],
  104. ];
  105. /////////////////////////////////////////
  106. // tumblr/dashboard
  107. local["^http://www.tumblr.com/dashboard"] = [
  108. // ["C-<left>", function (ev, arg) {gBrowser.mTabContainer.advanceSelectedTab(-1, true); }],
  109. // ["C-<right>", function (ev, arg) {gBrowser.mTabContainer.advanceSelectedTab(1, true); }],
  110. ["<left>", function (ev, arg) { window.content.location.href = "http://www.tumblr.com/dashboard"; }],
  111. // ["<right>", null],
  112. ["J", function (ev, arg) {
  113. if (window.loadURI) {
  114. loadURI("javascript:(function(){b=20;s=100;t=document.getElementById('next_page_link').href.split('/')[5];max=t.substr(0,t.length-5);min=max-s;i=Math.floor(Math.random()*(max-min)+min);u=(i<b)?'http://www.tumblr.com/dashboard':'http://www.tumblr.com/dashboard/2/'+i+'00000';window.content.location.href=u;}())");
  115. }
  116. }],
  117. ];
  118. ///////////////////////////////////////////
  119. // plugin option
  120. plugins.options["instapaper.close_after_post"] = true;
  121. plugins.options["instapaper.initial_comment_function"] = function(){
  122. var now = new Date();
  123. return "[" + now.toString() + "]";
  124. };
  125. //////////////////////////////////////////
  126. // yatc
  127. style.register("#keysnail-twitter-client-container{ display:none !important; }");
  128. plugins.options["twitter_client.popup_new_statuses"] = false;
  129. plugins.options["twitter_client.automatically_begin"] = false;
  130. plugins.options["twitter_client.automatically_begin_list"] = false;
  131. plugins.options["twitter_client.timeline_count_beginning"] = 0;
  132. plugins.options["twitter_client.timeline_count_every_updates"] = 0;
  133. plugins.options["twitter_client.tweet_keymap"] = {
  134. "C-RET" : "prompt-decide",
  135. "RET" : ""
  136. };
  137. plugins.options["twitter_client.jmp_id"] = "10sr";
  138. plugins.options["twitter_client.jmp_key"] = "R_c51f889a77cb4b4e993ed868f65083f5";
  139. plugins.options["twitter_client.use_jmp"] = true;
  140. ////////////////////////////////////////////
  141. // my ext
  142. ext.add('view-page-source', function(){
  143. window.content.location.href = "view-source:" + window.content.location.href;
  144. }, 'view page source');
  145. ext.add('my-setpref', function(){
  146. util.setPrefs(
  147. {
  148. "browser.bookmarks.max_backups":0,
  149. "browser.cache.memory.capacity":16384,
  150. "browser.download.manager.closeWhenDone":true,
  151. "browser.download.useDownloadDir":false,
  152. "browser.fullscreen.autohide":false,
  153. "browser.search.openintab":true,
  154. "browser.sessionhistory.max_total_viewers":8,
  155. "browser.sessionstore.restore_on_demand":true,
  156. "browser.tabs.closeWindowWithLastTab":false,
  157. "browser.tabs.loadDivertedInBackground": true,
  158. "browser.urlbar.autocomplete.enabled":false,
  159. "browser.urlbar.trimURLs":false,
  160. "dom.disable_window_open_feature.location": false,
  161. "dom.max_script_run_time": 30,
  162. "extensions.chaika.bbsmenu.open_new_tab":true,
  163. "extensions.chaika.bbsmenu.open_single_click":false,
  164. "extensions.chaika.board.open_new_tab":true,
  165. "extensions.chaika.board.open_single_click":false,
  166. "extensions.foxage2ch.openThreadInTab":true,
  167. "extensions.saveimageinfolder.general-duplicatefilenamevalue":1,
  168. "extensions.saveimageinfolder.general-fileprefixvalue":"%yyyy%%MM%%dd%-%hh%%mm%%ss%_",
  169. "extensions.saveimageinfolder.usecache":true,
  170. "extensions.tabutils.openTabNext":1,
  171. "extensions.tabutils.styles.current":"{\"bold\":true,\"italic\":false,\"underline\":true,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#000000\",\"bgColor\":false,\"bgColorCode\":\"#000000\",\"outline\":false,\"outlineColorCode\":\"#000000\"}",
  172. "extensions.tabutils.styles.unread":"{\"bold\":false,\"italic\":false,\"underline\":false,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#CC0000\",\"bgColor\":false,\"bgColorCode\":\"undefined\",\"outline\":false,\"outlineColorCode\":\"undefined\"}",
  173. "extensions.yass.edgetype":0,
  174. "extensions.yass.selectedpreset":"red",
  175. "refcontrol.actions":"@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  176. "font.default.x-western":"sans-serif",
  177. "general.warnOnAboutConfig":false,
  178. "keyword.URL":"http://www.bing.com/search?q=",
  179. "network.dns.disableIPv6":true,
  180. "refcontrol.actions":"@DEFAULT=@FORGE",
  181. "scrapbook.tabs.open":true
  182. }
  183. );
  184. if(/^Linux/.test(navigator.platform)){
  185. util.setPrefs(
  186. {
  187. "browser.cache.disk.parent_directory":"/tmp",
  188. "browser.cache.disk.capacity":524288
  189. }
  190. );
  191. }
  192. display.showPopup("Keysnail", "My prefs done.");
  193. }, 'my setpref');
  194. ext.add('auto-install-plugins', function(ev, arg){
  195. var urls = [
  196. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  197. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  198. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  199. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  200. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  201. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  202. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  203. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  204. 'https://raw.github.com/gist/1976942/firefox-addon-manager.ks.js',
  205. 'https://raw.github.com/gist/1450594/mstranslator.ks.js'
  206. ];
  207. function inst(a){
  208. if(a.length == 0){
  209. display.showPopup("auto-install-plugins", "All installation finished.");
  210. }else{
  211. var url = a.shift();
  212. var path = userscript.pluginDir + userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  213. if(plugins.context[path] === undefined){
  214. userscript.installPluginFromURL(url, function(){inst(a);});
  215. }else{
  216. inst(a);
  217. }
  218. }
  219. }
  220. inst(urls);
  221. }, 'Install plugins automatically if not installed yet.');
  222. ext.add('put-aside-this-page', function (ev, arg) {
  223. var n = gBrowser.mCurrentTab._tPos;
  224. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  225. if (n != 0) {
  226. gBrowser.selectedTab = gBrowser.mTabs[n];
  227. }
  228. }, 'put aside this page');
  229. ext.add('send-escape', function (ev, arg) {
  230. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  231. }, 'escape');
  232. ext.add("open-hatebu-comment", function (ev, arg) {
  233. if (window.loadURI) {
  234. loadURI("javascript:location.href='http://b.hatena.ne.jp/entry?mode=more&url='+escape(location.href);");
  235. }
  236. }, 'hatebu');
  237. ext.add("fullscreen-page",function (ev) {
  238. getBrowser().selectedTab = getBrowser().addTab("http://home.tiscali.nl/annejan/swf/timeline.swf");
  239. BrowserFullScreen();
  240. }, "fullscreen page");
  241. ext.add("focus-on-content", function(){
  242. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  243. gBrowser.focus();
  244. content.focus();
  245. }, "forcus on content");
  246. ext.add("hide-sidebar", function(){
  247. var sidebarBox = document.getElementById("sidebar-box");
  248. if (!sidebarBox.hidden) {
  249. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  250. }
  251. }, "hide-sidebar");
  252. ext.add("close-and-next-tab", function (ev, arg) {
  253. var n = gBrowser.mCurrentTab._tPos;
  254. BrowserCloseTabOrWindow();
  255. gBrowser.selectedTab = gBrowser.mTabs[n];
  256. }, "close and focus to next tab");
  257. //////////////////////////////////////
  258. //
  259. ext.add("restart-firefox-add-menu", function(){
  260. const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  261. var cmdelm = document.createElementNS(XUL_NS, "command");
  262. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs")
  263. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  264. var commandset = document.getElementById("mainCommandSet");
  265. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  266. commandset.appendChild(cmdelm);
  267. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  268. menuelm.setAttribute("label", "Restart Firefox");
  269. menuelm.setAttribute("id", "my_menu_restartFirefoxKs")
  270. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  271. var menu = document.getElementById("menu_FilePopup");
  272. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  273. menu.appendChild(menuelm);
  274. }, "add restart firefox menu");
  275. //////////////////////////////////////
  276. // restart firefox
  277. // http://keysnail.g.hatena.ne.jp/Shinnya/20100723/1279878815
  278. ext.add("restart-firefox",function (ev) {
  279. const nsIAppStartup = Components.interfaces.nsIAppStartup;
  280. // Notify all windows that an application quit has been requested.
  281. var os = Components.classes["@mozilla.org/observer-service;1"]
  282. .getService(Components.interfaces.nsIObserverService);
  283. var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  284. .createInstance(Components.interfaces.nsISupportsPRBool);
  285. os.notifyObservers(cancelQuit, "quit-application-requested", null);
  286. // Something aborted the quit process.
  287. if (cancelQuit.data)
  288. return;
  289. // Notify all windows that an application quit has been granted.
  290. os.notifyObservers(null, "quit-application-granted", null);
  291. // Enumerate all windows and call shutdown handlers
  292. var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  293. .getService(Components.interfaces.nsIWindowMediator);
  294. var windows = wm.getEnumerator(null);
  295. while (windows.hasMoreElements()) {
  296. var win = windows.getNext();
  297. if (("tryToClose" in win) && !win.tryToClose())
  298. return;
  299. }
  300. Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
  301. .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
  302. }, "restart firefox");
  303. /////////////////////////////////////////
  304. // copy feed url
  305. ext.add("copy-url", function () {
  306. const doc = content.document;
  307. let feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  308. for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]',
  309. 'link[type="application/atom+xml"]'])))];
  310. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1");
  311. for (i = 0; i < feeds.length; i++)
  312. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  313. feeds.unshift([window.content.document.title,window.content.location.href]);
  314. prompt.selector(
  315. {
  316. message : "Select Feed",
  317. collection : feeds,
  318. callback : function (i) {
  319. if (i >= 0)
  320. command.setClipboardText(feeds[i][1]);
  321. }
  322. }
  323. );
  324. }, "Copy url or feed url of current page");
  325. ///////////////////////////////////////
  326. // keysnail z menu
  327. ext.add("keysnail-setting-menu",function(){
  328. var settingmenulist = [["keysnail setting dialogue", function(){return function(){KeySnail.openPreference();};}],
  329. ["keysnail plugin manager", function(){return function(){userscript.openPluginManager();};}],
  330. ["firefox addon manager", function(){return function(){BrowserOpenAddonsMgr();};}],
  331. ["reload .keysnail.js", function(){return function() {userscript.reload();};}],
  332. // ["check for plugins update", function(){return function(){ext.exec("check-for-plugins-update");};}],
  333. ["restart firefox", function(){return function(){ext.exec("restart-firefox");};}]
  334. ];
  335. prompt.selector(
  336. {
  337. message : "open setting dialog",
  338. collection : settingmenulist,
  339. callback : function (i) { settingmenulist[i][1]()(); }
  340. });
  341. },"open keysnail setting menu");
  342. ////////////////////////
  343. // multiple tab handler
  344. ext.add("multiple-tab-handler-close-selected-and-current-tabs", function () {
  345. BrowserCloseTabOrWindow();
  346. // if (MultipleTabService) {
  347. // //BrowserCloseTabOrWindow();
  348. // //MultipleTabService.setSelection(gBrowser.mCurrentTab, true);
  349. MultipleTabService.closeTabs(MultipleTabService.getSelectedTabs());
  350. // } else {
  351. // BrowserCloseTabOrWindow();}
  352. }, '選択タブと現在のタブを閉じる');
  353. ext.add("if-mth-exist", function() {
  354. if (MultipleTabService === undefined) display.echoStatusBar("mth not exist.");
  355. },'if mth exist');
  356. // search web
  357. ext.add("query-then-engine", function () {
  358. prompt.reader({message : "Search Word?:",
  359. callback : function (q) {
  360. if (q) {
  361. prompt.selector({ message : "search \"" + q + "\" with?",
  362. collection : plugins.options["search-url-list"],
  363. width : [20,80],
  364. callback : function (i) { getBrowser().selectedTab = getBrowser().addTab(plugins.options["search-url-list"][i][1].replace("%r",q).replace("%q",encodeURIComponent(q))); },
  365. });
  366. };
  367. },
  368. initialInput : content.document.getSelection() || "",
  369. });
  370. }, "enter search word and then select engine");
  371. /////////////////////////////////////
  372. // closed tab list
  373. ext.add("list-closed-tabs", function () {
  374. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  375. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  376. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  377. var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  378. if (!closedTabs.length)
  379. return void display.echoStatusBar("最近閉じたタブが見つかりませんでした", 2000);
  380. prompt.selector(
  381. {
  382. message : "select tab to undo:",
  383. collection : closedTabs,
  384. flags : [ICON | IGNORE, 0, 0],
  385. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  386. });
  387. }, "List closed tabs");
  388. ext.add("echo-closed-tabs", function () {
  389. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  390. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  391. // var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  392. var lasttab = json.decode(ss.getClosedTabData(window))[0];
  393. dump = ""
  394. for (var i in lasttab) { dump += lasttab[i] + "\n"; }
  395. confirm(dump);
  396. }, "List closed tabs");
  397. ///////////////////////////////
  398. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  399. ext.add("list-tab-history", function () {
  400. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  401. var tabHistory = [];
  402. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  403. if (sessionHistory.count < 1)
  404. return void display.echoStatusBar("Tab history not exist", 2000);
  405. var curIdx = sessionHistory.index;
  406. for (var i = 0; i < sessionHistory.count; i++) {
  407. var entry = sessionHistory.getEntryAtIndex(i, false);
  408. if (!entry)
  409. continue;
  410. try {
  411. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  412. .getService(Ci.nsIFaviconService)
  413. .getFaviconForPage(entry.URI).spec;
  414. } catch (ex) {}
  415. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  416. }
  417. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  418. if (tabHistory[thIdx][3] == curIdx) break;
  419. }
  420. prompt.selector(
  421. {
  422. message : "select history in tab",
  423. collection : tabHistory,
  424. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  425. header : ["Title", "URL"],
  426. initialIndex : thIdx,
  427. callback : function(i) { if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]); }
  428. });
  429. }, 'List tab history');
  430. //}}%PRESERVE%
  431. // ========================================================================= //
  432. // ========================= Special key settings ========================== //
  433. key.quitKey = "<delete>";
  434. key.helpKey = "<f1>";
  435. key.escapeKey = "C-q";
  436. key.macroStartKey = "";
  437. key.macroEndKey = "";
  438. key.universalArgumentKey = "C-u";
  439. key.negativeArgument1Key = "C--";
  440. key.negativeArgument2Key = "C-M--";
  441. key.negativeArgument3Key = "M--";
  442. key.suspendKey = "Not defined";
  443. // ================================= Hooks ================================= //
  444. hook.setHook('KeySnailInitialized', function () {
  445. ext.exec("shiitake-enable-style");
  446. });
  447. hook.setHook('KeyBoardQuit', function (aEvent) {
  448. ext.exec("hide-sidebar");
  449. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  450. gBrowser.focus();
  451. content.focus();
  452. command.closeFindBar();
  453. if (util.isCaretEnabled()) {
  454. command.resetMark(aEvent);
  455. } else {
  456. goDoCommand("cmd_selectNone");
  457. }
  458. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  459. });
  460. hook.setHook('Unload', function () {
  461. util.getBrowserWindows().some(function (win) {
  462. if (win === window) {
  463. return false;
  464. }
  465. const ks = win.KeySnail;
  466. share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate);
  467. ks.setUpPluginUpdaterDelegator();
  468. return true;
  469. });
  470. });
  471. // ============================= Key bindings ============================== //
  472. key.setGlobalKey('C-<right>', function () {
  473. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  474. }, 'ひとつ右のタブへ');
  475. key.setGlobalKey('C-<left>', function () {
  476. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  477. }, 'ひとつ左のタブへ');
  478. key.setGlobalKey('C-<up>', function () {
  479. var browser = getBrowser();
  480. if (browser.mCurrentTab.previousSibling) {
  481. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  482. } else {
  483. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  484. }
  485. }, '選択中のタブを右へ');
  486. key.setGlobalKey('C-<down>', function () {
  487. var browser = getBrowser();
  488. if (browser.mCurrentTab.nextSibling) {
  489. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  490. } else {
  491. browser.moveTabTo(browser.mCurrentTab, 0);
  492. }
  493. }, '選択中のタブを左へ');
  494. key.setGlobalKey('M-:', function (ev) {
  495. command.interpreter();
  496. }, 'JavaScript のコードを評価');
  497. key.setGlobalKey('C-h', function (ev, arg) {
  498. return;
  499. }, 'ignore');
  500. key.setViewKey('D', function (ev, arg) {
  501. ext.exec("dig-url", arg, ev);
  502. }, 'dig url with selector', true);
  503. key.setViewKey('x', function (aEvent, aArg) {
  504. ext.select(aArg, aEvent);
  505. }, 'エクステ一覧');
  506. key.setViewKey(['t', 'm'], function (ev, arg) {
  507. if (window.loadURI) {
  508. loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;");
  509. }
  510. }, 'open with tweetmeme');
  511. key.setViewKey(['t', 'w'], function (ev, arg) {
  512. ext.exec("twitter-client-tweet", arg, ev);
  513. }, 'つぶやく', true);
  514. key.setViewKey(['t', 'p'], function (ev, arg) {
  515. ext.exec("twitter-client-tweet-this-page", arg, ev);
  516. }, 'このページのタイトルと URL を使ってつぶやく', true);
  517. key.setViewKey('u', function () {
  518. undoCloseTab();
  519. }, '閉じたタブを元に戻す');
  520. key.setViewKey('g', function () {
  521. goDoCommand("cmd_scrollTop");
  522. }, 'ページ先頭へ移動');
  523. key.setViewKey('G', function () {
  524. goDoCommand("cmd_scrollBottom");
  525. }, 'ページ末尾へ移動');
  526. key.setViewKey('r', function (aEvent) {
  527. BrowserReload();
  528. }, '再読み込み');
  529. key.setViewKey('m', function (ev, arg) {
  530. _fi.toogle();
  531. }, 'fetchimiをトグル');
  532. key.setViewKey('d', function (ev, arg) {
  533. if (window.loadURI) {
  534. loadURI("javascript:(function(){f='http://www.delicious.com/save?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&notes='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=6&';a=function(){if(!window.open(f+'noui=1&jump=doclose','deliciousuiv6','location=1,links=0,scrollbars=0,toolbar=0,width=550,height=585'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()");
  535. }
  536. }, 'deliciousでブックマーク');
  537. key.setViewKey('p', function (ev, arg) {
  538. if (window.loadURI) {
  539. loadURI("javascript:var%20b=document.body;var%20POSTEROUS___bookmarklet_domain='http://posterous.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.type='text/javascript');void(z.src='http://posterous.com/javascripts/bookmarklet2.js');void(b.appendChild(z));}else{}");
  540. }
  541. }, 'posterousに投稿');
  542. key.setViewKey('SPC', function (ev, arg) {
  543. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  544. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  545. }, 'タブの選択をトグルして次のタブ');
  546. key.setViewKey('S-SPC', function (ev, arg) {
  547. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  548. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  549. }, 'タブの選択をトグルして前のタブ');
  550. key.setViewKey('z', function (ev, arg) {
  551. ext.exec("keysnail-setting-menu", arg, ev);
  552. }, 'open keysnail setting menu', true);
  553. key.setViewKey('C-SPC', function (ev, arg) {
  554. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  555. }, 'タブの選択をトグル');
  556. key.setViewKey('U', function (ev, arg) {
  557. ext.exec("list-closed-tabs", arg, ev);
  558. }, 'List closed tabs', true);
  559. key.setViewKey('e', function () {
  560. command.focusElement(command.elementsRetrieverTextarea, 0);
  561. }, '最初のインプットエリアへフォーカス', true);
  562. key.setViewKey('S', function (ev, arg) {
  563. if (window.loadURI) {
  564. loadURI("javascript:var%20b=document.body;var%20GR________bookmarklet_domain='https://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='https://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}");
  565. }
  566. }, 'google reader share');
  567. key.setViewKey('!', function (ev, arg) {
  568. shell.input();
  569. }, 'Command system');
  570. key.setViewKey('b', function (ev, arg) {
  571. BarTap.putOnTap(gBrowser.mCurrentTab, gBrowser);
  572. }, 'bartab put on tab');
  573. key.setViewKey('R', function () {
  574. BrowserReloadSkipCache();
  575. }, '更新(キャッシュを無視)');
  576. key.setViewKey('<backspace>', function () {
  577. BrowserBack();
  578. }, '戻る');
  579. key.setViewKey('S-<backspace>', function () {
  580. BrowserForward();
  581. }, '進む');
  582. key.setViewKey('q', function (ev, arg) {
  583. ext.exec("query-then-engine", arg, ev);
  584. }, 'enter search word and then select engine', true);
  585. key.setViewKey('/', function () {
  586. command.iSearchForward();
  587. }, 'インクリメンタル検索', true);
  588. key.setViewKey('?', function (ev) {
  589. command.iSearchForwardKs(ev);
  590. }, 'Emacs ライクなインクリメンタル検索', true);
  591. key.setViewKey('a', function (ev, arg) {
  592. allTabs.open();
  593. }, 'alltabs.open');
  594. key.setViewKey('<left>', function (ev) {
  595. goDoCommand("cmd_scrollPageUp");
  596. }, '一画面分スクロールアップ');
  597. key.setViewKey('<right>', function (ev) {
  598. goDoCommand("cmd_scrollPageDown");
  599. }, '一画面スクロールダウン');
  600. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  601. return;
  602. }, 'ignore');
  603. key.setViewKey([[':'], ['P']], function (ev, arg) {
  604. return !document.getElementById("keysnail-prompt").hidden &&
  605. document.getElementById("keysnail-prompt-textbox").focus();
  606. }, 'KeySnail のプロンプトへフォーカス', true);
  607. key.setViewKey('H', function (ev, arg) {
  608. ext.exec("open-hatebu-comment", arg, ev);
  609. }, 'hatebu', true);
  610. key.setViewKey('l', function (ev) {
  611. command.focusToById("urlbar");
  612. }, 'ロケーションバーへフォーカス', true);
  613. key.setViewKey('0', function (ev) {
  614. BrowserCloseTabOrWindow();
  615. }, 'タブ / ウィンドウを閉じる');
  616. key.setViewKey('C', function (ev, arg) {
  617. ext.exec("linksnail", arg, ev);
  618. }, 'LinkSnail', true);
  619. key.setViewKey('C-<backspace>', function (ev, arg) {
  620. ext.exec("list-tab-history", arg, ev);
  621. }, 'List tab history', true);
  622. key.setViewKey('I', function (ev, arg) {
  623. ext.exec("instapaper-post-page-with-comment", arg, ev);
  624. }, 'post page and comment', true);
  625. key.setViewKey('T', function (ev, arg) {
  626. ext.exec("mstranslator-open-prompt", arg, ev);
  627. }, 'MSTranslator - Open prompt', true);
  628. key.setEditKey('C-<tab>', function (ev) {
  629. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  630. }, '次のテキストエリアへフォーカス');