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.
 
 
 
 
 
 

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