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

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