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

_keysnail.js 34 KiB

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