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.
 
 
 
 
 
 

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