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.
 
 
 
 
 
 

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