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.
 
 
 
 
 
 

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