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.
 
 
 
 
 
 

858 regels
32 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:88"] = [
  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('post-to-posterous', function (ev, arg) {
  151. if (window.loadURI) {
  152. 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{}");
  153. }
  154. }, 'post to posterous');
  155. ext.add("echo-tab-info", function(){
  156. var all = gBrowser.tabs.length;
  157. var ix = gBrowser.mCurrentTab._tPos;
  158. var title = window.document.title;
  159. var url = window.content.location.href;
  160. display.echoStatusBar((ix + 1).toString() + " / " +
  161. all.toString() + " : " +
  162. title + " <" +
  163. url + ">");
  164. }, "echo tab info");
  165. ext.add("strong-fullscreen", function(){
  166. var elemids = [
  167. "navigator-toolbox"
  168. ];
  169. BrowserFullScreen();
  170. var isfullscreen = window.fullScreen;
  171. for(var i = 0; i < elemids.length; i++){
  172. var elem = document.getElementById(elemids[i]);
  173. if(elem){
  174. if(isfullscreen){
  175. elem.style.display = "none";
  176. }else{
  177. elem.style.display = null;
  178. }
  179. }
  180. }
  181. var tabs = document.getElementById("verticaltabs-box");
  182. if(tabs){
  183. var pref_key = "extensions.verticaltabs.width";
  184. var pref_key_bak = pref_key + "_bak"
  185. if(isfullscreen){
  186. var width_orig = util.getIntPref(pref_key);
  187. util.setIntPref(pref_key_bak, width_orig);
  188. util.setIntPref(pref_key, 0);
  189. tabs.setAttribute("width", "0");
  190. }else if(parseInt(tabs.getAttribute("width") || "") === 0){
  191. var width_bak = util.getIntPref(pref_key_bak);
  192. util.setIntPref(pref_key, width_bak);
  193. tabs.setAttribute("width", width_bak.toString());
  194. }
  195. }
  196. }, "go fullscreen with hiding toolbar and tabbar");
  197. ext.add("list-page-url", function(){
  198. // window.content.document.links
  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. "gecko.handlerService.schemes.mailto.1.name":"Gmail",
  282. "general.warnOnAboutConfig":false,
  283. "keyword.URL":"http://www.bing.com/search?q=",
  284. "network.dns.disableIPv6":true,
  285. "refcontrol.actions":"@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  286. "scrapbook.tabs.open":true
  287. }
  288. );
  289. if(/^Linux/.test(navigator.platform)){
  290. util.setPrefs(
  291. {
  292. "browser.cache.disk.parent_directory":"/tmp",
  293. "browser.cache.disk.capacity":524288
  294. }
  295. );
  296. }
  297. display.showPopup("Keysnail", "My prefs done.");
  298. }, 'my setpref');
  299. ext.add('auto-install-plugins', function(ev, arg){
  300. var urls = [
  301. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  302. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  303. 'https://raw.github.com/mooz/keysnail/master/plugins/hok.ks.js',
  304. 'https://github.com/mooz/keysnail/raw/master/plugins/builtin-commands-ext.ks.js',
  305. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  306. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  307. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  308. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  309. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  310. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  311. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  312. 'https://raw.github.com/gist/1976942/firefox-addon-manager.ks.js',
  313. 'https://raw.github.com/gist/1450594/mstranslator.ks.js'
  314. ];
  315. function inst(a){
  316. if(a.length == 0){
  317. display.showPopup("auto-install-plugins", "All installation finished.");
  318. }else{
  319. var url = a.shift();
  320. var path = userscript.pluginDir + userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  321. if(plugins.context[path] === undefined){
  322. userscript.installPluginFromURL(url, function(){inst(a);});
  323. }else{
  324. inst(a);
  325. }
  326. }
  327. }
  328. inst(urls);
  329. }, 'Install plugins automatically if not installed yet.');
  330. ext.add('put-aside-this-page', function (ev, arg) {
  331. var n = gBrowser.mCurrentTab._tPos;
  332. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  333. if (n != 0) {
  334. gBrowser.selectedTab = gBrowser.mTabs[n];
  335. }
  336. }, 'put aside this page');
  337. ext.add('send-escape', function (ev, arg) {
  338. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  339. }, 'escape');
  340. ext.add("open-hatebu-comment", function (ev, arg) {
  341. if (window.loadURI) {
  342. loadURI("javascript:location.href='http://b.hatena.ne.jp/entry?mode=more&url='+encodeURIComponent(location.href);");
  343. }
  344. }, 'hatebu');
  345. // ext.add("focus-on-content", function(){
  346. // let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  347. // gBrowser.focus();
  348. // content.focus();
  349. // }, "forcus on content");
  350. ext.add("hide-sidebar", function(){
  351. var sidebarBox = document.getElementById("sidebar-box");
  352. if (!sidebarBox.hidden) {
  353. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  354. }
  355. }, "hide-sidebar");
  356. ext.add("close-and-next-tab", function (ev, arg) {
  357. var n = gBrowser.mCurrentTab._tPos;
  358. gBrowser.removeCurrentTab();
  359. gBrowser.selectedTab = gBrowser.mTabs[n];
  360. }, "close and focus to next tab");
  361. //////////////////////////////////////
  362. //
  363. ext.add("restart-firefox-add-menu", function(){
  364. const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  365. var cmdelm = document.createElementNS(XUL_NS, "command");
  366. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  367. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  368. var commandset = document.getElementById("mainCommandSet");
  369. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  370. commandset.appendChild(cmdelm);
  371. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  372. menuelm.setAttribute("label", "Restart Firefox");
  373. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  374. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  375. var menu = document.getElementById("menu_FilePopup");
  376. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  377. menu.appendChild(menuelm);
  378. }, "add restart firefox menu");
  379. /////////////////////////////////////////
  380. // copy feed url
  381. ext.add("copy-url", function () {
  382. const doc = content.document;
  383. let feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  384. for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]',
  385. 'link[type="application/atom+xml"]'])))];
  386. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1");
  387. for (i = 0; i < feeds.length; i++)
  388. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  389. feeds.unshift([window.content.document.title,window.content.location.href]);
  390. prompt.selector(
  391. {
  392. message : "Select Feed",
  393. collection : feeds,
  394. callback : function (i) {
  395. if (i >= 0)
  396. command.setClipboardText(feeds[i][1]);
  397. }
  398. }
  399. );
  400. }, "Copy url or feed url of current page");
  401. ///////////////////////////////////////
  402. // keysnail z menu
  403. ext.add("keysnail-setting-dialog", function(){
  404. KeySnail.openPreference();
  405. }, "keysnail setting dialog");
  406. ext.add("keysnail-plugin-manager", function(){
  407. userscript.openPluginManager();
  408. }, "keysnail plugin manager");
  409. ext.add("firefox-open-addon-manager", function(){
  410. BrowserOpenAddonsMgr();
  411. }, "firefox addon manager");
  412. ext.add("keysnail-reload-init-file", function(){
  413. userscript.reload();
  414. }, "keysnail reload init file");
  415. ext.add("keysnail-z-menu",function(){
  416. var list = [["keysnail-setting-dialog"],
  417. ["keysnail-plugin-manager"],
  418. ["firefox-open-addon-manager"],
  419. ["keysnail-reload-init-file"],
  420. // ["check-for-plugins-update"],
  421. ["restart-firefox"]
  422. ];
  423. prompt.selector(
  424. {
  425. message : "open setting dialog",
  426. collection : list,
  427. callback : function (i) {
  428. ext.exec(list[i][0]);
  429. }
  430. });
  431. },"open keysnail z menu");
  432. ///////////////////////////////////
  433. // search web
  434. ext.add("query-then-engine", function () {
  435. prompt.reader({message : "Search Word?:",
  436. group : "query_word",
  437. completer : completer.matcher.header(share.friendsCache || []),
  438. callback : function (q) {
  439. if (q) {
  440. prompt.selector({ message : "search \"" + q + "\" with?",
  441. collection : plugins.options["search-url-list"],
  442. width : [20,80],
  443. callback : function (i) {
  444. getBrowser().selectedTab = getBrowser().addTab(plugins.options["search-url-list"][i][1].replace("%r",q).replace("%q",encodeURIComponent(q)));
  445. },
  446. });
  447. };
  448. },
  449. initialInput : content.document.getSelection() || "",
  450. });
  451. }, "enter search word and then select engine");
  452. /////////////////////////////////////
  453. // closed tab list
  454. ext.add("list-closed-tabs", function () {
  455. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  456. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  457. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  458. var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  459. if (!closedTabs.length)
  460. return void display.echoStatusBar("No recently closed tab.", 2000);
  461. prompt.selector(
  462. {
  463. message : "select tab to undo:",
  464. collection : closedTabs,
  465. flags : [ICON | IGNORE, 0, 0],
  466. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  467. });
  468. }, "List closed tabs");
  469. // ext.add("echo-closed-tabs", function () {
  470. // var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  471. // var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  472. // // var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  473. // var lasttab = json.decode(ss.getClosedTabData(window))[0];
  474. // dump = ""
  475. // for (var i in lasttab) { dump += lasttab[i] + "\n"; }
  476. // confirm(dump);
  477. // }, "List closed tabs");
  478. ///////////////////////////////
  479. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  480. ext.add("list-tab-history", function () {
  481. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  482. var tabHistory = [];
  483. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  484. if (sessionHistory.count < 1)
  485. return void display.echoStatusBar("Tab history not exist", 2000);
  486. var curIdx = sessionHistory.index;
  487. for (var i = 0; i < sessionHistory.count; i++) {
  488. var entry = sessionHistory.getEntryAtIndex(i, false);
  489. if (!entry)
  490. continue;
  491. try {
  492. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  493. .getService(Ci.nsIFaviconService)
  494. .getFaviconForPage(entry.URI).spec;
  495. } catch (ex) {}
  496. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  497. }
  498. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  499. if (tabHistory[thIdx][3] == curIdx) break;
  500. }
  501. prompt.selector(
  502. {
  503. message : "select history in tab",
  504. collection : tabHistory,
  505. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  506. header : ["Title", "URL"],
  507. initialIndex : thIdx,
  508. callback : function(i) { if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]); }
  509. });
  510. }, 'List tab history');
  511. //}}%PRESERVE%
  512. // ========================================================================= //
  513. // ========================= Special key settings ========================== //
  514. key.quitKey = "ESC";
  515. key.helpKey = "<f1>";
  516. key.escapeKey = "C-q";
  517. key.macroStartKey = "";
  518. key.macroEndKey = "";
  519. key.universalArgumentKey = "C-u";
  520. key.negativeArgument1Key = "C--";
  521. key.negativeArgument2Key = "C-M--";
  522. key.negativeArgument3Key = "M--";
  523. key.suspendKey = "Not defined";
  524. // ================================= Hooks ================================= //
  525. hook.setHook('KeyBoardQuit', function (aEvent) {
  526. ext.exec("hide-sidebar");
  527. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  528. gBrowser.focus();
  529. content.focus();
  530. command.closeFindBar();
  531. if (util.isCaretEnabled()) {
  532. command.resetMark(aEvent);
  533. } else {
  534. goDoCommand("cmd_selectNone");
  535. }
  536. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  537. });
  538. hook.setHook('Unload', function () {
  539. util.getBrowserWindows().some(function (win) {
  540. if (win === window) {
  541. return false;
  542. }
  543. const ks = win.KeySnail;
  544. share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate);
  545. ks.setUpPluginUpdaterDelegator();
  546. return true;
  547. });
  548. });
  549. // ============================= Key bindings ============================== //
  550. key.setGlobalKey('C-<right>', function () {
  551. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  552. }, 'ひとつ右のタブへ');
  553. key.setGlobalKey('C-<left>', function () {
  554. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  555. }, 'ひとつ左のタブへ');
  556. key.setGlobalKey('C-<up>', function () {
  557. var browser = getBrowser();
  558. if (browser.mCurrentTab.previousSibling) {
  559. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  560. } else {
  561. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  562. }
  563. }, '選択中のタブを右へ');
  564. key.setGlobalKey('C-<down>', function () {
  565. var browser = getBrowser();
  566. if (browser.mCurrentTab.nextSibling) {
  567. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  568. } else {
  569. browser.moveTabTo(browser.mCurrentTab, 0);
  570. }
  571. }, '選択中のタブを左へ');
  572. key.setGlobalKey('C-h', function (ev, arg) {
  573. return;
  574. }, 'ignore');
  575. key.setGlobalKey('<delete>', function (ev, arg) {
  576. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  577. gBrowser.focus();
  578. content.focus();
  579. }, 'コンテンツへフォーカス', true);
  580. key.setGlobalKey('C-p', function (ev, arg) {
  581. return !document.getElementById("keysnail-prompt").hidden &&
  582. document.getElementById("keysnail-prompt-textbox").focus();
  583. }, 'KeySnail のプロンプトへフォーカス', true);
  584. key.setGlobalKey('<f11>', function (ev, arg) {
  585. ext.exec("strong-fullscreen", arg, ev);
  586. }, 'go fullscreen with hiding toolbar and tabbar', true);
  587. key.setViewKey('N', function (ev) {
  588. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  589. }, 'ひとつ右のタブへ');
  590. key.setViewKey('P', function (ev) {
  591. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  592. }, 'ひとつ左のタブへ');
  593. key.setViewKey('o', function (ev, arg) {
  594. ext.exec("hok-start-foreground-mode", arg, ev);
  595. }, 'Start Hit a Hint foreground mode', true);
  596. key.setViewKey('c', function (ev) {
  597. command.interpreter();
  598. }, 'JavaScript のコードを評価');
  599. key.setViewKey('D', function (ev, arg) {
  600. ext.exec("dig-url", arg, ev);
  601. }, 'dig url with selector', true);
  602. key.setViewKey('x', function (aEvent, aArg) {
  603. ext.select(aArg, aEvent);
  604. }, 'エクステ一覧');
  605. key.setViewKey(['t', 'm'], function (ev, arg) {
  606. if (window.loadURI) {
  607. loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;");
  608. }
  609. }, 'open with tweetmeme');
  610. key.setViewKey(['t', 'w'], function (ev, arg) {
  611. ext.exec("twitter-client-tweet", arg, ev);
  612. }, 'つぶやく', true);
  613. key.setViewKey(['t', 'p'], function (ev, arg) {
  614. ext.exec("twitter-client-tweet-this-page", arg, ev);
  615. }, 'このページのタイトルと URL を使ってつぶやく', true);
  616. key.setViewKey([['u'], ['<left>']], function (ev) {
  617. goDoCommand("cmd_scrollPageUp");
  618. }, '一画面分スクロールアップ');
  619. key.setViewKey('g', function () {
  620. goDoCommand("cmd_scrollTop");
  621. }, 'ページ先頭へ移動');
  622. key.setViewKey('G', function () {
  623. goDoCommand("cmd_scrollBottom");
  624. }, 'ページ末尾へ移動');
  625. key.setViewKey('r', function (aEvent) {
  626. BrowserReload();
  627. }, '再読み込み');
  628. key.setViewKey('m', function (ev, arg) {
  629. _fi.toogle();
  630. }, 'fetchimiをトグル');
  631. key.setViewKey('SPC', function (ev, arg) {
  632. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  633. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  634. }, 'タブの選択をトグルして次のタブ');
  635. key.setViewKey('S-SPC', function (ev, arg) {
  636. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  637. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  638. }, 'タブの選択をトグルして前のタブ');
  639. key.setViewKey('z', function (ev, arg) {
  640. ext.exec("keysnail-z-menu", arg, ev);
  641. }, 'open keysnail setting menu', true);
  642. key.setViewKey('C-SPC', function (ev, arg) {
  643. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  644. }, 'タブの選択をトグル');
  645. key.setViewKey('e', function () {
  646. command.focusElement(command.elementsRetrieverTextarea, 0);
  647. }, '最初のインプットエリアへフォーカス', true);
  648. key.setViewKey('S', function (ev, arg) {
  649. if (window.loadURI) {
  650. 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{}");
  651. }
  652. }, 'google reader share');
  653. key.setViewKey('!', function (ev, arg) {
  654. shell.input();
  655. }, 'Command system');
  656. key.setViewKey('R', function () {
  657. BrowserReloadSkipCache();
  658. }, '更新(キャッシュを無視)');
  659. key.setViewKey('<backspace>', function () {
  660. BrowserBack();
  661. }, '戻る');
  662. key.setViewKey('S-<backspace>', function () {
  663. BrowserForward();
  664. }, '進む');
  665. key.setViewKey('q', function (ev, arg) {
  666. ext.exec("query-then-engine", arg, ev);
  667. }, 'enter search word and then select engine', true);
  668. key.setViewKey('/', function () {
  669. command.iSearchForward();
  670. }, 'インクリメンタル検索', true);
  671. key.setViewKey('?', function (ev) {
  672. command.iSearchForwardKs(ev);
  673. }, 'Emacs ライクなインクリメンタル検索', true);
  674. key.setViewKey('a', function (ev, arg) {
  675. allTabs.open();
  676. }, 'alltabs.open');
  677. key.setViewKey([['<right>'], ['d']], function (ev) {
  678. goDoCommand("cmd_scrollPageDown");
  679. }, '一画面スクロールダウン');
  680. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  681. return;
  682. }, 'ignore');
  683. key.setViewKey(':', function (ev, arg) {
  684. return !document.getElementById("keysnail-prompt").hidden &&
  685. document.getElementById("keysnail-prompt-textbox").focus();
  686. }, 'KeySnail のプロンプトへフォーカス', true);
  687. key.setViewKey('B', function (ev) {
  688. var browser = getBrowser();
  689. if (browser.mCurrentTab.previousSibling) {
  690. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  691. } else {
  692. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  693. }
  694. }, '選択中のタブを左へ');
  695. key.setViewKey('0', function (ev) {
  696. BrowserCloseTabOrWindow();
  697. }, 'タブ / ウィンドウを閉じる');
  698. key.setViewKey('C', function (ev, arg) {
  699. ext.exec("linksnail", arg, ev);
  700. }, 'LinkSnail', true);
  701. key.setViewKey('C-<backspace>', function (ev, arg) {
  702. ext.exec("list-tab-history", arg, ev);
  703. }, 'List tab history', true);
  704. key.setViewKey('I', function (ev, arg) {
  705. ext.exec("instapaper-post-page-with-comment", arg, ev);
  706. }, 'post page and comment', true);
  707. key.setViewKey('T', function (ev, arg) {
  708. ext.exec("mstranslator-open-prompt", arg, ev);
  709. }, 'MSTranslator - Open prompt', true);
  710. key.setViewKey('n', function (ev) {
  711. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  712. }, '一行スクロールダウン');
  713. key.setViewKey('p', function (ev) {
  714. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  715. }, '一行スクロールアップ');
  716. key.setViewKey('f', function (ev) {
  717. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  718. }, '右へスクロール');
  719. key.setViewKey('b', function (ev) {
  720. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  721. }, '左へスクロール');
  722. key.setViewKey('F', function (ev) {
  723. var browser = getBrowser();
  724. if (browser.mCurrentTab.nextSibling) {
  725. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  726. } else {
  727. browser.moveTabTo(browser.mCurrentTab, 0);
  728. }
  729. }, '選択中のタブを右へ');
  730. key.setViewKey('U', function (ev, arg) {
  731. ext.exec("list-closed-tabs", arg, ev);
  732. }, 'List closed tabs', true);
  733. key.setEditKey('C-<tab>', function (ev) {
  734. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  735. }, '次のテキストエリアへフォーカス');