Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

_keysnail.js 34 KiB

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