Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

874 lignes
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('KeySnailInitialized', function () {
  533. ext.exec("shiitake-enable-style");
  534. });
  535. hook.setHook('KeyBoardQuit', function (aEvent) {
  536. ext.exec("hide-sidebar");
  537. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  538. gBrowser.focus();
  539. content.focus();
  540. command.closeFindBar();
  541. if (util.isCaretEnabled()) {
  542. command.resetMark(aEvent);
  543. } else {
  544. goDoCommand("cmd_selectNone");
  545. }
  546. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  547. });
  548. hook.setHook('Unload', function () {
  549. util.getBrowserWindows().some(function (win) {
  550. if (win === window) {
  551. return false;
  552. }
  553. const ks = win.KeySnail;
  554. share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate);
  555. ks.setUpPluginUpdaterDelegator();
  556. return true;
  557. });
  558. });
  559. // ============================= Key bindings ============================== //
  560. key.setGlobalKey('C-<right>', function () {
  561. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  562. }, 'ひとつ右のタブへ');
  563. key.setGlobalKey('C-<left>', function () {
  564. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  565. }, 'ひとつ左のタブへ');
  566. key.setGlobalKey('C-<up>', function () {
  567. var browser = getBrowser();
  568. if (browser.mCurrentTab.previousSibling) {
  569. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  570. } else {
  571. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  572. }
  573. }, '選択中のタブを右へ');
  574. key.setGlobalKey('C-<down>', function () {
  575. var browser = getBrowser();
  576. if (browser.mCurrentTab.nextSibling) {
  577. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  578. } else {
  579. browser.moveTabTo(browser.mCurrentTab, 0);
  580. }
  581. }, '選択中のタブを左へ');
  582. key.setGlobalKey('C-h', function (ev, arg) {
  583. return;
  584. }, 'ignore');
  585. key.setGlobalKey('<delete>', function (ev, arg) {
  586. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  587. gBrowser.focus();
  588. content.focus();
  589. }, 'コンテンツへフォーカス', true);
  590. key.setGlobalKey('C-p', function (ev, arg) {
  591. return !document.getElementById("keysnail-prompt").hidden &&
  592. document.getElementById("keysnail-prompt-textbox").focus();
  593. }, 'KeySnail のプロンプトへフォーカス', true);
  594. key.setViewKey('J', function (ev) {
  595. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  596. }, 'ひとつ右のタブへ');
  597. key.setViewKey('K', function (ev) {
  598. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  599. }, 'ひとつ左のタブへ');
  600. key.setViewKey('o', function (ev, arg) {
  601. ext.exec("hok-start-foreground-mode", arg, ev);
  602. }, 'Start Hit a Hint foreground mode', true);
  603. key.setViewKey('c', function (ev) {
  604. command.interpreter();
  605. }, 'JavaScript のコードを評価');
  606. key.setViewKey('D', function (ev, arg) {
  607. ext.exec("dig-url", arg, ev);
  608. }, 'dig url with selector', true);
  609. key.setViewKey('x', function (aEvent, aArg) {
  610. ext.select(aArg, aEvent);
  611. }, 'エクステ一覧');
  612. key.setViewKey(['t', 'm'], function (ev, arg) {
  613. if (window.loadURI) {
  614. loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;");
  615. }
  616. }, 'open with tweetmeme');
  617. key.setViewKey(['t', 'w'], function (ev, arg) {
  618. ext.exec("twitter-client-tweet", arg, ev);
  619. }, 'つぶやく', true);
  620. key.setViewKey(['t', 'p'], function (ev, arg) {
  621. ext.exec("twitter-client-tweet-this-page", arg, ev);
  622. }, 'このページのタイトルと URL を使ってつぶやく', true);
  623. key.setViewKey([['u'], ['<left>']], function (ev) {
  624. goDoCommand("cmd_scrollPageUp");
  625. }, '一画面分スクロールアップ');
  626. key.setViewKey('g', function () {
  627. goDoCommand("cmd_scrollTop");
  628. }, 'ページ先頭へ移動');
  629. key.setViewKey('G', function () {
  630. goDoCommand("cmd_scrollBottom");
  631. }, 'ページ末尾へ移動');
  632. key.setViewKey('r', function (aEvent) {
  633. BrowserReload();
  634. }, '再読み込み');
  635. key.setViewKey('m', function (ev, arg) {
  636. _fi.toogle();
  637. }, 'fetchimiをトグル');
  638. key.setViewKey('p', function (ev, arg) {
  639. if (window.loadURI) {
  640. 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{}");
  641. }
  642. }, 'posterousに投稿');
  643. key.setViewKey('SPC', function (ev, arg) {
  644. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  645. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  646. }, 'タブの選択をトグルして次のタブ');
  647. key.setViewKey('S-SPC', function (ev, arg) {
  648. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  649. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  650. }, 'タブの選択をトグルして前のタブ');
  651. key.setViewKey('z', function (ev, arg) {
  652. ext.exec("keysnail-z-menu", arg, ev);
  653. }, 'open keysnail setting menu', true);
  654. key.setViewKey('C-SPC', function (ev, arg) {
  655. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  656. }, 'タブの選択をトグル');
  657. key.setViewKey('e', function () {
  658. command.focusElement(command.elementsRetrieverTextarea, 0);
  659. }, '最初のインプットエリアへフォーカス', true);
  660. key.setViewKey('S', function (ev, arg) {
  661. if (window.loadURI) {
  662. 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{}");
  663. }
  664. }, 'google reader share');
  665. key.setViewKey('!', function (ev, arg) {
  666. shell.input();
  667. }, 'Command system');
  668. key.setViewKey('R', function () {
  669. BrowserReloadSkipCache();
  670. }, '更新(キャッシュを無視)');
  671. key.setViewKey('<backspace>', function () {
  672. BrowserBack();
  673. }, '戻る');
  674. key.setViewKey('S-<backspace>', function () {
  675. BrowserForward();
  676. }, '進む');
  677. key.setViewKey('q', function (ev, arg) {
  678. ext.exec("query-then-engine", arg, ev);
  679. }, 'enter search word and then select engine', true);
  680. key.setViewKey('/', function () {
  681. command.iSearchForward();
  682. }, 'インクリメンタル検索', true);
  683. key.setViewKey('?', function (ev) {
  684. command.iSearchForwardKs(ev);
  685. }, 'Emacs ライクなインクリメンタル検索', true);
  686. key.setViewKey('a', function (ev, arg) {
  687. allTabs.open();
  688. }, 'alltabs.open');
  689. key.setViewKey([['<right>'], ['d']], function (ev) {
  690. goDoCommand("cmd_scrollPageDown");
  691. }, '一画面スクロールダウン');
  692. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  693. return;
  694. }, 'ignore');
  695. key.setViewKey(':', function (ev, arg) {
  696. return !document.getElementById("keysnail-prompt").hidden &&
  697. document.getElementById("keysnail-prompt-textbox").focus();
  698. }, 'KeySnail のプロンプトへフォーカス', true);
  699. key.setViewKey('H', function (ev) {
  700. var browser = getBrowser();
  701. if (browser.mCurrentTab.previousSibling) {
  702. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  703. } else {
  704. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  705. }
  706. }, '選択中のタブを左へ');
  707. key.setViewKey('0', function (ev) {
  708. BrowserCloseTabOrWindow();
  709. }, 'タブ / ウィンドウを閉じる');
  710. key.setViewKey('C', function (ev, arg) {
  711. ext.exec("linksnail", arg, ev);
  712. }, 'LinkSnail', true);
  713. key.setViewKey('C-<backspace>', function (ev, arg) {
  714. ext.exec("list-tab-history", arg, ev);
  715. }, 'List tab history', true);
  716. key.setViewKey('I', function (ev, arg) {
  717. ext.exec("instapaper-post-page-with-comment", arg, ev);
  718. }, 'post page and comment', true);
  719. key.setViewKey('T', function (ev, arg) {
  720. ext.exec("mstranslator-open-prompt", arg, ev);
  721. }, 'MSTranslator - Open prompt', true);
  722. key.setViewKey('j', function (ev) {
  723. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  724. }, '一行スクロールダウン');
  725. key.setViewKey('k', function (ev) {
  726. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  727. }, '一行スクロールアップ');
  728. key.setViewKey('l', function (ev) {
  729. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  730. }, '右へスクロール');
  731. key.setViewKey('h', function (ev) {
  732. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  733. }, '左へスクロール');
  734. key.setViewKey('L', function (ev) {
  735. var browser = getBrowser();
  736. if (browser.mCurrentTab.nextSibling) {
  737. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  738. } else {
  739. browser.moveTabTo(browser.mCurrentTab, 0);
  740. }
  741. }, '選択中のタブを右へ');
  742. key.setViewKey('U', function (ev) {
  743. undoCloseTab();
  744. }, '閉じたタブを元に戻す');
  745. key.setEditKey('C-<tab>', function (ev) {
  746. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  747. }, '次のテキストエリアへフォーカス');
  748. key.setGlobalKey('<f11>', function (ev, arg) {
  749. ext.exec('strong-fullscreen', arg, ev);
  750. }, 'go fullscreen with hiding toolbar and tabbar', true);