您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

_keysnail.js 34 KiB

13 年前
13 年前
12 年前
13 年前
13 年前
13 年前
12 年前
13 年前
13 年前
13 年前
13 年前
12 年前
13 年前
13 年前
13 年前
13 年前
12 年前
13 年前
13 年前
13 年前
13 年前
13 年前
12 年前
12 年前
12 年前
13 年前
13 年前
12 年前
13 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
12 年前
13 年前
12 年前
12 年前
13 年前
13 年前
13 年前
13 年前
13 年前
13 年前
13 年前
13 年前
12 年前
12 年前
13 年前
13 年前
13 年前
12 年前
12 年前
13 年前
12 年前
13 年前
12 年前
13 年前
12 年前
13 年前
13 年前
13 年前
13 年前
12 年前
13 年前
13 年前
13 年前
12 年前
12 年前
13 年前
13 年前
13 年前
13 年前
13 年前
12 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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:..../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('post-to-posterous', function (ev, arg) {
  151. if (window.loadURI) {
  152. loadURI("javascript:var%20b=document.body;var%20POSTEROUS___bookmarklet_domain='http://posterous.com';var%20d=new%20Date();var%20e=(new%20Date(d.getFullYear(),d.getMonth(),d.getDate())).getTime();if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.type='text/javascript');void(z.src='http://posterous.com/javascripts/bookmarklet2.js?'+e);void(b.appendChild(z));}else{}");
  153. }
  154. }, 'post to posterous');
  155. ext.add("echo-tab-info", function(){
  156. var all = gBrowser.tabs.length;
  157. var ix = gBrowser.mCurrentTab._tPos;
  158. var title = window.document.title;
  159. var url = window.content.location.href;
  160. display.echoStatusBar((ix + 1).toString() + " / " +
  161. all.toString() + " : " +
  162. title + " <" +
  163. url + ">");
  164. }, "echo tab info");
  165. ext.add("strong-fullscreen", function(){
  166. var elemids = [
  167. "navigator-toolbox"
  168. ];
  169. BrowserFullScreen();
  170. var isfullscreen = window.fullScreen;
  171. for(var i = 0; i < elemids.length; i++){
  172. var elem = document.getElementById(elemids[i]);
  173. if(elem){
  174. if(isfullscreen){
  175. elem.style.display = "none";
  176. }else{
  177. elem.style.display = null;
  178. }
  179. }
  180. }
  181. var tabs = document.getElementById("verticaltabs-box");
  182. if(tabs){
  183. var pref_key = "extensions.verticaltabs.width";
  184. var pref_key_bak = pref_key + "_bak"
  185. if(isfullscreen){
  186. var width_orig = util.getIntPref(pref_key);
  187. util.setIntPref(pref_key_bak, width_orig);
  188. util.setIntPref(pref_key, 0);
  189. tabs.setAttribute("width", "0");
  190. }else if(parseInt(tabs.getAttribute("width") || "") === 0){
  191. var width_bak = util.getIntPref(pref_key_bak);
  192. util.setIntPref(pref_key, width_bak);
  193. tabs.setAttribute("width", width_bak.toString());
  194. }
  195. }
  196. }, "go fullscreen with hiding toolbar and tabbar");
  197. // ext.add("open-url-from-clipboard", function(){
  198. // var list = command.getClipboardText().split("\n");
  199. // for(var i = 0; i < list.length; i++){
  200. // if(list[i] != ""){
  201. // gBrowser.loadOneTab(list[i], null, null, null, false);
  202. // }
  203. // }
  204. // }, "open tabs of newline separated url list from clipboard");
  205. ext.add("list-page-url", function(){
  206. var urls = [];
  207. var aa = window.content.document.getElementsByTagName("a");
  208. var text = "";
  209. var alt = "";
  210. for (var i = 0; i < aa.length ; i++) {
  211. if(aa[i].href == ""){ continue; }
  212. if (aa[i].text == "" && aa[i].hasChildNodes() && aa[i].childNodes[0].nodeType == Node.ELEMENT_NODE){
  213. alt = aa[i].childNodes[0].getAttribute("alt");
  214. text = " " + aa[i].childNodes[0].nodeName + (alt ? ": " + alt : "");
  215. }else{
  216. text = aa[i].text;
  217. }
  218. urls.push([text, decodeURIComponent(aa[i].href)]);
  219. }
  220. if(urls.length == 0){
  221. display.echoStatusBar("No url found.");
  222. return;
  223. }
  224. prompt.selector(
  225. {
  226. message : "Select URL",
  227. collection : urls,
  228. width : [35, 65],
  229. header : ["text", "url"],
  230. callback : function (i) {
  231. if (i >= 0)
  232. openUILinkIn(urls[i][1], "tab"); // or current tabshifted window
  233. }
  234. }
  235. );
  236. }, "list url");
  237. ext.add("bookmark-delicious", function(){
  238. f= 'http://www.delicious.com/save?url=' + encodeURIComponent(window.content.location.href) +
  239. '&title=' + encodeURIComponent(document.title) +
  240. '&notes=' + encodeURIComponent('' + (window.getSelection ?
  241. window.getSelection() : document.getSelection ?
  242. document.getSelection() : document.selection.createRange().text)) + '&v=6&';
  243. a = function(){
  244. if(! window.open(f + 'noui=1&jump=doclose', 'deliciousuiv6', 'location=1,links=0,scrollbars=0,toolbar=0,width=710,height=660')){
  245. location.href = f + 'jump=yes';
  246. }
  247. };
  248. if(/Firefox/.test(navigator.userAgent)){
  249. setTimeout(a,0);
  250. }else{
  251. a();
  252. }
  253. }, "bookmark delicious");
  254. ext.add('view-page-source', function(){
  255. window.content.location.href = "view-source:" + window.content.location.href;
  256. }, 'view page source');
  257. ext.add('my-setpref', function(){
  258. util.setPrefs(
  259. {
  260. "browser.bookmarks.max_backups":0,
  261. "browser.cache.memory.capacity":16384,
  262. "browser.download.manager.closeWhenDone":true,
  263. "browser.download.useDownloadDir":false,
  264. "browser.fullscreen.autohide":false,
  265. "browser.search.openintab":true,
  266. "browser.sessionhistory.max_total_viewers":8,
  267. "browser.sessionstore.restore_on_demand":true,
  268. "browser.tabs.closeWindowWithLastTab":false,
  269. "browser.tabs.loadDivertedInBackground": true,
  270. "browser.urlbar.autocomplete.enabled":false,
  271. "browser.urlbar.trimURLs":false,
  272. "dom.disable_window_open_feature.location": false,
  273. "dom.max_script_run_time": 30,
  274. "extensions.chaika.bbsmenu.open_new_tab":true,
  275. "extensions.chaika.bbsmenu.open_single_click":false,
  276. "extensions.chaika.board.open_new_tab":true,
  277. "extensions.chaika.board.open_single_click":false,
  278. "extensions.foxage2ch.openThreadInTab":true,
  279. "extensions.saveimageinfolder.general-duplicatefilenamevalue":1,
  280. "extensions.saveimageinfolder.general-fileprefixvalue":"%yyyy%%MM%%dd%-%hh%%mm%%ss%_",
  281. "extensions.saveimageinfolder.usecache":true,
  282. "extensions.tabutils.openTabNext":1,
  283. "extensions.tabutils.styles.current":"{\"bold\":true,\"italic\":false,\"underline\":true,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#000000\",\"bgColor\":false,\"bgColorCode\":\"#000000\",\"outline\":false,\"outlineColorCode\":\"#000000\"}",
  284. "extensions.tabutils.styles.unread":"{\"bold\":false,\"italic\":false,\"underline\":false,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#CC0000\",\"bgColor\":false,\"bgColorCode\":\"undefined\",\"outline\":false,\"outlineColorCode\":\"undefined\"}",
  285. "extensions.yass.edgetype":0,
  286. "extensions.yass.selectedpreset":"red",
  287. "font.default.x-western":"sans-serif",
  288. "general.warnOnAboutConfig":false,
  289. "keyword.URL":"http://www.bing.com/search?q=",
  290. "network.dns.disableIPv6":true,
  291. "refcontrol.actions":"@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  292. "scrapbook.tabs.open":true
  293. }
  294. );
  295. if(/^Linux/.test(navigator.platform)){
  296. util.setPrefs(
  297. {
  298. "browser.cache.disk.parent_directory":"/tmp",
  299. "browser.cache.disk.capacity":524288
  300. }
  301. );
  302. }
  303. display.showPopup("Keysnail", "My prefs done.");
  304. }, 'my setpref');
  305. ext.add('auto-install-plugins', function(ev, arg){
  306. var urls = [
  307. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  308. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  309. 'https://raw.github.com/mooz/keysnail/master/plugins/hok.ks.js',
  310. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  311. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  312. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  313. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  314. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  315. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  316. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  317. 'https://raw.github.com/gist/1976942/firefox-addon-manager.ks.js',
  318. 'https://raw.github.com/gist/1450594/mstranslator.ks.js'
  319. ];
  320. function inst(a){
  321. if(a.length == 0){
  322. display.showPopup("auto-install-plugins", "All installation finished.");
  323. }else{
  324. var url = a.shift();
  325. var path = userscript.pluginDir + userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  326. if(plugins.context[path] === undefined){
  327. userscript.installPluginFromURL(url, function(){inst(a);});
  328. }else{
  329. inst(a);
  330. }
  331. }
  332. }
  333. inst(urls);
  334. }, 'Install plugins automatically if not installed yet.');
  335. ext.add('put-aside-this-page', function (ev, arg) {
  336. var n = gBrowser.mCurrentTab._tPos;
  337. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  338. if (n != 0) {
  339. gBrowser.selectedTab = gBrowser.mTabs[n];
  340. }
  341. }, 'put aside this page');
  342. ext.add('send-escape', function (ev, arg) {
  343. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  344. }, 'escape');
  345. ext.add("open-hatebu-comment", function (ev, arg) {
  346. if (window.loadURI) {
  347. loadURI("javascript:location.href='http://b.hatena.ne.jp/entry?mode=more&url='+encodeURIComponent(location.href);");
  348. }
  349. }, 'hatebu');
  350. // ext.add("focus-on-content", function(){
  351. // let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  352. // gBrowser.focus();
  353. // content.focus();
  354. // }, "forcus on content");
  355. ext.add("hide-sidebar", function(){
  356. var sidebarBox = document.getElementById("sidebar-box");
  357. if (!sidebarBox.hidden) {
  358. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  359. }
  360. }, "hide-sidebar");
  361. ext.add("close-and-next-tab", function (ev, arg) {
  362. var n = gBrowser.mCurrentTab._tPos;
  363. gBrowser.removeCurrentTab();
  364. gBrowser.selectedTab = gBrowser.mTabs[n];
  365. }, "close and focus to next tab");
  366. //////////////////////////////////////
  367. //
  368. ext.add("restart-firefox-add-menu", function(){
  369. const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  370. var cmdelm = document.createElementNS(XUL_NS, "command");
  371. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  372. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  373. var commandset = document.getElementById("mainCommandSet");
  374. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  375. commandset.appendChild(cmdelm);
  376. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  377. menuelm.setAttribute("label", "Restart Firefox");
  378. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  379. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  380. var menu = document.getElementById("menu_FilePopup");
  381. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  382. menu.appendChild(menuelm);
  383. }, "add restart firefox menu");
  384. //////////////////////////////////////
  385. // restart firefox
  386. // http://keysnail.g.hatena.ne.jp/Shinnya/20100723/1279878815
  387. // ext.add("restart-firefox",function (ev) {
  388. // const nsIAppStartup = Components.interfaces.nsIAppStartup;
  389. // // Notify all windows that an application quit has been requested.
  390. // var os = Components.classes["@mozilla.org/observer-service;1"]
  391. // .getService(Components.interfaces.nsIObserverService);
  392. // var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  393. // .createInstance(Components.interfaces.nsISupportsPRBool);
  394. // os.notifyObservers(cancelQuit, "quit-application-requested", null);
  395. // // Something aborted the quit process.
  396. // if (cancelQuit.data)
  397. // return;
  398. // // Notify all windows that an application quit has been granted.
  399. // os.notifyObservers(null, "quit-application-granted", null);
  400. // // Enumerate all windows and call shutdown handlers
  401. // var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  402. // .getService(Components.interfaces.nsIWindowMediator);
  403. // var windows = wm.getEnumerator(null);
  404. // while (windows.hasMoreElements()) {
  405. // var win = windows.getNext();
  406. // if (("tryToClose" in win) && !win.tryToClose())
  407. // return;
  408. // }
  409. // Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
  410. // .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
  411. // }, "restart firefox");
  412. /////////////////////////////////////////
  413. // copy feed url
  414. ext.add("copy-url", function () {
  415. const doc = content.document;
  416. let feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  417. for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]',
  418. 'link[type="application/atom+xml"]'])))];
  419. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1");
  420. for (i = 0; i < feeds.length; i++)
  421. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  422. feeds.unshift([window.content.document.title,window.content.location.href]);
  423. prompt.selector(
  424. {
  425. message : "Select Feed",
  426. collection : feeds,
  427. callback : function (i) {
  428. if (i >= 0)
  429. command.setClipboardText(feeds[i][1]);
  430. }
  431. }
  432. );
  433. }, "Copy url or feed url of current page");
  434. ///////////////////////////////////////
  435. // keysnail z menu
  436. ext.add("keysnail-setting-dialog", function(){
  437. KeySnail.openPreference();
  438. }, "keysnail setting dialog");
  439. ext.add("keysnail-plugin-manager", function(){
  440. userscript.openPluginManager();
  441. }, "keysnail plugin manager");
  442. ext.add("firefox-open-addon-manager", function(){
  443. BrowserOpenAddonsMgr();
  444. }, "firefox addon manager");
  445. ext.add("keysnail-reload-init-file", function(){
  446. userscript.reload();
  447. }, "keysnail reload init file");
  448. ext.add("keysnail-z-menu",function(){
  449. var list = [["keysnail-setting-dialog"],
  450. ["keysnail-plugin-manager"],
  451. ["firefox-open-addon-manager"],
  452. ["keysnail-reload-init-file"],
  453. // ["check-for-plugins-update"],
  454. ["restart-firefox"]
  455. ];
  456. prompt.selector(
  457. {
  458. message : "open setting dialog",
  459. collection : list,
  460. callback : function (i) {
  461. ext.exec(list[i][0]);
  462. }
  463. });
  464. },"open keysnail z menu");
  465. ///////////////////////////////////
  466. // search web
  467. ext.add("query-then-engine", function () {
  468. prompt.reader({message : "Search Word?:",
  469. group : "query_word",
  470. completer : completer.matcher.header(share.friendsCache || []),
  471. callback : function (q) {
  472. if (q) {
  473. prompt.selector({ message : "search \"" + q + "\" with?",
  474. collection : plugins.options["search-url-list"],
  475. width : [20,80],
  476. callback : function (i) {
  477. getBrowser().selectedTab = getBrowser().addTab(plugins.options["search-url-list"][i][1].replace("%r",q).replace("%q",encodeURIComponent(q)));
  478. },
  479. });
  480. };
  481. },
  482. initialInput : content.document.getSelection() || "",
  483. });
  484. }, "enter search word and then select engine");
  485. /////////////////////////////////////
  486. // closed tab list
  487. ext.add("list-closed-tabs", function () {
  488. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  489. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  490. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  491. var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  492. if (!closedTabs.length)
  493. return void display.echoStatusBar("No recently closed tab.", 2000);
  494. prompt.selector(
  495. {
  496. message : "select tab to undo:",
  497. collection : closedTabs,
  498. flags : [ICON | IGNORE, 0, 0],
  499. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  500. });
  501. }, "List closed tabs");
  502. // ext.add("echo-closed-tabs", function () {
  503. // var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  504. // var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  505. // // var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  506. // var lasttab = json.decode(ss.getClosedTabData(window))[0];
  507. // dump = ""
  508. // for (var i in lasttab) { dump += lasttab[i] + "\n"; }
  509. // confirm(dump);
  510. // }, "List closed tabs");
  511. ///////////////////////////////
  512. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  513. ext.add("list-tab-history", function () {
  514. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  515. var tabHistory = [];
  516. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  517. if (sessionHistory.count < 1)
  518. return void display.echoStatusBar("Tab history not exist", 2000);
  519. var curIdx = sessionHistory.index;
  520. for (var i = 0; i < sessionHistory.count; i++) {
  521. var entry = sessionHistory.getEntryAtIndex(i, false);
  522. if (!entry)
  523. continue;
  524. try {
  525. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  526. .getService(Ci.nsIFaviconService)
  527. .getFaviconForPage(entry.URI).spec;
  528. } catch (ex) {}
  529. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  530. }
  531. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  532. if (tabHistory[thIdx][3] == curIdx) break;
  533. }
  534. prompt.selector(
  535. {
  536. message : "select history in tab",
  537. collection : tabHistory,
  538. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  539. header : ["Title", "URL"],
  540. initialIndex : thIdx,
  541. callback : function(i) { if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]); }
  542. });
  543. }, 'List tab history');
  544. //}}%PRESERVE%
  545. // ========================================================================= //
  546. // ========================= Special key settings ========================== //
  547. key.quitKey = "ESC";
  548. key.helpKey = "<f1>";
  549. key.escapeKey = "C-q";
  550. key.macroStartKey = "";
  551. key.macroEndKey = "";
  552. key.universalArgumentKey = "C-u";
  553. key.negativeArgument1Key = "C--";
  554. key.negativeArgument2Key = "C-M--";
  555. key.negativeArgument3Key = "M--";
  556. key.suspendKey = "Not defined";
  557. // ================================= Hooks ================================= //
  558. hook.setHook('KeyBoardQuit', function (aEvent) {
  559. ext.exec("hide-sidebar");
  560. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  561. gBrowser.focus();
  562. content.focus();
  563. command.closeFindBar();
  564. if (util.isCaretEnabled()) {
  565. command.resetMark(aEvent);
  566. } else {
  567. goDoCommand("cmd_selectNone");
  568. }
  569. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  570. });
  571. hook.setHook('Unload', function () {
  572. util.getBrowserWindows().some(function (win) {
  573. if (win === window) {
  574. return false;
  575. }
  576. const ks = win.KeySnail;
  577. share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate);
  578. ks.setUpPluginUpdaterDelegator();
  579. return true;
  580. });
  581. });
  582. // ============================= Key bindings ============================== //
  583. key.setGlobalKey('C-<right>', function () {
  584. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  585. }, 'ひとつ右のタブへ');
  586. key.setGlobalKey('C-<left>', function () {
  587. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  588. }, 'ひとつ左のタブへ');
  589. key.setGlobalKey('C-<up>', function () {
  590. var browser = getBrowser();
  591. if (browser.mCurrentTab.previousSibling) {
  592. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  593. } else {
  594. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  595. }
  596. }, '選択中のタブを右へ');
  597. key.setGlobalKey('C-<down>', function () {
  598. var browser = getBrowser();
  599. if (browser.mCurrentTab.nextSibling) {
  600. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  601. } else {
  602. browser.moveTabTo(browser.mCurrentTab, 0);
  603. }
  604. }, '選択中のタブを左へ');
  605. key.setGlobalKey('C-h', function (ev, arg) {
  606. return;
  607. }, 'ignore');
  608. key.setGlobalKey('<delete>', function (ev, arg) {
  609. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  610. gBrowser.focus();
  611. content.focus();
  612. }, 'コンテンツへフォーカス', true);
  613. key.setGlobalKey('C-p', function (ev, arg) {
  614. return !document.getElementById("keysnail-prompt").hidden &&
  615. document.getElementById("keysnail-prompt-textbox").focus();
  616. }, 'KeySnail のプロンプトへフォーカス', true);
  617. key.setGlobalKey('<f11>', function (ev, arg) {
  618. ext.exec("strong-fullscreen", arg, ev);
  619. }, 'go fullscreen with hiding toolbar and tabbar', true);
  620. key.setViewKey('N', function (ev) {
  621. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  622. }, 'ひとつ右のタブへ');
  623. key.setViewKey('P', function (ev) {
  624. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  625. }, 'ひとつ左のタブへ');
  626. key.setViewKey('o', function (ev, arg) {
  627. ext.exec("hok-start-foreground-mode", arg, ev);
  628. }, 'Start Hit a Hint foreground mode', true);
  629. key.setViewKey('c', function (ev) {
  630. command.interpreter();
  631. }, 'JavaScript のコードを評価');
  632. key.setViewKey('D', function (ev, arg) {
  633. ext.exec("dig-url", arg, ev);
  634. }, 'dig url with selector', true);
  635. key.setViewKey('x', function (aEvent, aArg) {
  636. ext.select(aArg, aEvent);
  637. }, 'エクステ一覧');
  638. key.setViewKey(['t', 'm'], function (ev, arg) {
  639. if (window.loadURI) {
  640. loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;");
  641. }
  642. }, 'open with tweetmeme');
  643. key.setViewKey(['t', 'w'], function (ev, arg) {
  644. ext.exec("twitter-client-tweet", arg, ev);
  645. }, 'つぶやく', true);
  646. key.setViewKey(['t', 'p'], function (ev, arg) {
  647. ext.exec("twitter-client-tweet-this-page", arg, ev);
  648. }, 'このページのタイトルと URL を使ってつぶやく', true);
  649. key.setViewKey([['u'], ['<left>']], function (ev) {
  650. goDoCommand("cmd_scrollPageUp");
  651. }, '一画面分スクロールアップ');
  652. key.setViewKey('g', function () {
  653. goDoCommand("cmd_scrollTop");
  654. }, 'ページ先頭へ移動');
  655. key.setViewKey('G', function () {
  656. goDoCommand("cmd_scrollBottom");
  657. }, 'ページ末尾へ移動');
  658. key.setViewKey('r', function (aEvent) {
  659. BrowserReload();
  660. }, '再読み込み');
  661. key.setViewKey('m', function (ev, arg) {
  662. _fi.toogle();
  663. }, 'fetchimiをトグル');
  664. key.setViewKey('SPC', function (ev, arg) {
  665. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  666. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  667. }, 'タブの選択をトグルして次のタブ');
  668. key.setViewKey('S-SPC', function (ev, arg) {
  669. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  670. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  671. }, 'タブの選択をトグルして前のタブ');
  672. key.setViewKey('z', function (ev, arg) {
  673. ext.exec("keysnail-z-menu", arg, ev);
  674. }, 'open keysnail setting menu', true);
  675. key.setViewKey('C-SPC', function (ev, arg) {
  676. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  677. }, 'タブの選択をトグル');
  678. key.setViewKey('e', function () {
  679. command.focusElement(command.elementsRetrieverTextarea, 0);
  680. }, '最初のインプットエリアへフォーカス', true);
  681. key.setViewKey('S', function (ev, arg) {
  682. if (window.loadURI) {
  683. 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{}");
  684. }
  685. }, 'google reader share');
  686. key.setViewKey('!', function (ev, arg) {
  687. shell.input();
  688. }, 'Command system');
  689. key.setViewKey('R', function () {
  690. BrowserReloadSkipCache();
  691. }, '更新(キャッシュを無視)');
  692. key.setViewKey('<backspace>', function () {
  693. BrowserBack();
  694. }, '戻る');
  695. key.setViewKey('S-<backspace>', function () {
  696. BrowserForward();
  697. }, '進む');
  698. key.setViewKey('q', function (ev, arg) {
  699. ext.exec("query-then-engine", arg, ev);
  700. }, 'enter search word and then select engine', true);
  701. key.setViewKey('/', function () {
  702. command.iSearchForward();
  703. }, 'インクリメンタル検索', true);
  704. key.setViewKey('?', function (ev) {
  705. command.iSearchForwardKs(ev);
  706. }, 'Emacs ライクなインクリメンタル検索', true);
  707. key.setViewKey('a', function (ev, arg) {
  708. allTabs.open();
  709. }, 'alltabs.open');
  710. key.setViewKey([['<right>'], ['d']], function (ev) {
  711. goDoCommand("cmd_scrollPageDown");
  712. }, '一画面スクロールダウン');
  713. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  714. return;
  715. }, 'ignore');
  716. key.setViewKey(':', function (ev, arg) {
  717. return !document.getElementById("keysnail-prompt").hidden &&
  718. document.getElementById("keysnail-prompt-textbox").focus();
  719. }, 'KeySnail のプロンプトへフォーカス', true);
  720. key.setViewKey('B', function (ev) {
  721. var browser = getBrowser();
  722. if (browser.mCurrentTab.previousSibling) {
  723. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  724. } else {
  725. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  726. }
  727. }, '選択中のタブを左へ');
  728. key.setViewKey('0', function (ev) {
  729. BrowserCloseTabOrWindow();
  730. }, 'タブ / ウィンドウを閉じる');
  731. key.setViewKey('C', function (ev, arg) {
  732. ext.exec("linksnail", arg, ev);
  733. }, 'LinkSnail', true);
  734. key.setViewKey('C-<backspace>', function (ev, arg) {
  735. ext.exec("list-tab-history", arg, ev);
  736. }, 'List tab history', true);
  737. key.setViewKey('I', function (ev, arg) {
  738. ext.exec("instapaper-post-page-with-comment", arg, ev);
  739. }, 'post page and comment', true);
  740. key.setViewKey('T', function (ev, arg) {
  741. ext.exec("mstranslator-open-prompt", arg, ev);
  742. }, 'MSTranslator - Open prompt', true);
  743. key.setViewKey('n', function (ev) {
  744. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  745. }, '一行スクロールダウン');
  746. key.setViewKey('p', function (ev) {
  747. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  748. }, '一行スクロールアップ');
  749. key.setViewKey('f', function (ev) {
  750. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  751. }, '右へスクロール');
  752. key.setViewKey('b', function (ev) {
  753. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  754. }, '左へスクロール');
  755. key.setViewKey('F', function (ev) {
  756. var browser = getBrowser();
  757. if (browser.mCurrentTab.nextSibling) {
  758. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  759. } else {
  760. browser.moveTabTo(browser.mCurrentTab, 0);
  761. }
  762. }, '選択中のタブを右へ');
  763. key.setViewKey('U', function (ev, arg) {
  764. ext.exec("list-closed-tabs", arg, ev);
  765. }, 'List closed tabs', true);
  766. key.setEditKey('C-<tab>', function (ev) {
  767. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  768. }, '次のテキストエリアへフォーカス');