選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

1085 行
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.yass.edgetype":0,
  400. "extensions.yass.selectedpreset":"red",
  401. "font.default.x-western":"sans-serif",
  402. "gecko.handlerService.schemes.mailto.1.name":"Gmail",
  403. "general.warnOnAboutConfig":false,
  404. "keyword.URL":"http://www.bing.com/search?q=",
  405. "browser.search.defaultenginename":"Bing",
  406. "browser.search.defaulturl":"http://www.bing.com/search?q=",
  407. "network.dns.disableIPv6":true,
  408. "refcontrol.actions":
  409. "@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  410. "scrapbook.tabs.open":true
  411. }
  412. );
  413. if(/^Linux/.test(navigator.platform)){
  414. util.setPrefs(
  415. {
  416. "browser.cache.disk.parent_directory":"/tmp",
  417. "browser.cache.disk.capacity":524288
  418. }
  419. );
  420. }
  421. display.showPopup("Keysnail", "My prefs done.");
  422. }, 'my setpref');
  423. ext.add('auto-install-plugins', function(ev, arg){
  424. var urls = [
  425. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  426. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  427. 'https://raw.github.com/mooz/keysnail/master/plugins/hok.ks.js',
  428. 'https://github.com/mooz/keysnail/raw/master/plugins/builtin-commands-ext.ks.js',
  429. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  430. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  431. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  432. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  433. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  434. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  435. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  436. 'https://raw.github.com/10sr/keysnail-plugin/master/list-current-urls.ks.js',
  437. 'https://gist.githubusercontent.com/10sr/1976942/raw/firefox-addon-manager.ks.js',
  438. 'https://gist.githubusercontent.com/958/1450594/raw/mstranslator.ks.js'
  439. ];
  440. function inst(a){
  441. if(a.length == 0){
  442. display.showPopup("auto-install-plugins",
  443. "All installation finished.");
  444. }else{
  445. var url = a.shift();
  446. var path = userscript.pluginDir +
  447. userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  448. if(plugins.context[path] === undefined){
  449. userscript.installPluginFromURL(url, function(){inst(a);});
  450. }else{
  451. inst(a);
  452. }
  453. }
  454. }
  455. inst(urls);
  456. }, 'Install plugins automatically if not installed yet.');
  457. ext.add('put-aside-this-page', function (ev, arg) {
  458. var n = getBrowser().mCurrentTab._tPos;
  459. getBrowser().moveTabTo(getBrowser().mCurrentTab, 0);
  460. if (n != 0) {
  461. getBrowser().selectedTab = getBrowser().mTabs[n];
  462. }
  463. }, 'put aside this page');
  464. ext.add('send-escape', function (ev, arg) {
  465. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  466. }, 'escape');
  467. ext.add("open-hatebu-comment", function (ev, arg) {
  468. var url = window.content.location.href.replace(/^[^/]*\/\//, "");
  469. window.content.location.href = "http://b.hatena.ne.jp/entry/" + url;
  470. }, 'hatebu');
  471. // ext.add("focus-on-content", function(){
  472. // let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  473. // gBrowser.focus();
  474. // content.focus();
  475. // }, "forcus on content");
  476. ext.add("hide-sidebar", function(){
  477. var sidebarBox = document.getElementById("sidebar-box");
  478. if (!sidebarBox.hidden) {
  479. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  480. }
  481. }, "hide-sidebar");
  482. ext.add("close-and-next-tab", function (ev, arg) {
  483. var n = getBrowser().mCurrentTab._tPos;
  484. getBrowser().removeCurrentTab();
  485. getBrowser().selectedTab = getBrowser().mTabs[n];
  486. }, "close and focus to next tab");
  487. //////////////////////////////////////
  488. //
  489. ext.add("restart-firefox-add-menu", function(){
  490. const XUL_NS =
  491. "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  492. var cmdelm = document.createElementNS(XUL_NS, "command");
  493. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  494. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  495. var commandset = document.getElementById("mainCommandSet");
  496. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  497. commandset.appendChild(cmdelm);
  498. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  499. menuelm.setAttribute("label", "Restart Firefox");
  500. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  501. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  502. var menu = document.getElementById("menu_FilePopup");
  503. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  504. menu.appendChild(menuelm);
  505. }, "add restart firefox menu");
  506. /////////////////////////////////////////
  507. // feed url
  508. ext.add("feed-add-to-feedly", function(){
  509. var url = window.content.location.href;
  510. window.content.location.href =
  511. "http://cloud.feedly.com/#subscription%2Ffeed%2F" +
  512. encodeURIComponent(url);
  513. }, "Add current feed to feedly");
  514. (function(){
  515. var feedhandler = "http://cloud.feedly.com/#subscription%2Ffeed%2F%s";
  516. function getFeeds(){
  517. const doc = content.document;
  518. var feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  519. for ([, e] in Iterator(doc.querySelectorAll([
  520. 'link[type="application/rss+xml"]',
  521. 'link[type="application/atom+xml"]'
  522. ])))];
  523. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,
  524. "$1");
  525. for (i = 0; i < feeds.length; i++)
  526. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  527. // feeds.unshift([window.content.document.title,
  528. // window.content.location.href]);
  529. return feeds;
  530. };
  531. ext.add("copy-feed-url", function () {
  532. var feeds = getFeeds();
  533. if (! feeds.length) {
  534. display.echoStatusBar("No feed found.");
  535. return;
  536. }
  537. prompt.selector(
  538. {
  539. message : "Select Feed",
  540. collection : feeds,
  541. callback : function (i) {
  542. if (i >= 0) {
  543. command.setClipboardText(feeds[i][1]);
  544. }
  545. }
  546. }
  547. );
  548. }, "Copy url or feed url of current page");
  549. ext.add("open-feed", function () {
  550. var feeds = getFeeds();
  551. if (! feeds.length) {
  552. display.echoStatusBar("No feed found.");
  553. return;
  554. }
  555. prompt.selector({
  556. message : "Select Feed",
  557. collection : feeds,
  558. callback : function (i) {
  559. if (i < 0) {
  560. return;
  561. }
  562. var feedurl = feeds[i][1];
  563. if (feedhandler) {
  564. window.openUILinkIn(
  565. feedhandler.replace("%s", feedurl),
  566. "tab"
  567. );
  568. } else {
  569. window.openUILinkIn(feedurl, "tab");
  570. }
  571. }
  572. });
  573. }, "Copy url or feed url of current page");
  574. })();
  575. ///////////////////////////////////////
  576. // keysnail z menu
  577. ext.add("keysnail-setting-dialog", function(){
  578. KeySnail.openPreference();
  579. }, "keysnail setting dialog");
  580. ext.add("keysnail-plugin-manager", function(){
  581. userscript.openPluginManager();
  582. }, "keysnail plugin manager");
  583. ext.add("firefox-open-addon-manager", function(){
  584. BrowserOpenAddonsMgr();
  585. }, "firefox addon manager");
  586. ext.add("keysnail-reload-init-file", function(){
  587. userscript.reload();
  588. }, "keysnail reload init file");
  589. ext.add("keysnail-z-menu",function(){
  590. var list = [["keysnail-setting-dialog"],
  591. ["keysnail-plugin-manager"],
  592. ["firefox-open-addon-manager"],
  593. ["keysnail-reload-init-file"],
  594. // ["check-for-plugins-update"],
  595. ["restart-firefox"]
  596. ];
  597. prompt.selector(
  598. {
  599. message : "open setting dialog",
  600. collection : list,
  601. callback : function (i) {
  602. ext.exec(list[i][0]);
  603. }
  604. });
  605. },"open keysnail z menu");
  606. ///////////////////////////////////
  607. // search web
  608. ext.add("query-then-engine", function () {
  609. prompt.reader({
  610. message : "Search Word?:",
  611. group : "query_word",
  612. completer : completer.matcher.header(share.friendsCache || []),
  613. callback : function (q) {
  614. if (q) {
  615. prompt.selector({
  616. message : "search \"" + q + "\" with?",
  617. collection : plugins.options["search-url-list"],
  618. width : [20,80],
  619. callback : function (i) {
  620. getBrowser().selectedTab =
  621. getBrowser().addTab(
  622. plugins.options["search-url-list"][i][1].
  623. replace("%r",q).replace(
  624. "%q",encodeURIComponent(q)));
  625. }
  626. });
  627. };
  628. },
  629. initialInput : content.document.getSelection() || ""
  630. });
  631. }, "enter search word and then select engine");
  632. /////////////////////////////////////
  633. // closed tab list
  634. ext.add("list-closed-tabs", function () {
  635. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  636. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(
  637. Ci.nsISessionStore
  638. );
  639. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  640. var closedTabs = [[tab.image || fav, tab.title, tab.url]
  641. for each (tab in json.decode(ss.getClosedTabData(window)))
  642. ];
  643. if (!closedTabs.length)
  644. return void display.echoStatusBar("No recently closed tab.", 2000);
  645. prompt.selector(
  646. {
  647. message : "select tab to undo:",
  648. collection : closedTabs,
  649. flags : [ICON | IGNORE, 0, 0],
  650. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  651. });
  652. }, "List closed tabs");
  653. ///////////////////////////////
  654. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  655. ext.add("list-tab-history", function () {
  656. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  657. var tabHistory = [];
  658. var sessionHistory = getBrowser().webNavigation.sessionHistory;
  659. if (sessionHistory.count < 1)
  660. return void display.echoStatusBar("Tab history not exist", 2000);
  661. var curIdx = sessionHistory.index;
  662. for (var i = 0; i < sessionHistory.count; i++) {
  663. var entry = sessionHistory.getEntryAtIndex(i, false);
  664. if (!entry)
  665. continue;
  666. try {
  667. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  668. .getService(Ci.nsIFaviconService)
  669. .getFaviconForPage(entry.URI).spec;
  670. } catch (ex) {}
  671. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  672. }
  673. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  674. if (tabHistory[thIdx][3] == curIdx) break;
  675. }
  676. prompt.selector(
  677. {
  678. message : "select history in tab",
  679. collection : tabHistory,
  680. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  681. header : ["Title", "URL"],
  682. initialIndex : thIdx,
  683. callback : function(i) {
  684. if (i >= 0)
  685. getBrowser().webNavigation.gotoIndex(tabHistory[i][3]);
  686. }
  687. });
  688. }, 'List tab history');
  689. //}}%PRESERVE%
  690. // ========================================================================= //
  691. // ========================= Special key settings ========================== //
  692. key.quitKey = "ESC";
  693. key.helpKey = "<f1>";
  694. key.escapeKey = "C-q";
  695. key.macroStartKey = "";
  696. key.macroEndKey = "";
  697. key.universalArgumentKey = "C-u";
  698. key.negativeArgument1Key = "C--";
  699. key.negativeArgument2Key = "C-M--";
  700. key.negativeArgument3Key = "M--";
  701. key.suspendKey = "Not defined";
  702. // ================================= Hooks ================================= //
  703. hook.setHook('KeyBoardQuit', function (aEvent) {
  704. // ext.exec("hide-sidebar");
  705. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  706. getBrowser().focus();
  707. content.focus();
  708. command.closeFindBar();
  709. if (util.isCaretEnabled()) {
  710. command.resetMark(aEvent);
  711. } else {
  712. goDoCommand("cmd_selectNone");
  713. }
  714. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  715. });
  716. hook.setHook('Unload', function () {
  717. util.getBrowserWindows().some(function (win) {
  718. if (win === window) {
  719. return false;
  720. }
  721. const ks = win.KeySnail;
  722. share.pluginUpdater = ks.getPluginUpdater(
  723. share.pluginUpdater.pluginsWithUpdate);
  724. ks.setUpPluginUpdaterDelegator();
  725. return true;
  726. });
  727. });
  728. hook.setHook('LocationChange', function (aNsURI) {
  729. echoTabInfo.echo();
  730. });
  731. // ============================= Key bindings ============================== //
  732. key.setGlobalKey('C-<up>', function () {
  733. var browser = getBrowser();
  734. if (browser.mCurrentTab.previousSibling) {
  735. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  736. } else {
  737. browser.moveTabTo(browser.mCurrentTab,
  738. browser.mTabContainer.childNodes.length - 1);
  739. }
  740. }, '選択中のタブを右へ');
  741. key.setGlobalKey('C-<down>', function () {
  742. var browser = getBrowser();
  743. if (browser.mCurrentTab.nextSibling) {
  744. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  745. } else {
  746. browser.moveTabTo(browser.mCurrentTab, 0);
  747. }
  748. }, '選択中のタブを左へ');
  749. key.setGlobalKey('<delete>', function (ev, arg) {
  750. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  751. getBrowser().focus();
  752. content.focus();
  753. }, 'コンテンツへフォーカス', true);
  754. key.setGlobalKey('<f11>', function (ev, arg) {
  755. ext.exec("strong-fullscreen", arg, ev);
  756. }, 'go fullscreen with hiding toolbar and tabbar', true);
  757. key.setGlobalKey('<end>', function (ev) {
  758. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  759. }, 'ひとつ右のタブへ');
  760. key.setGlobalKey('<home>', function (ev) {
  761. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  762. }, 'ひとつ左のタブへ');
  763. key.setGlobalKey('<next>', function (ev) {
  764. let browser = getBrowser();
  765. if (browser.mCurrentTab.nextSibling) {
  766. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  767. } else {
  768. browser.moveTabTo(browser.mCurrentTab, 0);
  769. }
  770. }, '選択中のタブを右へ');
  771. key.setGlobalKey('<prior>', function (ev) {
  772. let browser = getBrowser();
  773. if (browser.mCurrentTab.previousSibling) {
  774. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  775. } else {
  776. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  777. }
  778. }, '選択中のタブを左へ');
  779. key.setViewKey('0', function (ev) {
  780. BrowserCloseTabOrWindow();
  781. }, 'タブ / ウィンドウを閉じる');
  782. key.setViewKey('l', function (ev) {
  783. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  784. }, 'ひとつ右のタブへ');
  785. key.setViewKey('h', function (ev) {
  786. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  787. }, 'ひとつ左のタブへ');
  788. key.setViewKey('o', function (ev, arg) {
  789. ext.exec("hok-start-foreground-mode", arg, ev);
  790. }, 'Start Hit a Hint foreground mode', true);
  791. key.setViewKey('c', function (ev) {
  792. command.interpreter();
  793. }, 'JavaScript のコードを評価');
  794. key.setViewKey('D', function (ev, arg) {
  795. ext.exec("dig-url", arg, ev);
  796. }, 'dig url with selector', true);
  797. key.setViewKey('x', function (aEvent, aArg) {
  798. ext.select(aArg, aEvent);
  799. }, 'エクステ一覧');
  800. key.setViewKey(['t', 'w'], function (ev, arg) {
  801. ext.exec("twitter-client-tweet", arg, ev);
  802. }, 'つぶやく', true);
  803. key.setViewKey(['t', 'p'], function (ev, arg) {
  804. ext.exec("twitter-client-tweet-this-page", arg, ev);
  805. }, 'このページのタイトルと URL を使ってつぶやく', true);
  806. key.setViewKey([['u'], ['S-SPC']], function (ev) {
  807. goDoCommand("cmd_scrollPageUp");
  808. }, '一画面分スクロールアップ');
  809. key.setViewKey('g', function () {
  810. goDoCommand("cmd_scrollTop");
  811. }, 'ページ先頭へ移動');
  812. key.setViewKey('G', function () {
  813. goDoCommand("cmd_scrollBottom");
  814. }, 'ページ末尾へ移動');
  815. key.setViewKey('r', function (aEvent) {
  816. BrowserReload();
  817. }, '再読み込み');
  818. key.setViewKey('z', function (ev, arg) {
  819. ext.exec("keysnail-z-menu", arg, ev);
  820. }, 'open keysnail setting menu', true);
  821. key.setViewKey('e', function () {
  822. command.focusElement(command.elementsRetrieverTextarea, 0);
  823. }, '最初のインプットエリアへフォーカス', true);
  824. key.setViewKey('S', function (ev, arg) {
  825. if (window.loadURI) {
  826. 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{}");
  827. }
  828. }, 'google reader share');
  829. key.setViewKey('!', function (ev, arg) {
  830. shell.input();
  831. }, 'Command system');
  832. key.setViewKey('R', function () {
  833. BrowserReloadSkipCache();
  834. }, '更新(キャッシュを無視)');
  835. key.setViewKey('<backspace>', function () {
  836. BrowserBack();
  837. }, '戻る');
  838. key.setViewKey('S-<backspace>', function () {
  839. BrowserForward();
  840. }, '進む');
  841. key.setViewKey('q', function (ev, arg) {
  842. ext.exec("query-then-engine", arg, ev);
  843. }, 'enter search word and then select engine', true);
  844. key.setViewKey('/', function () {
  845. command.iSearchForward();
  846. }, 'インクリメンタル検索', true);
  847. key.setViewKey('?', function (ev) {
  848. command.iSearchForwardKs(ev);
  849. }, 'Emacs ライクなインクリメンタル検索', true);
  850. key.setViewKey('a', function (ev, arg) {
  851. allTabs.open();
  852. }, 'alltabs.open');
  853. key.setViewKey([['d'], ['SPC']], function (ev) {
  854. goDoCommand("cmd_scrollPageDown");
  855. }, '一画面スクロールダウン');
  856. key.setViewKey(':', function (ev, arg) {
  857. return !document.getElementById("keysnail-prompt").hidden &&
  858. document.getElementById("keysnail-prompt-textbox").focus();
  859. }, 'KeySnail のプロンプトへフォーカス', true);
  860. key.setViewKey('B', function (ev) {
  861. var browser = getBrowser();
  862. if (browser.mCurrentTab.previousSibling) {
  863. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  864. } else {
  865. browser.moveTabTo(browser.mCurrentTab,
  866. browser.mTabContainer.childNodes.length - 1);
  867. }
  868. }, '選択中のタブを左へ');
  869. key.setViewKey('C', function (ev, arg) {
  870. ext.exec("linksnail", arg, ev);
  871. }, 'LinkSnail', true);
  872. key.setViewKey('C-<backspace>', function (ev, arg) {
  873. ext.exec("list-tab-history", arg, ev);
  874. }, 'List tab history', true);
  875. key.setViewKey('I', function (ev, arg) {
  876. ext.exec("instapaper-post-page-with-comment", arg, ev);
  877. }, 'post page and comment', true);
  878. key.setViewKey('T', function (ev, arg) {
  879. ext.exec("mstranslator-open-prompt", arg, ev);
  880. }, 'MSTranslator - Open prompt', true);
  881. key.setViewKey('f', function (ev, arg) {
  882. ext.exec('strong-fullscreen', arg, ev);
  883. }, 'go fullscreen with hiding toolbar and tabbar', true);
  884. key.setViewKey('F', function (ev) {
  885. var browser = getBrowser();
  886. if (browser.mCurrentTab.nextSibling) {
  887. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  888. } else {
  889. browser.moveTabTo(browser.mCurrentTab, 0);
  890. }
  891. }, '選択中のタブを右へ');
  892. key.setViewKey('U', function (ev, arg) {
  893. ext.exec("list-closed-tabs", arg, ev);
  894. }, 'List closed tabs', true);
  895. key.setViewKey('j', function (ev) {
  896. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  897. }, '一行スクロールダウン');
  898. key.setViewKey('k', function (ev) {
  899. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  900. }, '一行スクロールアップ');
  901. key.setEditKey('C-<tab>', function (ev) {
  902. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  903. }, '次のテキストエリアへフォーカス');
  904. key.setEditKey('C-a', function (ev) {
  905. command.beginLine(ev);
  906. }, '行頭へ移動');
  907. key.setEditKey('C-e', function (ev) {
  908. command.endLine(ev);
  909. }, '行末へ');
  910. key.setEditKey('C-d', function (ev) {
  911. goDoCommand("cmd_deleteCharForward");
  912. }, '次の一文字削除');
  913. key.setEditKey('C-b', function (ev) {
  914. command.previousChar(ev);
  915. }, '一文字左へ移動');
  916. key.setEditKey('C-f', function (ev) {
  917. command.nextChar(ev);
  918. }, '一文字右へ移動');
  919. key.setEditKey('C-h', function (ev) {
  920. goDoCommand("cmd_deleteCharBackward");
  921. }, '前の一文字を削除');
  922. key.setEditKey('C-k', function (ev) {
  923. command.killLine(ev);
  924. }, 'カーソルから先を一行カット (Kill line)');
  925. key.setEditKey('C-l', function (ev) {
  926. command.recenter(ev);
  927. }, 'カーソル位置が画面の中央へ来るようスクロール', true);
  928. key.setEditKey('C-n', function (ev) {
  929. command.nextLine(ev);
  930. }, '一行下へ');
  931. key.setEditKey('C-p', function (ev) {
  932. command.previousLine(ev);
  933. }, '一行上へ');
  934. key.setEditKey('C-o', function (ev) {
  935. command.openLine(ev);
  936. }, '行を開く (Open line)');
  937. key.setViewKey('p', function (ev, arg) {
  938. ext.exec('pocket-add-current', arg, ev);
  939. }, 'Add current page', true);
  940. key.setViewKey('P', function (ev, arg) {
  941. ext.exec('pocket-open-latest', arg, ev);
  942. }, 'Open last saved page', true);