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.
 
 
 
 
 
 

892 lines
34 KiB

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