Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

1086 righe
38 KiB

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