Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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