選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

_keysnail.js 32 KiB

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