No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

_keysnail.js 34 KiB

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