您最多选择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 年前
13 年前
13 年前
13 年前
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 年前
13 年前
13 年前
12 年前
13 年前
12 年前
13 年前
12 年前
13 年前
13 年前
13 年前
13 年前
12 年前
13 年前
13 年前
13 年前
12 年前
12 年前
13 年前
13 年前
13 年前
13 年前
13 年前
12 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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:88"] = [
  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://github.com/mooz/keysnail/raw/master/plugins/builtin-commands-ext.ks.js',
  311. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  312. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  313. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  314. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  315. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  316. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  317. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  318. 'https://raw.github.com/gist/1976942/firefox-addon-manager.ks.js',
  319. 'https://raw.github.com/gist/1450594/mstranslator.ks.js'
  320. ];
  321. function inst(a){
  322. if(a.length == 0){
  323. display.showPopup("auto-install-plugins", "All installation finished.");
  324. }else{
  325. var url = a.shift();
  326. var path = userscript.pluginDir + userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  327. if(plugins.context[path] === undefined){
  328. userscript.installPluginFromURL(url, function(){inst(a);});
  329. }else{
  330. inst(a);
  331. }
  332. }
  333. }
  334. inst(urls);
  335. }, 'Install plugins automatically if not installed yet.');
  336. ext.add('put-aside-this-page', function (ev, arg) {
  337. var n = gBrowser.mCurrentTab._tPos;
  338. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  339. if (n != 0) {
  340. gBrowser.selectedTab = gBrowser.mTabs[n];
  341. }
  342. }, 'put aside this page');
  343. ext.add('send-escape', function (ev, arg) {
  344. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  345. }, 'escape');
  346. ext.add("open-hatebu-comment", function (ev, arg) {
  347. if (window.loadURI) {
  348. loadURI("javascript:location.href='http://b.hatena.ne.jp/entry?mode=more&url='+encodeURIComponent(location.href);");
  349. }
  350. }, 'hatebu');
  351. // ext.add("focus-on-content", function(){
  352. // let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  353. // gBrowser.focus();
  354. // content.focus();
  355. // }, "forcus on content");
  356. ext.add("hide-sidebar", function(){
  357. var sidebarBox = document.getElementById("sidebar-box");
  358. if (!sidebarBox.hidden) {
  359. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  360. }
  361. }, "hide-sidebar");
  362. ext.add("close-and-next-tab", function (ev, arg) {
  363. var n = gBrowser.mCurrentTab._tPos;
  364. gBrowser.removeCurrentTab();
  365. gBrowser.selectedTab = gBrowser.mTabs[n];
  366. }, "close and focus to next tab");
  367. //////////////////////////////////////
  368. //
  369. ext.add("restart-firefox-add-menu", function(){
  370. const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  371. var cmdelm = document.createElementNS(XUL_NS, "command");
  372. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  373. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  374. var commandset = document.getElementById("mainCommandSet");
  375. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  376. commandset.appendChild(cmdelm);
  377. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  378. menuelm.setAttribute("label", "Restart Firefox");
  379. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  380. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  381. var menu = document.getElementById("menu_FilePopup");
  382. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  383. menu.appendChild(menuelm);
  384. }, "add restart firefox menu");
  385. //////////////////////////////////////
  386. // restart firefox
  387. // http://keysnail.g.hatena.ne.jp/Shinnya/20100723/1279878815
  388. // ext.add("restart-firefox",function (ev) {
  389. // const nsIAppStartup = Components.interfaces.nsIAppStartup;
  390. // // Notify all windows that an application quit has been requested.
  391. // var os = Components.classes["@mozilla.org/observer-service;1"]
  392. // .getService(Components.interfaces.nsIObserverService);
  393. // var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  394. // .createInstance(Components.interfaces.nsISupportsPRBool);
  395. // os.notifyObservers(cancelQuit, "quit-application-requested", null);
  396. // // Something aborted the quit process.
  397. // if (cancelQuit.data)
  398. // return;
  399. // // Notify all windows that an application quit has been granted.
  400. // os.notifyObservers(null, "quit-application-granted", null);
  401. // // Enumerate all windows and call shutdown handlers
  402. // var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  403. // .getService(Components.interfaces.nsIWindowMediator);
  404. // var windows = wm.getEnumerator(null);
  405. // while (windows.hasMoreElements()) {
  406. // var win = windows.getNext();
  407. // if (("tryToClose" in win) && !win.tryToClose())
  408. // return;
  409. // }
  410. // Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
  411. // .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
  412. // }, "restart firefox");
  413. /////////////////////////////////////////
  414. // copy feed url
  415. ext.add("copy-url", function () {
  416. const doc = content.document;
  417. let feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  418. for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]',
  419. 'link[type="application/atom+xml"]'])))];
  420. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1");
  421. for (i = 0; i < feeds.length; i++)
  422. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  423. feeds.unshift([window.content.document.title,window.content.location.href]);
  424. prompt.selector(
  425. {
  426. message : "Select Feed",
  427. collection : feeds,
  428. callback : function (i) {
  429. if (i >= 0)
  430. command.setClipboardText(feeds[i][1]);
  431. }
  432. }
  433. );
  434. }, "Copy url or feed url of current page");
  435. ///////////////////////////////////////
  436. // keysnail z menu
  437. ext.add("keysnail-setting-dialog", function(){
  438. KeySnail.openPreference();
  439. }, "keysnail setting dialog");
  440. ext.add("keysnail-plugin-manager", function(){
  441. userscript.openPluginManager();
  442. }, "keysnail plugin manager");
  443. ext.add("firefox-open-addon-manager", function(){
  444. BrowserOpenAddonsMgr();
  445. }, "firefox addon manager");
  446. ext.add("keysnail-reload-init-file", function(){
  447. userscript.reload();
  448. }, "keysnail reload init file");
  449. ext.add("keysnail-z-menu",function(){
  450. var list = [["keysnail-setting-dialog"],
  451. ["keysnail-plugin-manager"],
  452. ["firefox-open-addon-manager"],
  453. ["keysnail-reload-init-file"],
  454. // ["check-for-plugins-update"],
  455. ["restart-firefox"]
  456. ];
  457. prompt.selector(
  458. {
  459. message : "open setting dialog",
  460. collection : list,
  461. callback : function (i) {
  462. ext.exec(list[i][0]);
  463. }
  464. });
  465. },"open keysnail z menu");
  466. ///////////////////////////////////
  467. // search web
  468. ext.add("query-then-engine", function () {
  469. prompt.reader({message : "Search Word?:",
  470. group : "query_word",
  471. completer : completer.matcher.header(share.friendsCache || []),
  472. callback : function (q) {
  473. if (q) {
  474. prompt.selector({ message : "search \"" + q + "\" with?",
  475. collection : plugins.options["search-url-list"],
  476. width : [20,80],
  477. callback : function (i) {
  478. getBrowser().selectedTab = getBrowser().addTab(plugins.options["search-url-list"][i][1].replace("%r",q).replace("%q",encodeURIComponent(q)));
  479. },
  480. });
  481. };
  482. },
  483. initialInput : content.document.getSelection() || "",
  484. });
  485. }, "enter search word and then select engine");
  486. /////////////////////////////////////
  487. // closed tab list
  488. ext.add("list-closed-tabs", function () {
  489. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  490. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  491. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  492. var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  493. if (!closedTabs.length)
  494. return void display.echoStatusBar("No recently closed tab.", 2000);
  495. prompt.selector(
  496. {
  497. message : "select tab to undo:",
  498. collection : closedTabs,
  499. flags : [ICON | IGNORE, 0, 0],
  500. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  501. });
  502. }, "List closed tabs");
  503. // ext.add("echo-closed-tabs", function () {
  504. // var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  505. // var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  506. // // var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  507. // var lasttab = json.decode(ss.getClosedTabData(window))[0];
  508. // dump = ""
  509. // for (var i in lasttab) { dump += lasttab[i] + "\n"; }
  510. // confirm(dump);
  511. // }, "List closed tabs");
  512. ///////////////////////////////
  513. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  514. ext.add("list-tab-history", function () {
  515. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  516. var tabHistory = [];
  517. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  518. if (sessionHistory.count < 1)
  519. return void display.echoStatusBar("Tab history not exist", 2000);
  520. var curIdx = sessionHistory.index;
  521. for (var i = 0; i < sessionHistory.count; i++) {
  522. var entry = sessionHistory.getEntryAtIndex(i, false);
  523. if (!entry)
  524. continue;
  525. try {
  526. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  527. .getService(Ci.nsIFaviconService)
  528. .getFaviconForPage(entry.URI).spec;
  529. } catch (ex) {}
  530. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  531. }
  532. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  533. if (tabHistory[thIdx][3] == curIdx) break;
  534. }
  535. prompt.selector(
  536. {
  537. message : "select history in tab",
  538. collection : tabHistory,
  539. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  540. header : ["Title", "URL"],
  541. initialIndex : thIdx,
  542. callback : function(i) { if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]); }
  543. });
  544. }, 'List tab history');
  545. //}}%PRESERVE%
  546. // ========================================================================= //
  547. // ========================= Special key settings ========================== //
  548. key.quitKey = "ESC";
  549. key.helpKey = "<f1>";
  550. key.escapeKey = "C-q";
  551. key.macroStartKey = "";
  552. key.macroEndKey = "";
  553. key.universalArgumentKey = "C-u";
  554. key.negativeArgument1Key = "C--";
  555. key.negativeArgument2Key = "C-M--";
  556. key.negativeArgument3Key = "M--";
  557. key.suspendKey = "Not defined";
  558. // ================================= Hooks ================================= //
  559. hook.setHook('KeyBoardQuit', function (aEvent) {
  560. ext.exec("hide-sidebar");
  561. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  562. gBrowser.focus();
  563. content.focus();
  564. command.closeFindBar();
  565. if (util.isCaretEnabled()) {
  566. command.resetMark(aEvent);
  567. } else {
  568. goDoCommand("cmd_selectNone");
  569. }
  570. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  571. });
  572. hook.setHook('Unload', function () {
  573. util.getBrowserWindows().some(function (win) {
  574. if (win === window) {
  575. return false;
  576. }
  577. const ks = win.KeySnail;
  578. share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate);
  579. ks.setUpPluginUpdaterDelegator();
  580. return true;
  581. });
  582. });
  583. // ============================= Key bindings ============================== //
  584. key.setGlobalKey('C-<right>', function () {
  585. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  586. }, 'ひとつ右のタブへ');
  587. key.setGlobalKey('C-<left>', function () {
  588. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  589. }, 'ひとつ左のタブへ');
  590. key.setGlobalKey('C-<up>', function () {
  591. var browser = getBrowser();
  592. if (browser.mCurrentTab.previousSibling) {
  593. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  594. } else {
  595. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  596. }
  597. }, '選択中のタブを右へ');
  598. key.setGlobalKey('C-<down>', function () {
  599. var browser = getBrowser();
  600. if (browser.mCurrentTab.nextSibling) {
  601. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  602. } else {
  603. browser.moveTabTo(browser.mCurrentTab, 0);
  604. }
  605. }, '選択中のタブを左へ');
  606. key.setGlobalKey('C-h', function (ev, arg) {
  607. return;
  608. }, 'ignore');
  609. key.setGlobalKey('<delete>', function (ev, arg) {
  610. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  611. gBrowser.focus();
  612. content.focus();
  613. }, 'コンテンツへフォーカス', true);
  614. key.setGlobalKey('C-p', function (ev, arg) {
  615. return !document.getElementById("keysnail-prompt").hidden &&
  616. document.getElementById("keysnail-prompt-textbox").focus();
  617. }, 'KeySnail のプロンプトへフォーカス', true);
  618. key.setGlobalKey('<f11>', function (ev, arg) {
  619. ext.exec("strong-fullscreen", arg, ev);
  620. }, 'go fullscreen with hiding toolbar and tabbar', true);
  621. key.setViewKey('N', function (ev) {
  622. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  623. }, 'ひとつ右のタブへ');
  624. key.setViewKey('P', function (ev) {
  625. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  626. }, 'ひとつ左のタブへ');
  627. key.setViewKey('o', function (ev, arg) {
  628. ext.exec("hok-start-foreground-mode", arg, ev);
  629. }, 'Start Hit a Hint foreground mode', true);
  630. key.setViewKey('c', function (ev) {
  631. command.interpreter();
  632. }, 'JavaScript のコードを評価');
  633. key.setViewKey('D', function (ev, arg) {
  634. ext.exec("dig-url", arg, ev);
  635. }, 'dig url with selector', true);
  636. key.setViewKey('x', function (aEvent, aArg) {
  637. ext.select(aArg, aEvent);
  638. }, 'エクステ一覧');
  639. key.setViewKey(['t', 'm'], function (ev, arg) {
  640. if (window.loadURI) {
  641. loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;");
  642. }
  643. }, 'open with tweetmeme');
  644. key.setViewKey(['t', 'w'], function (ev, arg) {
  645. ext.exec("twitter-client-tweet", arg, ev);
  646. }, 'つぶやく', true);
  647. key.setViewKey(['t', 'p'], function (ev, arg) {
  648. ext.exec("twitter-client-tweet-this-page", arg, ev);
  649. }, 'このページのタイトルと URL を使ってつぶやく', true);
  650. key.setViewKey([['u'], ['<left>']], function (ev) {
  651. goDoCommand("cmd_scrollPageUp");
  652. }, '一画面分スクロールアップ');
  653. key.setViewKey('g', function () {
  654. goDoCommand("cmd_scrollTop");
  655. }, 'ページ先頭へ移動');
  656. key.setViewKey('G', function () {
  657. goDoCommand("cmd_scrollBottom");
  658. }, 'ページ末尾へ移動');
  659. key.setViewKey('r', function (aEvent) {
  660. BrowserReload();
  661. }, '再読み込み');
  662. key.setViewKey('m', function (ev, arg) {
  663. _fi.toogle();
  664. }, 'fetchimiをトグル');
  665. key.setViewKey('SPC', function (ev, arg) {
  666. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  667. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  668. }, 'タブの選択をトグルして次のタブ');
  669. key.setViewKey('S-SPC', function (ev, arg) {
  670. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  671. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  672. }, 'タブの選択をトグルして前のタブ');
  673. key.setViewKey('z', function (ev, arg) {
  674. ext.exec("keysnail-z-menu", arg, ev);
  675. }, 'open keysnail setting menu', true);
  676. key.setViewKey('C-SPC', function (ev, arg) {
  677. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  678. }, 'タブの選択をトグル');
  679. key.setViewKey('e', function () {
  680. command.focusElement(command.elementsRetrieverTextarea, 0);
  681. }, '最初のインプットエリアへフォーカス', true);
  682. key.setViewKey('S', function (ev, arg) {
  683. if (window.loadURI) {
  684. 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{}");
  685. }
  686. }, 'google reader share');
  687. key.setViewKey('!', function (ev, arg) {
  688. shell.input();
  689. }, 'Command system');
  690. key.setViewKey('R', function () {
  691. BrowserReloadSkipCache();
  692. }, '更新(キャッシュを無視)');
  693. key.setViewKey('<backspace>', function () {
  694. BrowserBack();
  695. }, '戻る');
  696. key.setViewKey('S-<backspace>', function () {
  697. BrowserForward();
  698. }, '進む');
  699. key.setViewKey('q', function (ev, arg) {
  700. ext.exec("query-then-engine", arg, ev);
  701. }, 'enter search word and then select engine', true);
  702. key.setViewKey('/', function () {
  703. command.iSearchForward();
  704. }, 'インクリメンタル検索', true);
  705. key.setViewKey('?', function (ev) {
  706. command.iSearchForwardKs(ev);
  707. }, 'Emacs ライクなインクリメンタル検索', true);
  708. key.setViewKey('a', function (ev, arg) {
  709. allTabs.open();
  710. }, 'alltabs.open');
  711. key.setViewKey([['<right>'], ['d']], function (ev) {
  712. goDoCommand("cmd_scrollPageDown");
  713. }, '一画面スクロールダウン');
  714. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  715. return;
  716. }, 'ignore');
  717. key.setViewKey(':', function (ev, arg) {
  718. return !document.getElementById("keysnail-prompt").hidden &&
  719. document.getElementById("keysnail-prompt-textbox").focus();
  720. }, 'KeySnail のプロンプトへフォーカス', true);
  721. key.setViewKey('B', function (ev) {
  722. var browser = getBrowser();
  723. if (browser.mCurrentTab.previousSibling) {
  724. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  725. } else {
  726. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  727. }
  728. }, '選択中のタブを左へ');
  729. key.setViewKey('0', function (ev) {
  730. BrowserCloseTabOrWindow();
  731. }, 'タブ / ウィンドウを閉じる');
  732. key.setViewKey('C', function (ev, arg) {
  733. ext.exec("linksnail", arg, ev);
  734. }, 'LinkSnail', true);
  735. key.setViewKey('C-<backspace>', function (ev, arg) {
  736. ext.exec("list-tab-history", arg, ev);
  737. }, 'List tab history', true);
  738. key.setViewKey('I', function (ev, arg) {
  739. ext.exec("instapaper-post-page-with-comment", arg, ev);
  740. }, 'post page and comment', true);
  741. key.setViewKey('T', function (ev, arg) {
  742. ext.exec("mstranslator-open-prompt", arg, ev);
  743. }, 'MSTranslator - Open prompt', true);
  744. key.setViewKey('n', function (ev) {
  745. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  746. }, '一行スクロールダウン');
  747. key.setViewKey('p', function (ev) {
  748. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  749. }, '一行スクロールアップ');
  750. key.setViewKey('f', function (ev) {
  751. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  752. }, '右へスクロール');
  753. key.setViewKey('b', function (ev) {
  754. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  755. }, '左へスクロール');
  756. key.setViewKey('F', function (ev) {
  757. var browser = getBrowser();
  758. if (browser.mCurrentTab.nextSibling) {
  759. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  760. } else {
  761. browser.moveTabTo(browser.mCurrentTab, 0);
  762. }
  763. }, '選択中のタブを右へ');
  764. key.setViewKey('U', function (ev, arg) {
  765. ext.exec("list-closed-tabs", arg, ev);
  766. }, 'List closed tabs', true);
  767. key.setEditKey('C-<tab>', function (ev) {
  768. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  769. }, '次のテキストエリアへフォーカス');