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.
 
 
 
 
 
 

1039 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. "browser.search.defaultenginename":"Bing",
  374. "browser.search.defaulturl":"http://www.bing.com/search?q=",
  375. "network.dns.disableIPv6":true,
  376. "refcontrol.actions":
  377. "@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  378. "scrapbook.tabs.open":true
  379. }
  380. );
  381. if(/^Linux/.test(navigator.platform)){
  382. util.setPrefs(
  383. {
  384. "browser.cache.disk.parent_directory":"/tmp",
  385. "browser.cache.disk.capacity":524288
  386. }
  387. );
  388. }
  389. display.showPopup("Keysnail", "My prefs done.");
  390. }, 'my setpref');
  391. ext.add('auto-install-plugins', function(ev, arg){
  392. var urls = [
  393. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  394. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  395. 'https://raw.github.com/mooz/keysnail/master/plugins/hok.ks.js',
  396. 'https://github.com/mooz/keysnail/raw/master/plugins/builtin-commands-ext.ks.js',
  397. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  398. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  399. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  400. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  401. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  402. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  403. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  404. 'https://raw.github.com/10sr/keysnail-plugin/master/list-current-urls.ks.js',
  405. 'https://raw.github.com/gist/1976942/firefox-addon-manager.ks.js',
  406. 'https://raw.github.com/gist/1450594/mstranslator.ks.js'
  407. ];
  408. function inst(a){
  409. if(a.length == 0){
  410. display.showPopup("auto-install-plugins",
  411. "All installation finished.");
  412. }else{
  413. var url = a.shift();
  414. var path = userscript.pluginDir +
  415. userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  416. if(plugins.context[path] === undefined){
  417. userscript.installPluginFromURL(url, function(){inst(a);});
  418. }else{
  419. inst(a);
  420. }
  421. }
  422. }
  423. inst(urls);
  424. }, 'Install plugins automatically if not installed yet.');
  425. ext.add('put-aside-this-page', function (ev, arg) {
  426. var n = gBrowser.mCurrentTab._tPos;
  427. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  428. if (n != 0) {
  429. gBrowser.selectedTab = gBrowser.mTabs[n];
  430. }
  431. }, 'put aside this page');
  432. ext.add('send-escape', function (ev, arg) {
  433. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  434. }, 'escape');
  435. ext.add("open-hatebu-comment", function (ev, arg) {
  436. var url = window.content.location.href.replace(/^[^/]*\/\//, "");
  437. window.content.location.href = "http://b.hatena.ne.jp/entry/" + url;
  438. }, 'hatebu');
  439. // ext.add("focus-on-content", function(){
  440. // let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  441. // gBrowser.focus();
  442. // content.focus();
  443. // }, "forcus on content");
  444. ext.add("hide-sidebar", function(){
  445. var sidebarBox = document.getElementById("sidebar-box");
  446. if (!sidebarBox.hidden) {
  447. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  448. }
  449. }, "hide-sidebar");
  450. ext.add("close-and-next-tab", function (ev, arg) {
  451. var n = gBrowser.mCurrentTab._tPos;
  452. gBrowser.removeCurrentTab();
  453. gBrowser.selectedTab = gBrowser.mTabs[n];
  454. }, "close and focus to next tab");
  455. //////////////////////////////////////
  456. //
  457. ext.add("restart-firefox-add-menu", function(){
  458. const XUL_NS =
  459. "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  460. var cmdelm = document.createElementNS(XUL_NS, "command");
  461. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  462. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  463. var commandset = document.getElementById("mainCommandSet");
  464. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  465. commandset.appendChild(cmdelm);
  466. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  467. menuelm.setAttribute("label", "Restart Firefox");
  468. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  469. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  470. var menu = document.getElementById("menu_FilePopup");
  471. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  472. menu.appendChild(menuelm);
  473. }, "add restart firefox menu");
  474. /////////////////////////////////////////
  475. // feed url
  476. ext.add("feed-add-to-feedly", function(){
  477. var url = window.content.location.href;
  478. window.content.location.href =
  479. "http://cloud.feedly.com/#subscription%2Ffeed%2F" +
  480. encodeURIComponent(url);
  481. }, "Add current feed to feedly");
  482. (function(){
  483. var feedhandler = "http://cloud.feedly.com/#subscription%2Ffeed%2F%s";
  484. function getFeeds(){
  485. const doc = content.document;
  486. var feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  487. for ([, e] in Iterator(doc.querySelectorAll([
  488. 'link[type="application/rss+xml"]',
  489. 'link[type="application/atom+xml"]'
  490. ])))];
  491. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,
  492. "$1");
  493. for (i = 0; i < feeds.length; i++)
  494. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  495. // feeds.unshift([window.content.document.title,
  496. // window.content.location.href]);
  497. return feeds;
  498. };
  499. ext.add("copy-feed-url", function () {
  500. var feeds = getFeeds();
  501. if (! feeds.length) {
  502. display.echoStatusBar("No feed found.");
  503. return;
  504. }
  505. prompt.selector(
  506. {
  507. message : "Select Feed",
  508. collection : feeds,
  509. callback : function (i) {
  510. if (i >= 0) {
  511. command.setClipboardText(feeds[i][1]);
  512. }
  513. }
  514. }
  515. );
  516. }, "Copy url or feed url of current page");
  517. ext.add("open-feed", function () {
  518. var feeds = getFeeds();
  519. if (! feeds.length) {
  520. display.echoStatusBar("No feed found.");
  521. return;
  522. }
  523. prompt.selector({
  524. message : "Select Feed",
  525. collection : feeds,
  526. callback : function (i) {
  527. if (i < 0) {
  528. return;
  529. }
  530. var feedurl = feeds[i][1];
  531. if (feedhandler) {
  532. window.openUILinkIn(
  533. feedhandler.replace("%s", feedurl),
  534. "tab"
  535. );
  536. } else {
  537. window.openUILinkIn(feedurl, "tab");
  538. }
  539. }
  540. });
  541. }, "Copy url or feed url of current page");
  542. })();
  543. ///////////////////////////////////////
  544. // keysnail z menu
  545. ext.add("keysnail-setting-dialog", function(){
  546. KeySnail.openPreference();
  547. }, "keysnail setting dialog");
  548. ext.add("keysnail-plugin-manager", function(){
  549. userscript.openPluginManager();
  550. }, "keysnail plugin manager");
  551. ext.add("firefox-open-addon-manager", function(){
  552. BrowserOpenAddonsMgr();
  553. }, "firefox addon manager");
  554. ext.add("keysnail-reload-init-file", function(){
  555. userscript.reload();
  556. }, "keysnail reload init file");
  557. ext.add("keysnail-z-menu",function(){
  558. var list = [["keysnail-setting-dialog"],
  559. ["keysnail-plugin-manager"],
  560. ["firefox-open-addon-manager"],
  561. ["keysnail-reload-init-file"],
  562. // ["check-for-plugins-update"],
  563. ["restart-firefox"]
  564. ];
  565. prompt.selector(
  566. {
  567. message : "open setting dialog",
  568. collection : list,
  569. callback : function (i) {
  570. ext.exec(list[i][0]);
  571. }
  572. });
  573. },"open keysnail z menu");
  574. ///////////////////////////////////
  575. // search web
  576. ext.add("query-then-engine", function () {
  577. prompt.reader({
  578. message : "Search Word?:",
  579. group : "query_word",
  580. completer : completer.matcher.header(share.friendsCache || []),
  581. callback : function (q) {
  582. if (q) {
  583. prompt.selector({
  584. message : "search \"" + q + "\" with?",
  585. collection : plugins.options["search-url-list"],
  586. width : [20,80],
  587. callback : function (i) {
  588. getBrowser().selectedTab =
  589. getBrowser().addTab(
  590. plugins.options["search-url-list"][i][1].
  591. replace("%r",q).replace(
  592. "%q",encodeURIComponent(q)));
  593. }
  594. });
  595. };
  596. },
  597. initialInput : content.document.getSelection() || ""
  598. });
  599. }, "enter search word and then select engine");
  600. /////////////////////////////////////
  601. // closed tab list
  602. ext.add("list-closed-tabs", function () {
  603. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  604. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(
  605. Ci.nsISessionStore
  606. );
  607. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  608. var closedTabs = [[tab.image || fav, tab.title, tab.url]
  609. for each (tab in json.decode(ss.getClosedTabData(window)))
  610. ];
  611. if (!closedTabs.length)
  612. return void display.echoStatusBar("No recently closed tab.", 2000);
  613. prompt.selector(
  614. {
  615. message : "select tab to undo:",
  616. collection : closedTabs,
  617. flags : [ICON | IGNORE, 0, 0],
  618. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  619. });
  620. }, "List closed tabs");
  621. ///////////////////////////////
  622. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  623. ext.add("list-tab-history", function () {
  624. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  625. var tabHistory = [];
  626. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  627. if (sessionHistory.count < 1)
  628. return void display.echoStatusBar("Tab history not exist", 2000);
  629. var curIdx = sessionHistory.index;
  630. for (var i = 0; i < sessionHistory.count; i++) {
  631. var entry = sessionHistory.getEntryAtIndex(i, false);
  632. if (!entry)
  633. continue;
  634. try {
  635. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  636. .getService(Ci.nsIFaviconService)
  637. .getFaviconForPage(entry.URI).spec;
  638. } catch (ex) {}
  639. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  640. }
  641. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  642. if (tabHistory[thIdx][3] == curIdx) break;
  643. }
  644. prompt.selector(
  645. {
  646. message : "select history in tab",
  647. collection : tabHistory,
  648. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  649. header : ["Title", "URL"],
  650. initialIndex : thIdx,
  651. callback : function(i) {
  652. if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]);
  653. }
  654. });
  655. }, 'List tab history');
  656. //}}%PRESERVE%
  657. // ========================================================================= //
  658. // ========================= Special key settings ========================== //
  659. key.quitKey = "ESC";
  660. key.helpKey = "<f1>";
  661. key.escapeKey = "C-q";
  662. key.macroStartKey = "";
  663. key.macroEndKey = "";
  664. key.universalArgumentKey = "C-u";
  665. key.negativeArgument1Key = "C--";
  666. key.negativeArgument2Key = "C-M--";
  667. key.negativeArgument3Key = "M--";
  668. key.suspendKey = "Not defined";
  669. // ================================= Hooks ================================= //
  670. hook.setHook('KeyBoardQuit', function (aEvent) {
  671. // ext.exec("hide-sidebar");
  672. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  673. gBrowser.focus();
  674. content.focus();
  675. command.closeFindBar();
  676. if (util.isCaretEnabled()) {
  677. command.resetMark(aEvent);
  678. } else {
  679. goDoCommand("cmd_selectNone");
  680. }
  681. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  682. });
  683. hook.setHook('Unload', function () {
  684. util.getBrowserWindows().some(function (win) {
  685. if (win === window) {
  686. return false;
  687. }
  688. const ks = win.KeySnail;
  689. share.pluginUpdater = ks.getPluginUpdater(
  690. share.pluginUpdater.pluginsWithUpdate);
  691. ks.setUpPluginUpdaterDelegator();
  692. return true;
  693. });
  694. });
  695. // ============================= Key bindings ============================== //
  696. key.setGlobalKey('C-<right>', function () {
  697. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  698. }, 'ひとつ右のタブへ');
  699. key.setGlobalKey('C-<left>', function () {
  700. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  701. }, 'ひとつ左のタブへ');
  702. key.setGlobalKey('C-<up>', function () {
  703. var browser = getBrowser();
  704. if (browser.mCurrentTab.previousSibling) {
  705. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  706. } else {
  707. browser.moveTabTo(browser.mCurrentTab,
  708. browser.mTabContainer.childNodes.length - 1);
  709. }
  710. }, '選択中のタブを右へ');
  711. key.setGlobalKey('C-<down>', function () {
  712. var browser = getBrowser();
  713. if (browser.mCurrentTab.nextSibling) {
  714. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  715. } else {
  716. browser.moveTabTo(browser.mCurrentTab, 0);
  717. }
  718. }, '選択中のタブを左へ');
  719. key.setGlobalKey('<delete>', function (ev, arg) {
  720. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  721. gBrowser.focus();
  722. content.focus();
  723. }, 'コンテンツへフォーカス', true);
  724. key.setGlobalKey('<f11>', function (ev, arg) {
  725. ext.exec("strong-fullscreen", arg, ev);
  726. }, 'go fullscreen with hiding toolbar and tabbar', true);
  727. key.setViewKey('0', function (ev) {
  728. BrowserCloseTabOrWindow();
  729. }, 'タブ / ウィンドウを閉じる');
  730. key.setViewKey('N', function (ev) {
  731. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  732. }, 'ひとつ右のタブへ');
  733. key.setViewKey('P', function (ev) {
  734. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  735. }, 'ひとつ左のタブへ');
  736. key.setViewKey('o', function (ev, arg) {
  737. ext.exec("hok-start-foreground-mode", arg, ev);
  738. }, 'Start Hit a Hint foreground mode', true);
  739. key.setViewKey('c', function (ev) {
  740. command.interpreter();
  741. }, 'JavaScript のコードを評価');
  742. key.setViewKey('D', function (ev, arg) {
  743. ext.exec("dig-url", arg, ev);
  744. }, 'dig url with selector', true);
  745. key.setViewKey('x', function (aEvent, aArg) {
  746. ext.select(aArg, aEvent);
  747. }, 'エクステ一覧');
  748. key.setViewKey(['t', 'w'], function (ev, arg) {
  749. ext.exec("twitter-client-tweet", arg, ev);
  750. }, 'つぶやく', true);
  751. key.setViewKey(['t', 'p'], function (ev, arg) {
  752. ext.exec("twitter-client-tweet-this-page", arg, ev);
  753. }, 'このページのタイトルと URL を使ってつぶやく', true);
  754. key.setViewKey('u', function (ev) {
  755. goDoCommand("cmd_scrollPageUp");
  756. }, '一画面分スクロールアップ');
  757. key.setViewKey('g', function () {
  758. goDoCommand("cmd_scrollTop");
  759. }, 'ページ先頭へ移動');
  760. key.setViewKey('G', function () {
  761. goDoCommand("cmd_scrollBottom");
  762. }, 'ページ末尾へ移動');
  763. key.setViewKey('r', function (aEvent) {
  764. BrowserReload();
  765. }, '再読み込み');
  766. key.setViewKey('m', function (ev, arg) {
  767. _fi.toogle();
  768. }, 'fetchimiをトグル');
  769. key.setViewKey('z', function (ev, arg) {
  770. ext.exec("keysnail-z-menu", arg, ev);
  771. }, 'open keysnail setting menu', true);
  772. key.setViewKey('e', function () {
  773. command.focusElement(command.elementsRetrieverTextarea, 0);
  774. }, '最初のインプットエリアへフォーカス', true);
  775. key.setViewKey('S', function (ev, arg) {
  776. if (window.loadURI) {
  777. 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{}");
  778. }
  779. }, 'google reader share');
  780. key.setViewKey('!', function (ev, arg) {
  781. shell.input();
  782. }, 'Command system');
  783. key.setViewKey('R', function () {
  784. BrowserReloadSkipCache();
  785. }, '更新(キャッシュを無視)');
  786. key.setViewKey('<backspace>', function () {
  787. BrowserBack();
  788. }, '戻る');
  789. key.setViewKey('S-<backspace>', function () {
  790. BrowserForward();
  791. }, '進む');
  792. key.setViewKey('q', function (ev, arg) {
  793. ext.exec("query-then-engine", arg, ev);
  794. }, 'enter search word and then select engine', true);
  795. key.setViewKey('/', function () {
  796. command.iSearchForward();
  797. }, 'インクリメンタル検索', true);
  798. key.setViewKey('?', function (ev) {
  799. command.iSearchForwardKs(ev);
  800. }, 'Emacs ライクなインクリメンタル検索', true);
  801. key.setViewKey('a', function (ev, arg) {
  802. allTabs.open();
  803. }, 'alltabs.open');
  804. key.setViewKey('d', function (ev) {
  805. goDoCommand("cmd_scrollPageDown");
  806. }, '一画面スクロールダウン');
  807. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  808. return;
  809. }, 'ignore');
  810. key.setViewKey(':', function (ev, arg) {
  811. return !document.getElementById("keysnail-prompt").hidden &&
  812. document.getElementById("keysnail-prompt-textbox").focus();
  813. }, 'KeySnail のプロンプトへフォーカス', true);
  814. key.setViewKey('B', function (ev) {
  815. var browser = getBrowser();
  816. if (browser.mCurrentTab.previousSibling) {
  817. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  818. } else {
  819. browser.moveTabTo(browser.mCurrentTab,
  820. browser.mTabContainer.childNodes.length - 1);
  821. }
  822. }, '選択中のタブを左へ');
  823. key.setViewKey('C', function (ev, arg) {
  824. ext.exec("linksnail", arg, ev);
  825. }, 'LinkSnail', true);
  826. key.setViewKey('C-<backspace>', function (ev, arg) {
  827. ext.exec("list-tab-history", arg, ev);
  828. }, 'List tab history', true);
  829. key.setViewKey('I', function (ev, arg) {
  830. ext.exec("instapaper-post-page-with-comment", arg, ev);
  831. }, 'post page and comment', true);
  832. key.setViewKey('T', function (ev, arg) {
  833. ext.exec("mstranslator-open-prompt", arg, ev);
  834. }, 'MSTranslator - Open prompt', true);
  835. key.setViewKey('n', function (ev) {
  836. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  837. }, '一行スクロールダウン');
  838. key.setViewKey('p', function (ev) {
  839. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  840. }, '一行スクロールアップ');
  841. key.setViewKey('f', function (ev, arg) {
  842. ext.exec('strong-fullscreen', arg, ev);
  843. }, 'go fullscreen with hiding toolbar and tabbar', true);
  844. key.setViewKey('b', function (ev) {
  845. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  846. }, '左へスクロール');
  847. key.setViewKey('F', function (ev) {
  848. var browser = getBrowser();
  849. if (browser.mCurrentTab.nextSibling) {
  850. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  851. } else {
  852. browser.moveTabTo(browser.mCurrentTab, 0);
  853. }
  854. }, '選択中のタブを右へ');
  855. key.setViewKey('U', function (ev, arg) {
  856. ext.exec("list-closed-tabs", arg, ev);
  857. }, 'List closed tabs', true);
  858. key.setEditKey('C-<tab>', function (ev) {
  859. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  860. }, '次のテキストエリアへフォーカス');
  861. key.setEditKey('C-a', function (ev) {
  862. command.beginLine(ev);
  863. }, '行頭へ移動');
  864. key.setEditKey('C-e', function (ev) {
  865. command.endLine(ev);
  866. }, '行末へ');
  867. key.setEditKey('C-d', function (ev) {
  868. goDoCommand("cmd_deleteCharForward");
  869. }, '次の一文字削除');
  870. key.setEditKey('C-b', function (ev) {
  871. command.previousChar(ev);
  872. }, '一文字左へ移動');
  873. key.setEditKey('C-f', function (ev) {
  874. command.nextChar(ev);
  875. }, '一文字右へ移動');
  876. key.setEditKey('C-h', function (ev) {
  877. goDoCommand("cmd_deleteCharBackward");
  878. }, '前の一文字を削除');
  879. key.setEditKey('C-k', function (ev) {
  880. command.killLine(ev);
  881. }, 'カーソルから先を一行カット (Kill line)');
  882. key.setEditKey('C-l', function (ev) {
  883. command.recenter(ev);
  884. }, 'カーソル位置が画面の中央へ来るようスクロール', true);
  885. key.setEditKey('C-n', function (ev) {
  886. command.nextLine(ev);
  887. }, '一行下へ');
  888. key.setEditKey('C-p', function (ev) {
  889. command.previousLine(ev);
  890. }, '一行上へ');
  891. key.setEditKey('C-o', function (ev) {
  892. command.openLine(ev);
  893. }, '行を開く (Open line)');
  894. key.setViewKey('S-SPC', function (ev) {
  895. goDoCommand("cmd_scrollPageUp");
  896. }, '一画面分スクロールアップ');
  897. key.setViewKey('SPC', function (ev) {
  898. goDoCommand("cmd_scrollPageDown");
  899. }, '一画面スクロールダウン');