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.
 
 
 
 
 
 

995 lines
35 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. // Original is at https://gist.github.com/Griever/62715
  13. (function(){
  14. // this makes all clicks open in new tab.
  15. return;
  16. // test if firefox 12
  17. if (12 > parseFloat(Cc['@mozilla.org/xre/app-info;1'].
  18. getService(Ci.nsIXULAppInfo).version)) {
  19. return;
  20. }
  21. whereToOpenLink_org = whereToOpenLink;
  22. eval('whereToOpenLink = ' + whereToOpenLink_org.toString()
  23. .replace('if (ctrl', 'if (true')
  24. // .replace('if (ctrl', 'if (ctrl && !shift|| !ctrl && shift')
  25. // .replace('if (shift ||', 'if (shift && ctrl ||')
  26. // .replace('middle && middleUsesTabs',
  27. // 'middle && middleUsesTabs && !alt')
  28. );
  29. })();
  30. //////////////////////////////////////
  31. //// sitelocalkeymap
  32. var local = {};
  33. plugins.options["site_local_keymap.local_keymap"] = local;
  34. function fake(k, i) function(){ key.feed(k, i); };
  35. function pass(k, i) [k, fake(k, i)];
  36. function ignore(k, i) [k, null];
  37. // ext.add("ext-name", function () {}, "ext description");
  38. // style.register("");
  39. // local["^http://"] = [['a', function(ev, arg){}],];
  40. ///////////////////////////////////////////
  41. //// firefox
  42. // style.register("#bookmarksPanel > hbox,#history-panel > hbox {" +
  43. // "display: none !important;}" +
  44. // " //#urlbar-container{max-width: 500px !important;}");
  45. // style.register( //not work
  46. // <><![CDATA[
  47. // input,textarea {
  48. // font-family: monospace !important;
  49. // }
  50. // ]]></>.toString()
  51. // );
  52. style.register(
  53. '@-moz-document url-prefix(\"http://www.tumblr.com/\") { #pagination {' +
  54. 'position: fixed;' +
  55. 'bottom: 50px;' +
  56. 'right: 100px;' +
  57. 'padding-right: 0px !important' +
  58. '} }' , style.XHTML);
  59. ///////////////////////////////////
  60. //search engine
  61. plugins.options["search-url-list"] = [
  62. ["bing","http://bing.com/search?q=%q"],
  63. ["yatwitter search","http://yats-data.com/yats/search?query=%q"],
  64. ["twitter search","http://twitter.com/search?q=%q&lang=all"],
  65. ["tospy", "http://topsy.com/s?allow_lang=ja&q=%q"],
  66. ["2ch","http://2ch-ranking.net/search.php?q=%q&imp=and&order=time"],
  67. ["I\'m feelig lucky!","http://www.google.co.jp/search?q=%q&btnI=kudos"],
  68. ["uncyclopedia","http://ja.uncyclopedia.info/wiki/%q"],
  69. ["wikipedia","http://ja.wikipedia.org/wiki/%q"],
  70. ["nicovideo.jp","http://www.nicovideo.jp/search/%q"],
  71. ["alc","http://eow.alc.co.jp/%q/UTF-8/"],
  72. ["google map",
  73. "http://maps.google.co.jp/maps?hl=ja&q=%q&um=1&ie=UTF-8&sa=N&tab=wl"],
  74. ["weblio","http://www.weblio.jp/content_find?query=%q"],
  75. ["shoutcast","http://www.shoutcast.com/Internet-Radio/%q"],
  76. ["delicious 10sr",
  77. "http://delicious.com/10sr?addtag=%q&setcount=50&opennew=1"],
  78. ["open raw","%r"]
  79. ];
  80. plugins.options["my-keysnail-bookmarks"] = [
  81. "twitter.com"
  82. ];
  83. // sitelocal keymap
  84. //////////////////////////////////////////
  85. // 2ch chaika
  86. // change chaika port every time firefox starts
  87. util.setIntPref("extensions.chaika.server_port.firefox",
  88. 8800 + Math.floor(Math.random() * 30));
  89. local["^http://127.0.0.1:88"] = [
  90. ['k', function(ev, arg){
  91. curl = window.content.location.href;
  92. kurl = curl.replace(/http:.*thread\/(.*\/).*/, "chaika://post/$1");
  93. window.content.location.href = kurl;
  94. }
  95. ]
  96. ];
  97. local["^http://w2.p2.2ch.net/p2/read.php"] = [
  98. ['k', function(ev, arg){
  99. var url = window.content.location.href;
  100. var pt = /host=(.*?)&bbs=(.*?)&key=(.*?)&ls=/ ;
  101. var result = url.match(pt);
  102. var k = format("chaika://post/http://%s/test/read.cgi/%s/%s/",
  103. result[1], result[2], result[3]);
  104. window.content.location.href = k;
  105. }
  106. ]
  107. ];
  108. /////////////////////////////////////////
  109. // feedly
  110. local["^http://(www|cloud)\.feedly\.com/"] = [
  111. ['d', null],
  112. ['j', null],
  113. ['k', null],
  114. ['n', null],
  115. ['p', null],
  116. ['o', null],
  117. ['b', null],
  118. ['S', null],
  119. ['s', null],
  120. ['?', null],
  121. ['r', null],
  122. ['g', null],
  123. // ['x', function(ev, arg){
  124. // ev.target.dispatchEvent(key.stringToKeyEvent("g", true));
  125. // }],
  126. ['l', function(ev, arg){
  127. var host = window.content.location.host;
  128. if (host === "cloud.feedly.com") {
  129. window.content.location.href = "http://" + host + "/#latest";
  130. } else if (host === "www.feedly.com") {
  131. window.content.location.href = "http://" + host + "/home#latest";
  132. }
  133. }],
  134. [['t', 'p'], function(ev, arg){
  135. ev.target.dispatchEvent(key.stringToKeyEvent("t", true));
  136. }],
  137. [['t', 'w'], function(ev, arg){
  138. ext.exec("twitter-client-tweet", arg, ev);
  139. }]
  140. ];
  141. /////////////////////////////////////////
  142. //nicovideo
  143. local["http://(www|tw|es|de|)\.nicovideo\.jp\/(watch|playlist)/*"] = [
  144. ["i", function(ev, arg){ ext.exec("nicoinfo", arg); }],
  145. ["p", function(ev, arg){ ext.exec("nicopause", arg); }],
  146. // ["o", function(ev, arg){ ext.exec("nicommentvisible", arg); }],
  147. ["m", function(ev, arg){ ext.exec("nicomute", arg); }],
  148. [".", function(ev, arg){ ext.exec("nicovolumeIncrement", arg); }],
  149. [",", function(ev, arg){ ext.exec("nicovolumeDecrement", arg); }],
  150. ['f', function(ev, arg){
  151. curl = window.content.location.href;
  152. kurl = curl.replace(/nicovideo.jp/, "nicovideofire.jp");
  153. window.content.location.href = kurl;
  154. }
  155. ]
  156. ];
  157. /////////////////////////////////////////
  158. // tumblr/dashboard
  159. local["^http://www.tumblr.com/dashboard"] = [
  160. // ["C-<left>", function(ev, arg){
  161. // gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  162. // }],
  163. // ["C-<right>", function(ev, arg){
  164. // gBrowser.mTabContainer.advanceSelectedTab(1, true);
  165. // }],
  166. ["<left>", function(ev, arg){
  167. window.content.location.href = "http://www.tumblr.com/dashboard";
  168. }],
  169. ["<right>", null],
  170. ["J", function(ev, arg){
  171. if (window.loadURI) {
  172. 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;}())");
  173. }
  174. }]
  175. ];
  176. ///////////////////////////////////////////
  177. // plugin option
  178. plugins.options["builtin_commands_ext.ext_list"] = [
  179. "focus-to-prompt",
  180. "open-url-from-clipboard",
  181. "restart-firefox"
  182. ];
  183. plugins.options["instapaper.close_after_post"] = true;
  184. plugins.options["instapaper.initial_comment_function"] = function(){
  185. var now = new Date();
  186. return "[" + now.toString() + "]";
  187. };
  188. //////////////////////////////////////////
  189. // yatc
  190. style.register("#keysnail-twitter-client-container{ display:none !important; }");
  191. plugins.options["twitter_client.popup_new_statuses"] = false;
  192. plugins.options["twitter_client.automatically_begin"] = false;
  193. plugins.options["twitter_client.automatically_begin_list"] = false;
  194. plugins.options["twitter_client.timeline_count_beginning"] = 0;
  195. plugins.options["twitter_client.timeline_count_every_updates"] = 0;
  196. plugins.options["twitter_client.tweet_keymap"] = {
  197. "C-RET" : "prompt-decide",
  198. "RET" : ""
  199. };
  200. plugins.options["twitter_client.jmp_id"] = "10sr";
  201. plugins.options["twitter_client.jmp_key"] =
  202. "R_c51f889a77cb4b4e993ed868f65083f5";
  203. plugins.options["twitter_client.use_jmp"] = true;
  204. ////////////////////////////////////////////
  205. // my ext
  206. (function(){
  207. function getOrganizer(){
  208. // [How to call for Firefox bookmark dialog? - Stack Overflow]
  209. // (http://stackoverflow.com/questions/9158187/how-to-call-for-firefox-bookmark-dialog)
  210. Components.utils.import("resource://gre/modules/Services.jsm");
  211. var organizer = Services.wm.getMostRecentWindow("Places:Organizer");
  212. if (!organizer) {
  213. // No currently open places window,
  214. // so open one with the specified mode.
  215. openDialog("chrome://browser/content/places/places.xul",
  216. "",
  217. "chrome,toolbar=yes,dialog=no,resizable",
  218. "AllBookmarks");
  219. return null;
  220. } else {
  221. return organizer;
  222. }
  223. }
  224. ext.add("export-bookmarks", function(ev, arg){
  225. var organizer = getOrganizer();
  226. if (organizer) {
  227. organizer.PlacesOrganizer.exportBookmarks();
  228. }
  229. }, "export bookmarks");
  230. ext.add("import-bookmarks", function(ev, arg){
  231. var organizer = getOrganizer();
  232. if (organizer) {
  233. organizer.PlacesOrganizer.importBookmarks();
  234. }
  235. }, "import bookmarks");
  236. })();
  237. ext.add("my-index-html", function(ev, arg){
  238. homepath = util.getEnv("HOME");
  239. file = ".index.html";
  240. if (homepath) {
  241. path = "file://" + homepath + "/" + file;
  242. window.openUILinkIn(path, "tab");
  243. }
  244. }, "open my index.html");
  245. ext.add("echo-tab-info", function(){
  246. var all = gBrowser.tabs.length;
  247. var ix = gBrowser.mCurrentTab._tPos;
  248. var title = window.document.title;
  249. var url = window.content.location.href;
  250. display.echoStatusBar((ix + 1).toString() + " / " +
  251. all.toString() + " : " +
  252. title + " <" +
  253. url + ">");
  254. }, "echo tab info");
  255. ext.add("strong-fullscreen", function(){
  256. var elemids = [
  257. "navigator-toolbox"
  258. ];
  259. BrowserFullScreen();
  260. var isfullscreen = window.fullScreen;
  261. for(var i = 0; i < elemids.length; i++){
  262. var elem = document.getElementById(elemids[i]);
  263. if(elem){
  264. if(isfullscreen){
  265. elem.style.display = "none";
  266. }else{
  267. elem.style.display = null;
  268. }
  269. }
  270. }
  271. var tabs = document.getElementById("verticaltabs-box");
  272. if(tabs){
  273. var pref_key = "extensions.verticaltabs.width";
  274. var pref_key_bak = pref_key + "_bak";
  275. if(isfullscreen){
  276. var width_orig = util.getIntPref(pref_key);
  277. util.setIntPref(pref_key_bak, width_orig);
  278. util.setIntPref(pref_key, 0);
  279. tabs.setAttribute("width", "0");
  280. }else if(parseInt(tabs.getAttribute("width") || "") === 0){
  281. var width_bak = util.getIntPref(pref_key_bak);
  282. util.setIntPref(pref_key, width_bak);
  283. tabs.setAttribute("width", width_bak.toString());
  284. }
  285. }
  286. }, "go fullscreen with hiding toolbar and tabbar");
  287. ext.add("bookmark-delicious", function(){
  288. f= 'http://www.delicious.com/save?url=' +
  289. encodeURIComponent(window.content.location.href) +
  290. '&title=' + encodeURIComponent(document.title) +
  291. '&notes=' + encodeURIComponent(
  292. '' + (window.getSelection ?
  293. window.getSelection() : (
  294. document.getSelection ?
  295. document.getSelection() :
  296. document.selection.createRange().text))) + '&v=6&';
  297. a = function(){
  298. if(! window.open(
  299. f + 'noui=1&jump=doclose',
  300. 'deliciousuiv6',
  301. 'location=1,links=0,scrollbars=0,toolbar=0,width=710,height=660')){
  302. location.href = f + 'jump=yes';
  303. }
  304. };
  305. if(/Firefox/.test(navigator.userAgent)){
  306. setTimeout(a,0);
  307. }else{
  308. a();
  309. }
  310. }, "bookmark delicious");
  311. ext.add('view-page-source', function(){
  312. window.content.location.href = "view-source:" +
  313. window.content.location.href;
  314. }, 'view page source');
  315. ext.add('my-setpref', function(){
  316. util.setPrefs(
  317. {
  318. "browser.bookmarks.max_backups":0,
  319. "browser.cache.memory.capacity":16384,
  320. "browser.download.manager.closeWhenDone":true,
  321. "browser.download.useDownloadDir":false,
  322. "browser.fullscreen.autohide":false,
  323. "browser.search.openintab":true,
  324. "browser.sessionhistory.max_total_viewers":8,
  325. "browser.sessionstore.restore_on_demand":true,
  326. "browser.tabs.closeWindowWithLastTab":false,
  327. "browser.tabs.loadDivertedInBackground": true,
  328. "browser.urlbar.autocomplete.enabled":false,
  329. "browser.urlbar.trimURLs":false,
  330. "dom.disable_window_open_feature.location": false,
  331. "dom.max_script_run_time": 30,
  332. "extensions.chaika.bbsmenu.open_new_tab":true,
  333. "extensions.chaika.bbsmenu.open_single_click":false,
  334. "extensions.chaika.board.open_new_tab":true,
  335. "extensions.chaika.board.open_single_click":false,
  336. "extensions.foxage2ch.openThreadInTab":true,
  337. "extensions.saveimageinfolder.general-duplicatefilenamevalue":1,
  338. "extensions.saveimageinfolder.general-fileprefixvalue":
  339. "%yyyy%%MM%%dd%-%hh%%mm%%ss%_",
  340. "extensions.saveimageinfolder.usecache":true,
  341. "extensions.tabutils.openTabNext":1,
  342. "extensions.tabutils.styles.current":
  343. "{\"bold\":true,\"italic\":false,\"underline\":true,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#000000\",\"bgColor\":false,\"bgColorCode\":\"#000000\",\"outline\":false,\"outlineColorCode\":\"#000000\"}",
  344. "extensions.tabutils.styles.unread":
  345. "{\"bold\":false,\"italic\":false,\"underline\":false,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#CC0000\",\"bgColor\":false,\"bgColorCode\":\"undefined\",\"outline\":false,\"outlineColorCode\":\"undefined\"}",
  346. "extensions.yass.edgetype":0,
  347. "extensions.yass.selectedpreset":"red",
  348. "font.default.x-western":"sans-serif",
  349. "gecko.handlerService.schemes.mailto.1.name":"Gmail",
  350. "general.warnOnAboutConfig":false,
  351. "keyword.URL":"http://www.bing.com/search?q=",
  352. "network.dns.disableIPv6":true,
  353. "refcontrol.actions":
  354. "@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  355. "scrapbook.tabs.open":true
  356. }
  357. );
  358. if(/^Linux/.test(navigator.platform)){
  359. util.setPrefs(
  360. {
  361. "browser.cache.disk.parent_directory":"/tmp",
  362. "browser.cache.disk.capacity":524288
  363. }
  364. );
  365. }
  366. display.showPopup("Keysnail", "My prefs done.");
  367. }, 'my setpref');
  368. ext.add('auto-install-plugins', function(ev, arg){
  369. var urls = [
  370. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  371. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  372. 'https://raw.github.com/mooz/keysnail/master/plugins/hok.ks.js',
  373. 'https://github.com/mooz/keysnail/raw/master/plugins/builtin-commands-ext.ks.js',
  374. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  375. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  376. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  377. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  378. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  379. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  380. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  381. 'https://raw.github.com/10sr/keysnail-plugin/master/list-current-urls.ks.js',
  382. 'https://raw.github.com/gist/1976942/firefox-addon-manager.ks.js',
  383. 'https://raw.github.com/gist/1450594/mstranslator.ks.js'
  384. ];
  385. function inst(a){
  386. if(a.length == 0){
  387. display.showPopup("auto-install-plugins",
  388. "All installation finished.");
  389. }else{
  390. var url = a.shift();
  391. var path = userscript.pluginDir +
  392. userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  393. if(plugins.context[path] === undefined){
  394. userscript.installPluginFromURL(url, function(){inst(a);});
  395. }else{
  396. inst(a);
  397. }
  398. }
  399. }
  400. inst(urls);
  401. }, 'Install plugins automatically if not installed yet.');
  402. ext.add('put-aside-this-page', function (ev, arg) {
  403. var n = gBrowser.mCurrentTab._tPos;
  404. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  405. if (n != 0) {
  406. gBrowser.selectedTab = gBrowser.mTabs[n];
  407. }
  408. }, 'put aside this page');
  409. ext.add('send-escape', function (ev, arg) {
  410. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  411. }, 'escape');
  412. ext.add("open-hatebu-comment", function (ev, arg) {
  413. var url = window.content.location.href.replace(/^[^/]*\/\//, "");
  414. window.content.location.href = "http://b.hatena.ne.jp/entry/" + url;
  415. }, 'hatebu');
  416. // ext.add("focus-on-content", function(){
  417. // let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  418. // gBrowser.focus();
  419. // content.focus();
  420. // }, "forcus on content");
  421. ext.add("hide-sidebar", function(){
  422. var sidebarBox = document.getElementById("sidebar-box");
  423. if (!sidebarBox.hidden) {
  424. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  425. }
  426. }, "hide-sidebar");
  427. ext.add("close-and-next-tab", function (ev, arg) {
  428. var n = gBrowser.mCurrentTab._tPos;
  429. gBrowser.removeCurrentTab();
  430. gBrowser.selectedTab = gBrowser.mTabs[n];
  431. }, "close and focus to next tab");
  432. //////////////////////////////////////
  433. //
  434. ext.add("restart-firefox-add-menu", function(){
  435. const XUL_NS =
  436. "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  437. var cmdelm = document.createElementNS(XUL_NS, "command");
  438. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  439. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  440. var commandset = document.getElementById("mainCommandSet");
  441. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  442. commandset.appendChild(cmdelm);
  443. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  444. menuelm.setAttribute("label", "Restart Firefox");
  445. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  446. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  447. var menu = document.getElementById("menu_FilePopup");
  448. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  449. menu.appendChild(menuelm);
  450. }, "add restart firefox menu");
  451. /////////////////////////////////////////
  452. // feed url
  453. (function(){
  454. function getFeeds(){
  455. const doc = content.document;
  456. var feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  457. for ([, e] in Iterator(doc.querySelectorAll([
  458. 'link[type="application/rss+xml"]',
  459. 'link[type="application/atom+xml"]'
  460. ])))];
  461. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,
  462. "$1");
  463. for (i = 0; i < feeds.length; i++)
  464. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  465. feeds.unshift([window.content.document.title,
  466. window.content.location.href]);
  467. return feeds;
  468. };
  469. ext.add("copy-feed-url", function () {
  470. var feeds = getFeeds();
  471. prompt.selector(
  472. {
  473. message : "Select Feed",
  474. collection : feeds,
  475. callback : function (i) {
  476. if (i >= 0) {
  477. command.setClipboardText(feeds[i][1]);
  478. }
  479. }
  480. }
  481. );
  482. }, "Copy url or feed url of current page");
  483. ext.add("open-feed", function () {
  484. var feeds = getFeeds();
  485. prompt.selector(
  486. {
  487. message : "Select Feed",
  488. collection : feeds,
  489. callback : function (i) {
  490. if (i >= 0) {
  491. window.openUILinkIn(feeds[i][1], "tab");
  492. }
  493. }
  494. }
  495. );
  496. }, "Copy url or feed url of current page");
  497. })();
  498. ///////////////////////////////////////
  499. // keysnail z menu
  500. ext.add("keysnail-setting-dialog", function(){
  501. KeySnail.openPreference();
  502. }, "keysnail setting dialog");
  503. ext.add("keysnail-plugin-manager", function(){
  504. userscript.openPluginManager();
  505. }, "keysnail plugin manager");
  506. ext.add("firefox-open-addon-manager", function(){
  507. BrowserOpenAddonsMgr();
  508. }, "firefox addon manager");
  509. ext.add("keysnail-reload-init-file", function(){
  510. userscript.reload();
  511. }, "keysnail reload init file");
  512. ext.add("keysnail-z-menu",function(){
  513. var list = [["keysnail-setting-dialog"],
  514. ["keysnail-plugin-manager"],
  515. ["firefox-open-addon-manager"],
  516. ["keysnail-reload-init-file"],
  517. // ["check-for-plugins-update"],
  518. ["restart-firefox"]
  519. ];
  520. prompt.selector(
  521. {
  522. message : "open setting dialog",
  523. collection : list,
  524. callback : function (i) {
  525. ext.exec(list[i][0]);
  526. }
  527. });
  528. },"open keysnail z menu");
  529. ///////////////////////////////////
  530. // search web
  531. ext.add("query-then-engine", function () {
  532. prompt.reader({
  533. message : "Search Word?:",
  534. group : "query_word",
  535. completer : completer.matcher.header(share.friendsCache || []),
  536. callback : function (q) {
  537. if (q) {
  538. prompt.selector({
  539. message : "search \"" + q + "\" with?",
  540. collection : plugins.options["search-url-list"],
  541. width : [20,80],
  542. callback : function (i) {
  543. getBrowser().selectedTab =
  544. getBrowser().addTab(
  545. plugins.options["search-url-list"][i][1].
  546. replace("%r",q).replace(
  547. "%q",encodeURIComponent(q)));
  548. }
  549. });
  550. };
  551. },
  552. initialInput : content.document.getSelection() || ""
  553. });
  554. }, "enter search word and then select engine");
  555. /////////////////////////////////////
  556. // closed tab list
  557. ext.add("list-closed-tabs", function () {
  558. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  559. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(
  560. Ci.nsISessionStore
  561. );
  562. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  563. var closedTabs = [[tab.image || fav, tab.title, tab.url]
  564. for each (tab in json.decode(ss.getClosedTabData(window)))
  565. ];
  566. if (!closedTabs.length)
  567. return void display.echoStatusBar("No recently closed tab.", 2000);
  568. prompt.selector(
  569. {
  570. message : "select tab to undo:",
  571. collection : closedTabs,
  572. flags : [ICON | IGNORE, 0, 0],
  573. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  574. });
  575. }, "List closed tabs");
  576. ///////////////////////////////
  577. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  578. ext.add("list-tab-history", function () {
  579. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  580. var tabHistory = [];
  581. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  582. if (sessionHistory.count < 1)
  583. return void display.echoStatusBar("Tab history not exist", 2000);
  584. var curIdx = sessionHistory.index;
  585. for (var i = 0; i < sessionHistory.count; i++) {
  586. var entry = sessionHistory.getEntryAtIndex(i, false);
  587. if (!entry)
  588. continue;
  589. try {
  590. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  591. .getService(Ci.nsIFaviconService)
  592. .getFaviconForPage(entry.URI).spec;
  593. } catch (ex) {}
  594. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  595. }
  596. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  597. if (tabHistory[thIdx][3] == curIdx) break;
  598. }
  599. prompt.selector(
  600. {
  601. message : "select history in tab",
  602. collection : tabHistory,
  603. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  604. header : ["Title", "URL"],
  605. initialIndex : thIdx,
  606. callback : function(i) {
  607. if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]);
  608. }
  609. });
  610. }, 'List tab history');
  611. //}}%PRESERVE%
  612. // ========================================================================= //
  613. // ========================= Special key settings ========================== //
  614. key.quitKey = "ESC";
  615. key.helpKey = "<f1>";
  616. key.escapeKey = "C-q";
  617. key.macroStartKey = "";
  618. key.macroEndKey = "";
  619. key.universalArgumentKey = "C-u";
  620. key.negativeArgument1Key = "C--";
  621. key.negativeArgument2Key = "C-M--";
  622. key.negativeArgument3Key = "M--";
  623. key.suspendKey = "Not defined";
  624. // ================================= Hooks ================================= //
  625. hook.setHook('KeyBoardQuit', function (aEvent) {
  626. ext.exec("hide-sidebar");
  627. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  628. gBrowser.focus();
  629. content.focus();
  630. command.closeFindBar();
  631. if (util.isCaretEnabled()) {
  632. command.resetMark(aEvent);
  633. } else {
  634. goDoCommand("cmd_selectNone");
  635. }
  636. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  637. });
  638. hook.setHook('Unload', function () {
  639. util.getBrowserWindows().some(function (win) {
  640. if (win === window) {
  641. return false;
  642. }
  643. const ks = win.KeySnail;
  644. share.pluginUpdater = ks.getPluginUpdater(
  645. share.pluginUpdater.pluginsWithUpdate
  646. );
  647. ks.setUpPluginUpdaterDelegator();
  648. return true;
  649. });
  650. });
  651. // ============================= Key bindings ============================== //
  652. key.setGlobalKey('C-<right>', function () {
  653. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  654. }, 'ひとつ右のタブへ');
  655. key.setGlobalKey('C-<left>', function () {
  656. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  657. }, 'ひとつ左のタブへ');
  658. key.setGlobalKey('C-<up>', function () {
  659. var browser = getBrowser();
  660. if (browser.mCurrentTab.previousSibling) {
  661. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  662. } else {
  663. browser.moveTabTo(browser.mCurrentTab,
  664. browser.mTabContainer.childNodes.length - 1);
  665. }
  666. }, '選択中のタブを右へ');
  667. key.setGlobalKey('C-<down>', function () {
  668. var browser = getBrowser();
  669. if (browser.mCurrentTab.nextSibling) {
  670. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  671. } else {
  672. browser.moveTabTo(browser.mCurrentTab, 0);
  673. }
  674. }, '選択中のタブを左へ');
  675. key.setGlobalKey('<delete>', function (ev, arg) {
  676. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  677. gBrowser.focus();
  678. content.focus();
  679. }, 'コンテンツへフォーカス', true);
  680. key.setGlobalKey('<f11>', function (ev, arg) {
  681. ext.exec("strong-fullscreen", arg, ev);
  682. }, 'go fullscreen with hiding toolbar and tabbar', true);
  683. key.setViewKey('0', function (ev) {
  684. BrowserCloseTabOrWindow();
  685. }, 'タブ / ウィンドウを閉じる');
  686. key.setViewKey('N', function (ev) {
  687. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  688. }, 'ひとつ右のタブへ');
  689. key.setViewKey('P', function (ev) {
  690. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  691. }, 'ひとつ左のタブへ');
  692. key.setViewKey('o', function (ev, arg) {
  693. ext.exec("hok-start-foreground-mode", arg, ev);
  694. }, 'Start Hit a Hint foreground mode', true);
  695. key.setViewKey('c', function (ev) {
  696. command.interpreter();
  697. }, 'JavaScript のコードを評価');
  698. key.setViewKey('D', function (ev, arg) {
  699. ext.exec("dig-url", arg, ev);
  700. }, 'dig url with selector', true);
  701. key.setViewKey('x', function (aEvent, aArg) {
  702. ext.select(aArg, aEvent);
  703. }, 'エクステ一覧');
  704. key.setViewKey(['t', 'w'], function (ev, arg) {
  705. ext.exec("twitter-client-tweet", arg, ev);
  706. }, 'つぶやく', true);
  707. key.setViewKey(['t', 'p'], function (ev, arg) {
  708. ext.exec("twitter-client-tweet-this-page", arg, ev);
  709. }, 'このページのタイトルと URL を使ってつぶやく', true);
  710. key.setViewKey([['u'], ['<left>']], function (ev) {
  711. goDoCommand("cmd_scrollPageUp");
  712. }, '一画面分スクロールアップ');
  713. key.setViewKey('g', function () {
  714. goDoCommand("cmd_scrollTop");
  715. }, 'ページ先頭へ移動');
  716. key.setViewKey('G', function () {
  717. goDoCommand("cmd_scrollBottom");
  718. }, 'ページ末尾へ移動');
  719. key.setViewKey('r', function (aEvent) {
  720. BrowserReload();
  721. }, '再読み込み');
  722. key.setViewKey('m', function (ev, arg) {
  723. _fi.toogle();
  724. }, 'fetchimiをトグル');
  725. key.setViewKey('SPC', function (ev, arg) {
  726. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  727. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  728. }, 'タブの選択をトグルして次のタブ');
  729. key.setViewKey('S-SPC', function (ev, arg) {
  730. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  731. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  732. }, 'タブの選択をトグルして前のタブ');
  733. key.setViewKey('z', function (ev, arg) {
  734. ext.exec("keysnail-z-menu", arg, ev);
  735. }, 'open keysnail setting menu', true);
  736. key.setViewKey('C-SPC', function (ev, arg) {
  737. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  738. }, 'タブの選択をトグル');
  739. key.setViewKey('e', function () {
  740. command.focusElement(command.elementsRetrieverTextarea, 0);
  741. }, '最初のインプットエリアへフォーカス', true);
  742. key.setViewKey('S', function (ev, arg) {
  743. if (window.loadURI) {
  744. 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{}");
  745. }
  746. }, 'google reader share');
  747. key.setViewKey('!', function (ev, arg) {
  748. shell.input();
  749. }, 'Command system');
  750. key.setViewKey('R', function () {
  751. BrowserReloadSkipCache();
  752. }, '更新(キャッシュを無視)');
  753. key.setViewKey('<backspace>', function () {
  754. BrowserBack();
  755. }, '戻る');
  756. key.setViewKey('S-<backspace>', function () {
  757. BrowserForward();
  758. }, '進む');
  759. key.setViewKey('q', function (ev, arg) {
  760. ext.exec("query-then-engine", arg, ev);
  761. }, 'enter search word and then select engine', true);
  762. key.setViewKey('/', function () {
  763. command.iSearchForward();
  764. }, 'インクリメンタル検索', true);
  765. key.setViewKey('?', function (ev) {
  766. command.iSearchForwardKs(ev);
  767. }, 'Emacs ライクなインクリメンタル検索', true);
  768. key.setViewKey('a', function (ev, arg) {
  769. allTabs.open();
  770. }, 'alltabs.open');
  771. key.setViewKey([['<right>'], ['d']], function (ev) {
  772. goDoCommand("cmd_scrollPageDown");
  773. }, '一画面スクロールダウン');
  774. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  775. return;
  776. }, 'ignore');
  777. key.setViewKey(':', function (ev, arg) {
  778. return !document.getElementById("keysnail-prompt").hidden &&
  779. document.getElementById("keysnail-prompt-textbox").focus();
  780. }, 'KeySnail のプロンプトへフォーカス', true);
  781. key.setViewKey('B', function (ev) {
  782. var browser = getBrowser();
  783. if (browser.mCurrentTab.previousSibling) {
  784. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  785. } else {
  786. browser.moveTabTo(browser.mCurrentTab,
  787. browser.mTabContainer.childNodes.length - 1);
  788. }
  789. }, '選択中のタブを左へ');
  790. key.setViewKey('C', function (ev, arg) {
  791. ext.exec("linksnail", arg, ev);
  792. }, 'LinkSnail', true);
  793. key.setViewKey('C-<backspace>', function (ev, arg) {
  794. ext.exec("list-tab-history", arg, ev);
  795. }, 'List tab history', true);
  796. key.setViewKey('I', function (ev, arg) {
  797. ext.exec("instapaper-post-page-with-comment", arg, ev);
  798. }, 'post page and comment', true);
  799. key.setViewKey('T', function (ev, arg) {
  800. ext.exec("mstranslator-open-prompt", arg, ev);
  801. }, 'MSTranslator - Open prompt', true);
  802. key.setViewKey('n', function (ev) {
  803. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  804. }, '一行スクロールダウン');
  805. key.setViewKey('p', function (ev) {
  806. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  807. }, '一行スクロールアップ');
  808. key.setViewKey('f', function (ev) {
  809. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  810. }, '右へスクロール');
  811. key.setViewKey('b', function (ev) {
  812. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  813. }, '左へスクロール');
  814. key.setViewKey('F', function (ev) {
  815. var browser = getBrowser();
  816. if (browser.mCurrentTab.nextSibling) {
  817. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  818. } else {
  819. browser.moveTabTo(browser.mCurrentTab, 0);
  820. }
  821. }, '選択中のタブを右へ');
  822. key.setViewKey('U', function (ev, arg) {
  823. ext.exec("list-closed-tabs", arg, ev);
  824. }, 'List closed tabs', true);
  825. key.setEditKey('C-<tab>', function (ev) {
  826. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  827. }, '次のテキストエリアへフォーカス');
  828. key.setEditKey('C-a', function (ev) {
  829. command.beginLine(ev);
  830. }, '行頭へ移動');
  831. key.setEditKey('C-e', function (ev) {
  832. command.endLine(ev);
  833. }, '行末へ');
  834. key.setEditKey('C-d', function (ev) {
  835. goDoCommand("cmd_deleteCharForward");
  836. }, '次の一文字削除');
  837. key.setEditKey('C-b', function (ev) {
  838. command.previousChar(ev);
  839. }, '一文字左へ移動');
  840. key.setEditKey('C-f', function (ev) {
  841. command.nextChar(ev);
  842. }, '一文字右へ移動');
  843. key.setEditKey('C-h', function (ev) {
  844. goDoCommand("cmd_deleteCharBackward");
  845. }, '前の一文字を削除');
  846. key.setEditKey('C-k', function (ev) {
  847. command.killLine(ev);
  848. }, 'カーソルから先を一行カット (Kill line)');
  849. key.setEditKey('C-l', function (ev) {
  850. command.recenter(ev);
  851. }, 'カーソル位置が画面の中央へ来るようスクロール', true);
  852. key.setEditKey('C-n', function (ev) {
  853. command.nextLine(ev);
  854. }, '一行下へ');
  855. key.setEditKey('C-p', function (ev) {
  856. command.previousLine(ev);
  857. }, '一行上へ');
  858. key.setEditKey('C-o', function (ev) {
  859. command.openLine(ev);
  860. }, '行を開く (Open line)');
  861. key.setViewKey('f', function (ev, arg) {
  862. ext.exec('strong-fullscreen', arg, ev);
  863. }, 'go fullscreen with hiding toolbar and tabbar', true);