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.
 
 
 
 
 
 

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