Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

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