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.

_keysnail.js 34 KiB

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