25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1040 lines
36 KiB

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