Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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