25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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