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 33 KiB

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