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.
 
 
 
 
 
 

770 lines
30 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. //検索エンジン
  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
  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. // エクステ
  142. ext.add('radikox-play-pause', function(){
  143. radikox.turn_power();
  144. radikox.power();
  145. }, 'radikox toggle play/pause');
  146. ext.add('radikox-select-station', function(){
  147. var m = document.getElementById("radikox_menupopup");
  148. }, 'radikox station');
  149. ext.add('my-setpref', function(){
  150. util.setPrefs(
  151. {
  152. "browser.tabs.loadDivertedInBackground": true,
  153. "dom.disable_window_open_feature.location": false,
  154. "dom.max_script_run_time": 30,
  155. "browser.bookmarks.max_backups":0,
  156. "browser.urlbar.autocomplete.enabled":false,
  157. "browser.cache.memory.capacity":16384,
  158. "browser.sessionhistory.max_total_viewers":8,
  159. "browser.download.manager.closeWhenDone":true,
  160. "browser.download.useDownloadDir":false,
  161. "browser.tabs.closeWindowWithLastTab":false,
  162. "network.dns.disableIPv6":true,
  163. "browser.urlbar.trimURLs":false,
  164. "browser.fullscreen.autohide":false,
  165. "keyword.URL":"http://www.bing.com/search?q=",
  166. }
  167. );
  168. }, 'my setpref');
  169. ext.add('auto-install-plugins', function(ev, arg){
  170. var urls = [
  171. 'https://github.com/mooz/keysnail/raw/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  172. 'https://github.com/mooz/keysnail/raw/master/plugins/site-local-keymap.ks.js',
  173. 'https://github.com/azu/KeySnail-Plugins/raw/master/JSReference/js-referrence.ks.js',
  174. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  175. 'https://github.com/tkosaka/keysnail-plugin/raw/master/nicontroller.ks.js',
  176. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  177. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  178. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  179. ];
  180. function inst(a){
  181. if(a.length == 0){
  182. display.showPopup("auto-install-plugins", "All installation finished.");
  183. }else{
  184. var url = a.shift();
  185. var path = userscript.pluginDir + userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  186. if(plugins.context[path] === undefined){
  187. userscript.installPluginFromURL(url, function(){inst(a);});
  188. }else{
  189. inst(a);
  190. }
  191. }
  192. }
  193. inst(urls);
  194. }, 'Install plugins automatically if not installed yet.');
  195. ext.add('put-aside-this-page', function (ev, arg) {
  196. var n = gBrowser.mCurrentTab._tPos;
  197. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  198. if (n != 0) {
  199. gBrowser.selectedTab = gBrowser.mTabs[n];
  200. }
  201. }, 'put aside this page');
  202. ext.add('send-escape', function (ev, arg) {
  203. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  204. }, 'escape');
  205. ext.add("open-hatebu-comment", function (ev, arg) {
  206. if (window.loadURI) {
  207. loadURI("javascript:location.href='http://b.hatena.ne.jp/entry?mode=more&url='+escape(location.href);");
  208. }
  209. }, 'hatebu');
  210. ext.add("fullscreen-page",function (ev) {
  211. getBrowser().selectedTab = getBrowser().addTab("http://home.tiscali.nl/annejan/swf/timeline.swf");
  212. BrowserFullScreen();
  213. }, "fullscreen page");
  214. ext.add("focus-on-content", function(){
  215. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  216. gBrowser.focus();
  217. content.focus();
  218. }, "forcus on content");
  219. ext.add("hide-sidebar", function(){
  220. var sidebarBox = document.getElementById("sidebar-box");
  221. if (!sidebarBox.hidden) {
  222. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  223. }
  224. }, "hide-sidebar");
  225. ext.add("close-and-next-tab", function (ev, arg) {
  226. var n = gBrowser.mCurrentTab._tPos;
  227. BrowserCloseTabOrWindow();
  228. gBrowser.selectedTab = gBrowser.mTabs[n];
  229. }, "close and focus to next tab");
  230. /////////////////////////////////////
  231. // google itranslate
  232. (function(){
  233. let targetLang = "ja"; // target lang to translate into
  234. let alternativeLang = "en"; // if given word is in targetLang, use this instead as a target lang
  235. function translate(word, target, next) {
  236. next("", "", " getting...");
  237. const base = "https://www.googleapis.com/language/translate/v2?key=%s&q=%s&target=%s";
  238. const apikey = "AIzaSyBq48p8NhFgaJ1DfUJ5ltbwLxeXpjEL86A";
  239. let ep = util.format(base, apikey, encodeURIComponent(word), target);
  240. util.httpGet(ep, false, function (res) {
  241. if (res.status === 200) {
  242. let json = decodeJSON(res.responseText);
  243. let srclang = json.data.translations[0].detectedSourceLanguage;
  244. if (target == srclang) {
  245. lookupword(word, alternativeLang);
  246. } else {
  247. let result = json.data.translations[0].translatedText;
  248. next(srclang, target, result);
  249. }
  250. } else {
  251. next("", "", "ERROR!");
  252. }
  253. });
  254. };
  255. function echo(srclang, from, tglang, to){
  256. display.echoStatusBar(srclang + " : " + from + " -> " + tglang + " : " + to);
  257. };
  258. function decodeJSON(json) {
  259. return util.safeEval("(" + json + ")");
  260. };
  261. function lookupword(word, target){
  262. translate(word, target, function (src, tg, translated) {
  263. echo(src, word, tg, translated);
  264. });
  265. };
  266. function read (aInitialInput) {
  267. let prevText = "";
  268. prompt.reader({
  269. message : "word or sentence to translate:",
  270. initialinput : aInitialInput,
  271. onChange: function (arg) {
  272. let word = arg.textbox.value;
  273. if (word !== prevText) {
  274. prevText = word;
  275. lookupword(word, targetLang);
  276. }
  277. },
  278. callback: function (s){},
  279. });
  280. };
  281. ext.add("google-itranslate",function(){read(content.document.getSelection() || "");},"google itranslate");
  282. })();
  283. //////////////////////////////////////
  284. //
  285. ext.add("restart-firefox-add-menu", function(){
  286. const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  287. var cmdelm = document.createElementNS(XUL_NS, "command");
  288. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs")
  289. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  290. var commandset = document.getElementById("mainCommandSet");
  291. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  292. commandset.appendChild(cmdelm);
  293. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  294. menuelm.setAttribute("label", "Restart Firefox");
  295. menuelm.setAttribute("id", "my_menu_restartFirefoxKs")
  296. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  297. var menu = document.getElementById("menu_FilePopup");
  298. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  299. menu.appendChild(menuelm);
  300. }, "add restart firefox menu");
  301. //////////////////////////////////////
  302. // restart firefox
  303. // http://keysnail.g.hatena.ne.jp/Shinnya/20100723/1279878815
  304. ext.add("restart-firefox",function (ev) {
  305. const nsIAppStartup = Components.interfaces.nsIAppStartup;
  306. // Notify all windows that an application quit has been requested.
  307. var os = Components.classes["@mozilla.org/observer-service;1"]
  308. .getService(Components.interfaces.nsIObserverService);
  309. var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  310. .createInstance(Components.interfaces.nsISupportsPRBool);
  311. os.notifyObservers(cancelQuit, "quit-application-requested", null);
  312. // Something aborted the quit process.
  313. if (cancelQuit.data)
  314. return;
  315. // Notify all windows that an application quit has been granted.
  316. os.notifyObservers(null, "quit-application-granted", null);
  317. // Enumerate all windows and call shutdown handlers
  318. var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  319. .getService(Components.interfaces.nsIWindowMediator);
  320. var windows = wm.getEnumerator(null);
  321. while (windows.hasMoreElements()) {
  322. var win = windows.getNext();
  323. if (("tryToClose" in win) && !win.tryToClose())
  324. return;
  325. }
  326. Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
  327. .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
  328. }, "restart firefox");
  329. /////////////////////////////////////////
  330. // copy feed url
  331. ext.add("copy-url", function () {
  332. const doc = content.document;
  333. let feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  334. for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]',
  335. 'link[type="application/atom+xml"]'])))];
  336. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1");
  337. for (i = 0; i < feeds.length; i++)
  338. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  339. feeds.unshift([window.content.document.title,window.content.location.href]);
  340. prompt.selector(
  341. {
  342. message : "Select Feed",
  343. collection : feeds,
  344. callback : function (i) {
  345. if (i >= 0)
  346. command.setClipboardText(feeds[i][1]);
  347. }
  348. }
  349. );
  350. }, "Copy url or feed url of current page");
  351. ///////////////////////////////////////
  352. // 評価しちゃうっぽい とりあえずこんな感じで
  353. ext.add("keysnail-setting-menu",function(){
  354. var settingmenulist = [["keysnail setting dialogue", function(){return function(){KeySnail.openPreference();};}],
  355. ["keysnail plugin manager", function(){return function(){userscript.openPluginManager();}}],
  356. ["firefox addon manager", function(){return function(){BrowserOpenAddonsMgr();};}],
  357. ["reload .keysnail.js", function(){return function() {userscript.reload();};}],
  358. // ["check for plugins update", function(){return function(){ext.exec("check-for-plugins-update");};}],
  359. ["restart firefox", function(){return function(){ext.exec("restart-firefox");};}],
  360. ];
  361. prompt.selector(
  362. {
  363. message : "open setting dialog",
  364. collection : settingmenulist,
  365. callback : function (i) { settingmenulist[i][1]()(); },
  366. });
  367. },"open keysnail setting menu");
  368. ////////////////////////
  369. //マルチプルタブハンドラ
  370. ext.add("multiple-tab-handler-close-selected-and-current-tabs", function () {
  371. BrowserCloseTabOrWindow();
  372. // if (MultipleTabService) {
  373. // //BrowserCloseTabOrWindow();
  374. // //MultipleTabService.setSelection(gBrowser.mCurrentTab, true);
  375. MultipleTabService.closeTabs(MultipleTabService.getSelectedTabs());
  376. // } else {
  377. // BrowserCloseTabOrWindow();}
  378. }, '選択タブと現在のタブを閉じる');
  379. ext.add("if-mth-exist", function() {
  380. if (MultipleTabService === undefined) display.echoStatusBar("mth not exist.");
  381. },'if mth exist');
  382. // search web
  383. ext.add("query-then-engine", function () {
  384. prompt.reader({message : "Search Word?:",
  385. callback : function (q) {
  386. if (q) {
  387. prompt.selector({ message : "search \"" + q + "\" with?",
  388. collection : plugins.options["search-url-list"],
  389. width : [20,80],
  390. callback : function (i) { getBrowser().selectedTab = getBrowser().addTab(plugins.options["search-url-list"][i][1].replace("%r",q).replace("%q",encodeURIComponent(q))); },
  391. });
  392. };
  393. },
  394. initialInput : content.document.getSelection() || "",
  395. });
  396. }, "enter search word and then select engine");
  397. /////////////////////////////////////
  398. // 閉じたタブリスト
  399. ext.add("list-closed-tabs", function () {
  400. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  401. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  402. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  403. var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  404. if (!closedTabs.length)
  405. return void display.echoStatusBar("最近閉じたタブが見つかりませんでした", 2000);
  406. prompt.selector(
  407. {
  408. message : "select tab to undo:",
  409. collection : closedTabs,
  410. flags : [ICON | IGNORE, 0, 0],
  411. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  412. });
  413. }, "List closed tabs");
  414. ext.add("echo-closed-tabs", function () {
  415. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  416. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  417. // var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  418. var lasttab = json.decode(ss.getClosedTabData(window))[0];
  419. dump = ""
  420. for (var i in lasttab) { dump += lasttab[i] + "\n"; }
  421. confirm(dump);
  422. }, "List closed tabs");
  423. ///////////////////////////////
  424. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  425. ext.add("list-tab-history", function () {
  426. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  427. var tabHistory = [];
  428. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  429. if (sessionHistory.count < 1)
  430. return void display.echoStatusBar("Tab history not exist", 2000);
  431. var curIdx = sessionHistory.index;
  432. for (var i = 0; i < sessionHistory.count; i++) {
  433. var entry = sessionHistory.getEntryAtIndex(i, false);
  434. if (!entry)
  435. continue;
  436. try {
  437. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  438. .getService(Ci.nsIFaviconService)
  439. .getFaviconForPage(entry.URI).spec;
  440. } catch (ex) {}
  441. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  442. }
  443. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  444. if (tabHistory[thIdx][3] == curIdx) break;
  445. }
  446. prompt.selector(
  447. {
  448. message : "select history in tab",
  449. collection : tabHistory,
  450. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  451. header : ["Title", "URL"],
  452. initialIndex : thIdx,
  453. callback : function(i) { if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]); }
  454. });
  455. }, 'List tab history');
  456. //}}%PRESERVE%
  457. // ========================================================================= //
  458. // ========================= Special key settings ========================== //
  459. key.quitKey = "<delete>";
  460. key.helpKey = "C-h";
  461. key.escapeKey = "C-q";
  462. key.macroStartKey = "";
  463. key.macroEndKey = "";
  464. key.universalArgumentKey = "C-u";
  465. key.negativeArgument1Key = "C--";
  466. key.negativeArgument2Key = "C-M--";
  467. key.negativeArgument3Key = "M--";
  468. key.suspendKey = "Not defined";
  469. // ================================= Hooks ================================= //
  470. hook.addToHook('KeySnailInitialized', function () {
  471. ext.exec("shiitake-enable-style");
  472. });
  473. hook.addToHook('KeyBoardQuit', function (aEvent) {
  474. ext.exec("hide-sidebar");
  475. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  476. gBrowser.focus();
  477. content.focus();
  478. command.closeFindBar();
  479. if (util.isCaretEnabled()) {
  480. command.resetMark(aEvent);
  481. } else {
  482. goDoCommand("cmd_selectNone");
  483. }
  484. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  485. });
  486. hook.setHook('Unload', function () {
  487. util.getBrowserWindows().some(function (win) {
  488. if (win === window) {
  489. return false;
  490. }
  491. const ks = win.KeySnail;
  492. share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate);
  493. ks.setUpPluginUpdaterDelegator();
  494. return true;
  495. });
  496. });
  497. // hook.addToHook('LocationChange', function (aNsURI) {
  498. // if(window.content.document.body){
  499. // display.prettyPrint(window.content.document.title);
  500. // }else{
  501. // window.addEventListener("load", function(){
  502. // disp = display;
  503. // disp.prettyPrint(window.content.document.title);
  504. // }, false);
  505. // }
  506. // });
  507. // ============================= Key bindings ============================== //
  508. key.setGlobalKey('C-<right>', function () {
  509. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  510. }, 'ひとつ右のタブへ');
  511. key.setGlobalKey('C-<left>', function () {
  512. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  513. }, 'ひとつ左のタブへ');
  514. key.setGlobalKey('C-<up>', function () {
  515. var browser = getBrowser();
  516. if (browser.mCurrentTab.previousSibling) {
  517. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  518. } else {
  519. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  520. }
  521. }, '選択中のタブを右へ');
  522. key.setGlobalKey('C-<down>', function () {
  523. var browser = getBrowser();
  524. if (browser.mCurrentTab.nextSibling) {
  525. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  526. } else {
  527. browser.moveTabTo(browser.mCurrentTab, 0);
  528. }
  529. }, '選択中のタブを左へ');
  530. key.setGlobalKey('M-:', function (ev) {
  531. command.interpreter();
  532. }, 'JavaScript のコードを評価');
  533. key.setViewKey('D', function (ev, arg) {
  534. ext.exec("dig-url", arg, ev);
  535. }, 'dig url with selector', true);
  536. key.setViewKey('x', function (aEvent, aArg) {
  537. ext.select(aArg, aEvent);
  538. }, 'エクステ一覧');
  539. key.setViewKey(['t', 'm'], function (ev, arg) {
  540. if (window.loadURI) {
  541. loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;");
  542. }
  543. }, 'open with tweetmeme');
  544. key.setViewKey(['t', 'w'], function (ev, arg) {
  545. ext.exec("twitter-client-tweet", arg, ev);
  546. }, 'つぶやく', true);
  547. key.setViewKey(['t', 'p'], function (ev, arg) {
  548. ext.exec("twitter-client-tweet-this-page", arg, ev);
  549. }, 'このページのタイトルと URL を使ってつぶやく', true);
  550. key.setViewKey('u', function () {
  551. undoCloseTab();
  552. }, '閉じたタブを元に戻す');
  553. key.setViewKey('g', function () {
  554. goDoCommand("cmd_scrollTop");
  555. }, 'ページ先頭へ移動');
  556. key.setViewKey('G', function () {
  557. goDoCommand("cmd_scrollBottom");
  558. }, 'ページ末尾へ移動');
  559. key.setViewKey('r', function (aEvent) {
  560. BrowserReload();
  561. }, '再読み込み');
  562. key.setViewKey('m', function (ev, arg) {
  563. _fi.toogle();
  564. }, 'fetchimiをトグル');
  565. key.setViewKey('d', function (ev, arg) {
  566. if (window.loadURI) {
  567. 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()}})()");
  568. }
  569. }, 'deliciousでブックマーク');
  570. key.setViewKey('p', function (ev, arg) {
  571. if (window.loadURI) {
  572. 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{}");
  573. }
  574. }, 'posterousに投稿');
  575. key.setViewKey('SPC', function (ev, arg) {
  576. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  577. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  578. }, 'タブの選択をトグルして次のタブ');
  579. key.setViewKey('S-SPC', function (ev, arg) {
  580. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  581. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  582. }, 'タブの選択をトグルして前のタブ');
  583. key.setViewKey('z', function (ev, arg) {
  584. ext.exec("keysnail-setting-menu", arg, ev);
  585. }, 'open keysnail setting menu', true);
  586. key.setViewKey('T', function (ev, arg) {
  587. ext.exec("google-itranslate", arg, ev);
  588. }, 'google itranslate', true);
  589. key.setViewKey('C-SPC', function (ev, arg) {
  590. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  591. }, 'タブの選択をトグル');
  592. key.setViewKey('U', function (ev, arg) {
  593. ext.exec("list-closed-tabs", arg, ev);
  594. }, 'List closed tabs', true);
  595. key.setViewKey('e', function () {
  596. command.focusElement(command.elementsRetrieverTextarea, 0);
  597. }, '最初のインプットエリアへフォーカス', true);
  598. key.setViewKey('S', function (ev, arg) {
  599. if (window.loadURI) {
  600. 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{}");
  601. }
  602. }, 'google reader share');
  603. key.setViewKey('!', function (ev, arg) {
  604. shell.input();
  605. }, 'Command system');
  606. key.setViewKey('b', function (ev, arg) {
  607. BarTap.putOnTap(gBrowser.mCurrentTab, gBrowser);
  608. }, 'bartab put on tab');
  609. key.setViewKey('R', function () {
  610. BrowserReloadSkipCache();
  611. }, '更新(キャッシュを無視)');
  612. key.setViewKey('<backspace>', function () {
  613. BrowserBack();
  614. }, '戻る');
  615. key.setViewKey('S-<backspace>', function () {
  616. BrowserForward();
  617. }, '進む');
  618. key.setViewKey('q', function (ev, arg) {
  619. ext.exec("query-then-engine", arg, ev);
  620. }, 'enter search word and then select engine', true);
  621. key.setViewKey('/', function () {
  622. command.iSearchForward();
  623. }, 'インクリメンタル検索', true);
  624. key.setViewKey('?', function (ev) {
  625. command.iSearchForwardKs(ev);
  626. }, 'Emacs ライクなインクリメンタル検索', true);
  627. key.setViewKey('a', function (ev, arg) {
  628. allTabs.open();
  629. }, 'alltabs.open');
  630. key.setViewKey('<left>', function (ev) {
  631. goDoCommand("cmd_scrollPageUp");
  632. }, '一画面分スクロールアップ');
  633. key.setViewKey('<right>', function (ev) {
  634. goDoCommand("cmd_scrollPageDown");
  635. }, '一画面スクロールダウン');
  636. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  637. return;
  638. }, 'ignore');
  639. key.setViewKey(':', function (ev, arg) {
  640. return !document.getElementById("keysnail-prompt").hidden && document.getElementById("keysnail-prompt-textbox").focus();
  641. }, 'KeySnail のプロンプトへフォーカス', true);
  642. key.setViewKey('H', function (ev, arg) {
  643. ext.exec("open-hatebu-comment", arg, ev);
  644. }, 'hatebu', true);
  645. key.setViewKey('l', function (ev) {
  646. command.focusToById("urlbar");
  647. }, 'ロケーションバーへフォーカス', true);
  648. key.setViewKey('0', function (ev) {
  649. BrowserCloseTabOrWindow();
  650. }, 'タブ / ウィンドウを閉じる');
  651. key.setViewKey('C', function (ev, arg) {
  652. ext.exec("linksnail", arg, ev);
  653. }, 'LinkSnail', true);
  654. key.setViewKey('C-<backspace>', function (ev, arg) {
  655. ext.exec("list-tab-history", arg, ev);
  656. }, 'List tab history', true);
  657. key.setEditKey('C-<tab>', function (ev) {
  658. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  659. }, '次のテキストエリアへフォーカス');
  660. key.setViewKey('I', function (ev, arg) {
  661. ext.exec('instapaper-post-page-with-comment', arg, ev);
  662. }, 'post page and comment', true);
  663. key.setViewKey('C-<backspace>', function (ev, arg) {
  664. ext.exec('list-tab-history', arg, ev);
  665. }, 'List tab history', true);