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.
 
 
 
 
 
 

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