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.
 
 
 
 
 
 

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