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.
 
 
 
 
 
 

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