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.
 
 
 
 
 
 

873 lines
33 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. "verticaltabs-box",
  164. "verticaltabs-splitter"
  165. ];
  166. BrowserFullScreen();
  167. var isfullscreen = window.fullScreen;
  168. for(var i = 0; i < elemids.length; i++){
  169. var elem = document.getElementById(elemids[i]);
  170. if(elem){ elem.hidden = isfullscreen; }
  171. }
  172. }, "go fullscreen with hiding toolbar and tabbar");
  173. // ext.add("open-url-from-clipboard", function(){
  174. // var list = command.getClipboardText().split("\n");
  175. // for(var i = 0; i < list.length; i++){
  176. // if(list[i] != ""){
  177. // gBrowser.loadOneTab(list[i], null, null, null, false);
  178. // }
  179. // }
  180. // }, "open tabs of newline separated url list from clipboard");
  181. ext.add("list-page-url", function(){
  182. var urls = [];
  183. var aa = window.content.document.getElementsByTagName("a");
  184. var text = "";
  185. var alt = "";
  186. for (var i = 0; i < aa.length ; i++) {
  187. if(aa[i].href == ""){ continue; }
  188. if (aa[i].text == "" && aa[i].hasChildNodes() && aa[i].childNodes[0].nodeType == Node.ELEMENT_NODE){
  189. alt = aa[i].childNodes[0].getAttribute("alt");
  190. text = " " + aa[i].childNodes[0].nodeName + (alt ? ": " + alt : "");
  191. }else{
  192. text = aa[i].text;
  193. }
  194. urls.push([text, decodeURIComponent(aa[i].href)]);
  195. }
  196. if(urls.length == 0){
  197. display.echoStatusBar("No url found.");
  198. return;
  199. }
  200. prompt.selector(
  201. {
  202. message : "Select URL",
  203. collection : urls,
  204. width : [35, 65],
  205. header : ["text", "url"],
  206. callback : function (i) {
  207. if (i >= 0)
  208. openUILinkIn(urls[i][1], "tab"); // or current tabshifted window
  209. }
  210. }
  211. );
  212. }, "list url");
  213. ext.add("bookmark-delicious", function(){
  214. f= 'http://www.delicious.com/save?url=' + encodeURIComponent(window.content.location.href) +
  215. '&title=' + encodeURIComponent(document.title) +
  216. '&notes=' + encodeURIComponent('' + (window.getSelection ?
  217. window.getSelection() : document.getSelection ?
  218. document.getSelection() : document.selection.createRange().text)) + '&v=6&';
  219. a = function(){
  220. if(! window.open(f + 'noui=1&jump=doclose', 'deliciousuiv6', 'location=1,links=0,scrollbars=0,toolbar=0,width=710,height=660')){
  221. location.href = f + 'jump=yes';
  222. }
  223. };
  224. if(/Firefox/.test(navigator.userAgent)){
  225. setTimeout(a,0);
  226. }else{
  227. a();
  228. }
  229. }, "bookmark delicious");
  230. ext.add('view-page-source', function(){
  231. window.content.location.href = "view-source:" + window.content.location.href;
  232. }, 'view page source');
  233. ext.add('my-setpref', function(){
  234. util.setPrefs(
  235. {
  236. "browser.bookmarks.max_backups":0,
  237. "browser.cache.memory.capacity":16384,
  238. "browser.download.manager.closeWhenDone":true,
  239. "browser.download.useDownloadDir":false,
  240. "browser.fullscreen.autohide":false,
  241. "browser.search.openintab":true,
  242. "browser.sessionhistory.max_total_viewers":8,
  243. "browser.sessionstore.restore_on_demand":true,
  244. "browser.tabs.closeWindowWithLastTab":false,
  245. "browser.tabs.loadDivertedInBackground": true,
  246. "browser.urlbar.autocomplete.enabled":false,
  247. "browser.urlbar.trimURLs":false,
  248. "dom.disable_window_open_feature.location": false,
  249. "dom.max_script_run_time": 30,
  250. "extensions.chaika.bbsmenu.open_new_tab":true,
  251. "extensions.chaika.bbsmenu.open_single_click":false,
  252. "extensions.chaika.board.open_new_tab":true,
  253. "extensions.chaika.board.open_single_click":false,
  254. "extensions.foxage2ch.openThreadInTab":true,
  255. "extensions.saveimageinfolder.general-duplicatefilenamevalue":1,
  256. "extensions.saveimageinfolder.general-fileprefixvalue":"%yyyy%%MM%%dd%-%hh%%mm%%ss%_",
  257. "extensions.saveimageinfolder.usecache":true,
  258. "extensions.tabutils.openTabNext":1,
  259. "extensions.tabutils.styles.current":"{\"bold\":true,\"italic\":false,\"underline\":true,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#000000\",\"bgColor\":false,\"bgColorCode\":\"#000000\",\"outline\":false,\"outlineColorCode\":\"#000000\"}",
  260. "extensions.tabutils.styles.unread":"{\"bold\":false,\"italic\":false,\"underline\":false,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#CC0000\",\"bgColor\":false,\"bgColorCode\":\"undefined\",\"outline\":false,\"outlineColorCode\":\"undefined\"}",
  261. "extensions.yass.edgetype":0,
  262. "extensions.yass.selectedpreset":"red",
  263. "font.default.x-western":"sans-serif",
  264. "general.warnOnAboutConfig":false,
  265. "keyword.URL":"http://www.bing.com/search?q=",
  266. "network.dns.disableIPv6":true,
  267. "refcontrol.actions":"@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  268. "scrapbook.tabs.open":true
  269. }
  270. );
  271. if(/^Linux/.test(navigator.platform)){
  272. util.setPrefs(
  273. {
  274. "browser.cache.disk.parent_directory":"/tmp",
  275. "browser.cache.disk.capacity":524288
  276. }
  277. );
  278. }
  279. display.showPopup("Keysnail", "My prefs done.");
  280. }, 'my setpref');
  281. ext.add('auto-install-plugins', function(ev, arg){
  282. var urls = [
  283. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  284. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  285. 'https://raw.github.com/mooz/keysnail/master/plugins/hok.ks.js',
  286. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  287. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  288. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  289. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  290. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  291. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  292. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  293. 'https://raw.github.com/gist/1976942/firefox-addon-manager.ks.js',
  294. 'https://raw.github.com/gist/1450594/mstranslator.ks.js'
  295. ];
  296. function inst(a){
  297. if(a.length == 0){
  298. display.showPopup("auto-install-plugins", "All installation finished.");
  299. }else{
  300. var url = a.shift();
  301. var path = userscript.pluginDir + userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  302. if(plugins.context[path] === undefined){
  303. userscript.installPluginFromURL(url, function(){inst(a);});
  304. }else{
  305. inst(a);
  306. }
  307. }
  308. }
  309. inst(urls);
  310. }, 'Install plugins automatically if not installed yet.');
  311. ext.add('put-aside-this-page', function (ev, arg) {
  312. var n = gBrowser.mCurrentTab._tPos;
  313. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  314. if (n != 0) {
  315. gBrowser.selectedTab = gBrowser.mTabs[n];
  316. }
  317. }, 'put aside this page');
  318. ext.add('send-escape', function (ev, arg) {
  319. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  320. }, 'escape');
  321. ext.add("open-hatebu-comment", function (ev, arg) {
  322. if (window.loadURI) {
  323. loadURI("javascript:location.href='http://b.hatena.ne.jp/entry?mode=more&url='+escape(location.href);");
  324. }
  325. }, 'hatebu');
  326. // ext.add("focus-on-content", function(){
  327. // let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  328. // gBrowser.focus();
  329. // content.focus();
  330. // }, "forcus on content");
  331. ext.add("hide-sidebar", function(){
  332. var sidebarBox = document.getElementById("sidebar-box");
  333. if (!sidebarBox.hidden) {
  334. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  335. }
  336. }, "hide-sidebar");
  337. ext.add("close-and-next-tab", function (ev, arg) {
  338. var n = gBrowser.mCurrentTab._tPos;
  339. gBrowser.removeCurrentTab();
  340. gBrowser.selectedTab = gBrowser.mTabs[n];
  341. }, "close and focus to next tab");
  342. //////////////////////////////////////
  343. //
  344. ext.add("restart-firefox-add-menu", function(){
  345. const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  346. var cmdelm = document.createElementNS(XUL_NS, "command");
  347. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  348. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  349. var commandset = document.getElementById("mainCommandSet");
  350. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  351. commandset.appendChild(cmdelm);
  352. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  353. menuelm.setAttribute("label", "Restart Firefox");
  354. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  355. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  356. var menu = document.getElementById("menu_FilePopup");
  357. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  358. menu.appendChild(menuelm);
  359. }, "add restart firefox menu");
  360. //////////////////////////////////////
  361. // restart firefox
  362. // http://keysnail.g.hatena.ne.jp/Shinnya/20100723/1279878815
  363. // ext.add("restart-firefox",function (ev) {
  364. // const nsIAppStartup = Components.interfaces.nsIAppStartup;
  365. // // Notify all windows that an application quit has been requested.
  366. // var os = Components.classes["@mozilla.org/observer-service;1"]
  367. // .getService(Components.interfaces.nsIObserverService);
  368. // var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  369. // .createInstance(Components.interfaces.nsISupportsPRBool);
  370. // os.notifyObservers(cancelQuit, "quit-application-requested", null);
  371. // // Something aborted the quit process.
  372. // if (cancelQuit.data)
  373. // return;
  374. // // Notify all windows that an application quit has been granted.
  375. // os.notifyObservers(null, "quit-application-granted", null);
  376. // // Enumerate all windows and call shutdown handlers
  377. // var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  378. // .getService(Components.interfaces.nsIWindowMediator);
  379. // var windows = wm.getEnumerator(null);
  380. // while (windows.hasMoreElements()) {
  381. // var win = windows.getNext();
  382. // if (("tryToClose" in win) && !win.tryToClose())
  383. // return;
  384. // }
  385. // Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
  386. // .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
  387. // }, "restart firefox");
  388. /////////////////////////////////////////
  389. // copy feed url
  390. ext.add("copy-url", function () {
  391. const doc = content.document;
  392. let feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  393. for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]',
  394. 'link[type="application/atom+xml"]'])))];
  395. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1");
  396. for (i = 0; i < feeds.length; i++)
  397. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  398. feeds.unshift([window.content.document.title,window.content.location.href]);
  399. prompt.selector(
  400. {
  401. message : "Select Feed",
  402. collection : feeds,
  403. callback : function (i) {
  404. if (i >= 0)
  405. command.setClipboardText(feeds[i][1]);
  406. }
  407. }
  408. );
  409. }, "Copy url or feed url of current page");
  410. ///////////////////////////////////////
  411. // keysnail z menu
  412. ext.add("keysnail-setting-dialog", function(){
  413. KeySnail.openPreference();
  414. }, "keysnail setting dialog");
  415. ext.add("keysnail-plugin-manager", function(){
  416. userscript.openPluginManager();
  417. }, "keysnail plugin manager");
  418. ext.add("firefox-open-addon-manager", function(){
  419. BrowserOpenAddonsMgr();
  420. }, "firefox addon manager");
  421. ext.add("keysnail-reload-init-file", function(){
  422. userscript.reload();
  423. }, "keysnail reload init file");
  424. ext.add("keysnail-z-menu",function(){
  425. var list = [["keysnail-setting-dialog"],
  426. ["keysnail-plugin-manager"],
  427. ["forefox-open-addon-manager"],
  428. ["keysnail-reload-init-file"],
  429. // ["check-for-plugins-update"],
  430. ["restart-firefox"]
  431. ];
  432. prompt.selector(
  433. {
  434. message : "open setting dialog",
  435. collection : list,
  436. callback : function (i) {
  437. ext.exec(list[i][0]);
  438. }
  439. });
  440. },"open keysnail z menu");
  441. ///////////////////////////////////
  442. // search web
  443. ext.add("query-then-engine", function () {
  444. prompt.reader({message : "Search Word?:",
  445. callback : function (q) {
  446. if (q) {
  447. prompt.selector({ message : "search \"" + q + "\" with?",
  448. collection : plugins.options["search-url-list"],
  449. width : [20,80],
  450. callback : function (i) {
  451. getBrowser().selectedTab = getBrowser().addTab(plugins.options["search-url-list"][i][1].replace("%r",q).replace("%q",encodeURIComponent(q)));
  452. },
  453. });
  454. };
  455. },
  456. initialInput : content.document.getSelection() || "",
  457. });
  458. }, "enter search word and then select engine");
  459. /////////////////////////////////////
  460. // closed tab list
  461. ext.add("list-closed-tabs", function () {
  462. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  463. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  464. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  465. var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  466. if (!closedTabs.length)
  467. return void display.echoStatusBar("No recently closed tab.", 2000);
  468. prompt.selector(
  469. {
  470. message : "select tab to undo:",
  471. collection : closedTabs,
  472. flags : [ICON | IGNORE, 0, 0],
  473. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  474. });
  475. }, "List closed tabs");
  476. // ext.add("echo-closed-tabs", function () {
  477. // var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  478. // var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  479. // // var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  480. // var lasttab = json.decode(ss.getClosedTabData(window))[0];
  481. // dump = ""
  482. // for (var i in lasttab) { dump += lasttab[i] + "\n"; }
  483. // confirm(dump);
  484. // }, "List closed tabs");
  485. ///////////////////////////////
  486. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  487. ext.add("list-tab-history", function () {
  488. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  489. var tabHistory = [];
  490. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  491. if (sessionHistory.count < 1)
  492. return void display.echoStatusBar("Tab history not exist", 2000);
  493. var curIdx = sessionHistory.index;
  494. for (var i = 0; i < sessionHistory.count; i++) {
  495. var entry = sessionHistory.getEntryAtIndex(i, false);
  496. if (!entry)
  497. continue;
  498. try {
  499. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  500. .getService(Ci.nsIFaviconService)
  501. .getFaviconForPage(entry.URI).spec;
  502. } catch (ex) {}
  503. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  504. }
  505. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  506. if (tabHistory[thIdx][3] == curIdx) break;
  507. }
  508. prompt.selector(
  509. {
  510. message : "select history in tab",
  511. collection : tabHistory,
  512. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  513. header : ["Title", "URL"],
  514. initialIndex : thIdx,
  515. callback : function(i) { if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]); }
  516. });
  517. }, 'List tab history');
  518. //}}%PRESERVE%
  519. // ========================================================================= //
  520. // ========================= Special key settings ========================== //
  521. key.quitKey = "ESC";
  522. key.helpKey = "<f1>";
  523. key.escapeKey = "C-q";
  524. key.macroStartKey = "";
  525. key.macroEndKey = "";
  526. key.universalArgumentKey = "C-u";
  527. key.negativeArgument1Key = "C--";
  528. key.negativeArgument2Key = "C-M--";
  529. key.negativeArgument3Key = "M--";
  530. key.suspendKey = "Not defined";
  531. // ================================= Hooks ================================= //
  532. hook.setHook('KeyBoardQuit', function (aEvent) {
  533. ext.exec("hide-sidebar");
  534. // focus to content
  535. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  536. gBrowser.focus();
  537. content.focus();
  538. command.closeFindBar();
  539. if (util.isCaretEnabled()) {
  540. command.resetMark(aEvent);
  541. } else {
  542. goDoCommand("cmd_selectNone");
  543. }
  544. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  545. });
  546. hook.setHook('Unload', function () {
  547. util.getBrowserWindows().some(function (win) {
  548. if (win === window) {
  549. return false;
  550. }
  551. const ks = win.KeySnail;
  552. share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate);
  553. ks.setUpPluginUpdaterDelegator();
  554. return true;
  555. });
  556. });
  557. // ============================= Key bindings ============================== //
  558. key.setGlobalKey('C-<right>', function () {
  559. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  560. }, 'ひとつ右のタブへ');
  561. key.setGlobalKey('C-<left>', function () {
  562. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  563. }, 'ひとつ左のタブへ');
  564. key.setGlobalKey('C-<up>', function () {
  565. var browser = getBrowser();
  566. if (browser.mCurrentTab.previousSibling) {
  567. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  568. } else {
  569. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  570. }
  571. }, '選択中のタブを右へ');
  572. key.setGlobalKey('C-<down>', function () {
  573. var browser = getBrowser();
  574. if (browser.mCurrentTab.nextSibling) {
  575. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  576. } else {
  577. browser.moveTabTo(browser.mCurrentTab, 0);
  578. }
  579. }, '選択中のタブを左へ');
  580. key.setGlobalKey('C-h', function (ev, arg) {
  581. return;
  582. }, 'ignore');
  583. key.setGlobalKey('<delete>', function (ev, arg) {
  584. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  585. gBrowser.focus();
  586. content.focus();
  587. }, 'コンテンツへフォーカス', true);
  588. key.setGlobalKey('C-p', function (ev, arg) {
  589. return !document.getElementById("keysnail-prompt").hidden &&
  590. document.getElementById("keysnail-prompt-textbox").focus();
  591. }, 'KeySnail のプロンプトへフォーカス', true);
  592. key.setViewKey('J', function (ev) {
  593. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  594. }, 'ひとつ右のタブへ');
  595. key.setViewKey('K', function (ev) {
  596. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  597. }, 'ひとつ左のタブへ');
  598. key.setViewKey('o', function (ev, arg) {
  599. ext.exec("hok-start-foreground-mode", arg, ev);
  600. }, 'Start Hit a Hint foreground mode', true);
  601. key.setViewKey('c', function (ev) {
  602. command.interpreter();
  603. }, 'JavaScript のコードを評価');
  604. key.setViewKey('D', function (ev, arg) {
  605. ext.exec("dig-url", arg, ev);
  606. }, 'dig url with selector', true);
  607. key.setViewKey('x', function (aEvent, aArg) {
  608. ext.select(aArg, aEvent);
  609. }, 'エクステ一覧');
  610. key.setViewKey(['t', 'm'], function (ev, arg) {
  611. if (window.loadURI) {
  612. loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;");
  613. }
  614. }, 'open with tweetmeme');
  615. key.setViewKey(['t', 'w'], function (ev, arg) {
  616. ext.exec("twitter-client-tweet", arg, ev);
  617. }, 'つぶやく', true);
  618. key.setViewKey(['t', 'p'], function (ev, arg) {
  619. ext.exec("twitter-client-tweet-this-page", arg, ev);
  620. }, 'このページのタイトルと URL を使ってつぶやく', true);
  621. key.setViewKey([['u'], ['<left>']], function (ev) {
  622. goDoCommand("cmd_scrollPageUp");
  623. }, '一画面分スクロールアップ');
  624. key.setViewKey('g', function () {
  625. goDoCommand("cmd_scrollTop");
  626. }, 'ページ先頭へ移動');
  627. key.setViewKey('G', function () {
  628. goDoCommand("cmd_scrollBottom");
  629. }, 'ページ末尾へ移動');
  630. key.setViewKey('r', function (aEvent) {
  631. BrowserReload();
  632. }, '再読み込み');
  633. key.setViewKey('m', function (ev, arg) {
  634. _fi.toogle();
  635. }, 'fetchimiをトグル');
  636. key.setViewKey('p', function (ev, arg) {
  637. if (window.loadURI) {
  638. 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{}");
  639. }
  640. }, 'posterousに投稿');
  641. key.setViewKey('SPC', function (ev, arg) {
  642. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  643. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  644. }, 'タブの選択をトグルして次のタブ');
  645. key.setViewKey('S-SPC', function (ev, arg) {
  646. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  647. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  648. }, 'タブの選択をトグルして前のタブ');
  649. key.setViewKey('z', function (ev, arg) {
  650. ext.exec("keysnail-z-menu", arg, ev);
  651. }, 'open keysnail setting menu', true);
  652. key.setViewKey('C-SPC', function (ev, arg) {
  653. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  654. }, 'タブの選択をトグル');
  655. key.setViewKey('e', function () {
  656. command.focusElement(command.elementsRetrieverTextarea, 0);
  657. }, '最初のインプットエリアへフォーカス', true);
  658. key.setViewKey('S', function (ev, arg) {
  659. if (window.loadURI) {
  660. 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{}");
  661. }
  662. }, 'google reader share');
  663. key.setViewKey('!', function (ev, arg) {
  664. shell.input();
  665. }, 'Command system');
  666. key.setViewKey('R', function () {
  667. BrowserReloadSkipCache();
  668. }, '更新(キャッシュを無視)');
  669. key.setViewKey('<backspace>', function () {
  670. BrowserBack();
  671. }, '戻る');
  672. key.setViewKey('S-<backspace>', function () {
  673. BrowserForward();
  674. }, '進む');
  675. key.setViewKey('q', function (ev, arg) {
  676. ext.exec("query-then-engine", arg, ev);
  677. }, 'enter search word and then select engine', true);
  678. key.setViewKey('/', function () {
  679. command.iSearchForward();
  680. }, 'インクリメンタル検索', true);
  681. key.setViewKey('?', function (ev) {
  682. command.iSearchForwardKs(ev);
  683. }, 'Emacs ライクなインクリメンタル検索', true);
  684. key.setViewKey('a', function (ev, arg) {
  685. allTabs.open();
  686. }, 'alltabs.open');
  687. key.setViewKey([['<right>'], ['d']], function (ev) {
  688. goDoCommand("cmd_scrollPageDown");
  689. }, '一画面スクロールダウン');
  690. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  691. return;
  692. }, 'ignore');
  693. key.setViewKey(':', function (ev, arg) {
  694. return !document.getElementById("keysnail-prompt").hidden &&
  695. document.getElementById("keysnail-prompt-textbox").focus();
  696. }, 'KeySnail のプロンプトへフォーカス', true);
  697. key.setViewKey('H', function (ev) {
  698. var browser = getBrowser();
  699. if (browser.mCurrentTab.previousSibling) {
  700. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  701. } else {
  702. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  703. }
  704. }, '選択中のタブを左へ');
  705. key.setViewKey('0', function (ev) {
  706. BrowserCloseTabOrWindow();
  707. }, 'タブ / ウィンドウを閉じる');
  708. key.setViewKey('C', function (ev, arg) {
  709. ext.exec("linksnail", arg, ev);
  710. }, 'LinkSnail', true);
  711. key.setViewKey('C-<backspace>', function (ev, arg) {
  712. ext.exec("list-tab-history", arg, ev);
  713. }, 'List tab history', true);
  714. key.setViewKey('I', function (ev, arg) {
  715. ext.exec("instapaper-post-page-with-comment", arg, ev);
  716. }, 'post page and comment', true);
  717. key.setViewKey('T', function (ev, arg) {
  718. ext.exec("mstranslator-open-prompt", arg, ev);
  719. }, 'MSTranslator - Open prompt', true);
  720. key.setViewKey('j', function (ev) {
  721. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  722. }, '一行スクロールダウン');
  723. key.setViewKey('k', function (ev) {
  724. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  725. }, '一行スクロールアップ');
  726. key.setViewKey('l', function (ev) {
  727. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  728. }, '右へスクロール');
  729. key.setViewKey('h', function (ev) {
  730. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  731. }, '左へスクロール');
  732. key.setViewKey('L', function (ev) {
  733. var browser = getBrowser();
  734. if (browser.mCurrentTab.nextSibling) {
  735. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  736. } else {
  737. browser.moveTabTo(browser.mCurrentTab, 0);
  738. }
  739. }, '選択中のタブを右へ');
  740. key.setViewKey('U', function (ev) {
  741. undoCloseTab();
  742. }, '閉じたタブを元に戻す');
  743. key.setEditKey('C-<tab>', function (ev) {
  744. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  745. }, '次のテキストエリアへフォーカス');
  746. key.setGlobalKey('<f11>', function (ev, arg) {
  747. ext.exec('strong-fullscreen', arg, ev);
  748. }, 'go fullscreen with hiding toolbar and tabbar', true);