Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

842 рядки
32 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. //////////////////////////////////////
  13. //// sitelocalkeymap
  14. var local = {};
  15. plugins.options["site_local_keymap.local_keymap"] = local;
  16. function fake(k, i) function () { key.feed(k, i); };
  17. function pass(k, i) [k, fake(k, i)];
  18. function ignore(k, i) [k, null];
  19. // ext.add("ext-name", function () {}, "ext description");
  20. // style.register("");
  21. // local["^http://"] = [['a', function(ev, arg){}],];
  22. ///////////////////////////////////////////
  23. //// firefox
  24. // style.register("#bookmarksPanel > hbox,#history-panel > hbox {display: none !important;} //#urlbar-container{max-width: 500px !important;}");
  25. ///////////////////////////////////
  26. //search engine
  27. plugins.options["search-url-list"] = [
  28. ["bing","http://bing.com/search?q=%q"],
  29. ["yatwitter search","http://yats-data.com/yats/search?query=%q"],
  30. ["twitter search","http://search.twitter.com/search?q=%q&lang=all"],
  31. ["tospy", "http://topsy.com/s?allow_lang=ja&q=%q"],
  32. ["2ch","http://2ch-ranking.net/search.php?q=%q&imp=and&order=time"],
  33. ["I\'m feelig lucky!","http://www.google.co.jp/search?q=%q&btnI=kudos"],
  34. ["uncyclopedia","http://ja.uncyclopedia.info/wiki/%q"],
  35. ["wikipedia","http://ja.wikipedia.org/wiki/%q"],
  36. ["nicovideo.jp","http://www.nicovideo.jp/search/%q"],
  37. ["alc","http://eow.alc.co.jp/%q/UTF-8/"],
  38. ["google map","http://maps.google.co.jp/maps?hl=ja&q=%q&um=1&ie=UTF-8&sa=N&tab=wl"],
  39. ["weblio","http://www.weblio.jp/content_find?query=%q"],
  40. ["shoutcast","http://www.shoutcast.com/Internet-Radio/%q"],
  41. ["10sr.posterous.com","http://www.google.com/search?q=%q&ie=UTF-8&oe=UTF-8&hl=ja&domains=10sr.posterous.com&sitesearch=10sr.posterous.com"],
  42. ["delicious 10sr","http://delicious.com/10sr?addtag=%q&setcount=50&opennew=1"],
  43. ["open raw","%r"],
  44. ];
  45. plugins.options["my-keysnail-bookmarks"] = [
  46. "twitter.com",
  47. ];
  48. // sitelocal keymap
  49. //////////////////////////////////////////
  50. // 2ch chaika
  51. // change chaika port every time firefox starts
  52. util.setIntPref("extensions.chaika.server_port.firefox",
  53. 8800 + Math.floor(Math.random() * 30));
  54. local["^http://127.0.0.1:8823/thread/"] = [
  55. ['k', function (ev, arg) {
  56. curl = window.content.location.href;
  57. kurl = curl.replace(/http:.*thread\/(.*\/).*/, "chaika://post/$1");
  58. window.content.location.href = kurl;
  59. }
  60. ],
  61. ];
  62. local["^http://w2.p2.2ch.net/p2/read.php"] = [
  63. ['k', function (ev, arg) {
  64. var url = window.content.location.href;
  65. var pt = /host=(.*?)&bbs=(.*?)&key=(.*?)&ls=/ ;
  66. var result = url.match(pt);
  67. var k = format("chaika://post/http://%s/test/read.cgi/%s/%s/", result[1], result[2], result[3]);
  68. window.content.location.href = k;
  69. }
  70. ],
  71. ];
  72. /////////////////////////////////////////
  73. // feedly
  74. local["^http://www.feedly.com/"] = [
  75. ['d', null],
  76. ['j', null],
  77. ['k', null],
  78. ['n', null],
  79. ['p', null],
  80. ['o', null],
  81. ['b', null],
  82. ['S', null],
  83. ['s', null],
  84. ['?', null],
  85. ['r', null],
  86. ['g', null],
  87. // ['x', function (ev, arg) {ev.target.dispatchEvent(key.stringToKeyEvent("g", true));}],
  88. ['l', function (ev, arg) {window.content.location.href = "http://www.feedly.com/home#latest";}],
  89. [['t', 'p'], function (ev, arg) {ev.target.dispatchEvent(key.stringToKeyEvent("t", true));}],
  90. [['t', 'w'], function (ev, arg) {ext.exec("twitter-client-tweet", arg, ev);}],
  91. ];
  92. /////////////////////////////////////////
  93. //nicovideo
  94. local["http://(www|tw|es|de|)\.nicovideo\.jp\/(watch|playlist)/*"] = [
  95. ["i", function (ev, arg) { ext.exec("nicoinfo", arg); }],
  96. ["p", function (ev, arg) { ext.exec("nicopause", arg); }],
  97. // ["o", function (ev, arg) { ext.exec("nicommentvisible", arg); }],
  98. ["m", function (ev, arg) { ext.exec("nicomute", arg); }],
  99. [".", function (ev, arg) { ext.exec("nicovolumeIncrement", arg); }],
  100. [",", function (ev, arg) { ext.exec("nicovolumeDecrement", arg); }],
  101. ['f', function (ev, arg) {
  102. curl = window.content.location.href;
  103. kurl = curl.replace(/nicovideo.jp/, "nicovideofire.jp");
  104. window.content.location.href = kurl;
  105. }
  106. ],
  107. ];
  108. /////////////////////////////////////////
  109. // tumblr/dashboard
  110. local["^http://www.tumblr.com/dashboard"] = [
  111. // ["C-<left>", function (ev, arg) {gBrowser.mTabContainer.advanceSelectedTab(-1, true); }],
  112. // ["C-<right>", function (ev, arg) {gBrowser.mTabContainer.advanceSelectedTab(1, true); }],
  113. ["<left>", function (ev, arg) { window.content.location.href = "http://www.tumblr.com/dashboard"; }],
  114. // ["<right>", null],
  115. ["J", function (ev, arg) {
  116. if (window.loadURI) {
  117. 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;}())");
  118. }
  119. }],
  120. ];
  121. ///////////////////////////////////////////
  122. // plugin option
  123. plugins.options["instapaper.close_after_post"] = true;
  124. plugins.options["instapaper.initial_comment_function"] = function(){
  125. var now = new Date();
  126. return "[" + now.toString() + "]";
  127. };
  128. //////////////////////////////////////////
  129. // yatc
  130. style.register("#keysnail-twitter-client-container{ display:none !important; }");
  131. plugins.options["twitter_client.popup_new_statuses"] = false;
  132. plugins.options["twitter_client.automatically_begin"] = false;
  133. plugins.options["twitter_client.automatically_begin_list"] = false;
  134. plugins.options["twitter_client.timeline_count_beginning"] = 0;
  135. plugins.options["twitter_client.timeline_count_every_updates"] = 0;
  136. plugins.options["twitter_client.tweet_keymap"] = {
  137. "C-RET" : "prompt-decide",
  138. "RET" : ""
  139. };
  140. plugins.options["twitter_client.jmp_id"] = "10sr";
  141. plugins.options["twitter_client.jmp_key"] = "R_c51f889a77cb4b4e993ed868f65083f5";
  142. plugins.options["twitter_client.use_jmp"] = true;
  143. ////////////////////////////////////////////
  144. // my ext
  145. ext.add("open-url-from-clipboard", function(){
  146. var list = command.getClipboardText().split("\n");
  147. for(var i = 0; i < list.length; i++){
  148. if(list[i] != ""){
  149. gBrowser.loadOneTab(list[i], null, null, null, false);
  150. }
  151. }
  152. }, "open tabs of newline separated url list from clipboard");
  153. ext.add("list-url", function(){
  154. var urls = [];
  155. var aa = window.content.document.getElementsByTagName("a");
  156. var text = "";
  157. var alt = "";
  158. for (var i = 0; i < aa.length ; i++) {
  159. if(aa[i].href == ""){ continue; }
  160. if (aa[i].text == "" && aa[i].hasChildNodes() && aa[i].childNodes[0].nodeType == Node.ELEMENT_NODE){
  161. alt = aa[i].childNodes[0].getAttribute("alt");
  162. text = " " + aa[i].childNodes[0].nodeName + (alt ? ": " + alt : "");
  163. }else{
  164. text = aa[i].text;
  165. }
  166. urls.push([text, decodeURIComponent(aa[i].href)]);
  167. }
  168. if(urls.length == 0){
  169. display.echoStatusBar("No url found.");
  170. return;
  171. }
  172. prompt.selector(
  173. {
  174. message : "Select URL",
  175. collection : urls,
  176. width : [35, 65],
  177. header : ["text", "url"],
  178. callback : function (i) {
  179. if (i >= 0)
  180. openUILinkIn(urls[i][1], "tab"); // or current tabshifted window
  181. }
  182. }
  183. );
  184. }, "list url");
  185. ext.add("bookmark-delicious", function(){
  186. f= 'http://www.delicious.com/save?url=' + encodeURIComponent(window.content.location.href) +
  187. '&title=' + encodeURIComponent(document.title) +
  188. '&notes=' + encodeURIComponent('' + (window.getSelection ?
  189. window.getSelection() : document.getSelection ?
  190. document.getSelection() : document.selection.createRange().text)) + '&v=6&';
  191. a = function(){
  192. if(! window.open(f + 'noui=1&jump=doclose', 'deliciousuiv6', 'location=1,links=0,scrollbars=0,toolbar=0,width=710,height=660')){
  193. location.href = f + 'jump=yes';
  194. }
  195. };
  196. if(/Firefox/.test(navigator.userAgent)){
  197. setTimeout(a,0);
  198. }else{
  199. a();
  200. }
  201. }, "bookmark delicious");
  202. ext.add('view-page-source', function(){
  203. window.content.location.href = "view-source:" + window.content.location.href;
  204. }, 'view page source');
  205. ext.add('my-setpref', function(){
  206. util.setPrefs(
  207. {
  208. "browser.bookmarks.max_backups":0,
  209. "browser.cache.memory.capacity":16384,
  210. "browser.download.manager.closeWhenDone":true,
  211. "browser.download.useDownloadDir":false,
  212. "browser.fullscreen.autohide":false,
  213. "browser.search.openintab":true,
  214. "browser.sessionhistory.max_total_viewers":8,
  215. "browser.sessionstore.restore_on_demand":true,
  216. "browser.tabs.closeWindowWithLastTab":false,
  217. "browser.tabs.loadDivertedInBackground": true,
  218. "browser.urlbar.autocomplete.enabled":false,
  219. "browser.urlbar.trimURLs":false,
  220. "dom.disable_window_open_feature.location": false,
  221. "dom.max_script_run_time": 30,
  222. "extensions.chaika.bbsmenu.open_new_tab":true,
  223. "extensions.chaika.bbsmenu.open_single_click":false,
  224. "extensions.chaika.board.open_new_tab":true,
  225. "extensions.chaika.board.open_single_click":false,
  226. "extensions.foxage2ch.openThreadInTab":true,
  227. "extensions.saveimageinfolder.general-duplicatefilenamevalue":1,
  228. "extensions.saveimageinfolder.general-fileprefixvalue":"%yyyy%%MM%%dd%-%hh%%mm%%ss%_",
  229. "extensions.saveimageinfolder.usecache":true,
  230. "extensions.tabutils.openTabNext":1,
  231. "extensions.tabutils.styles.current":"{\"bold\":true,\"italic\":false,\"underline\":true,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#000000\",\"bgColor\":false,\"bgColorCode\":\"#000000\",\"outline\":false,\"outlineColorCode\":\"#000000\"}",
  232. "extensions.tabutils.styles.unread":"{\"bold\":false,\"italic\":false,\"underline\":false,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#CC0000\",\"bgColor\":false,\"bgColorCode\":\"undefined\",\"outline\":false,\"outlineColorCode\":\"undefined\"}",
  233. "extensions.yass.edgetype":0,
  234. "extensions.yass.selectedpreset":"red",
  235. "font.default.x-western":"sans-serif",
  236. "general.warnOnAboutConfig":false,
  237. "keyword.URL":"http://www.bing.com/search?q=",
  238. "network.dns.disableIPv6":true,
  239. "refcontrol.actions":"@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  240. "scrapbook.tabs.open":true
  241. }
  242. );
  243. if(/^Linux/.test(navigator.platform)){
  244. util.setPrefs(
  245. {
  246. "browser.cache.disk.parent_directory":"/tmp",
  247. "browser.cache.disk.capacity":524288
  248. }
  249. );
  250. }
  251. display.showPopup("Keysnail", "My prefs done.");
  252. }, 'my setpref');
  253. ext.add('auto-install-plugins', function(ev, arg){
  254. var urls = [
  255. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  256. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  257. 'https://raw.github.com/mooz/keysnail/master/plugins/hok.ks.js',
  258. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  259. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  260. 'https://raw.github.com/tkosaka/keysnail-plugin/master/nicontroller.ks.js',
  261. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  262. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  263. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  264. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  265. 'https://raw.github.com/gist/1976942/firefox-addon-manager.ks.js',
  266. 'https://raw.github.com/gist/1450594/mstranslator.ks.js'
  267. ];
  268. function inst(a){
  269. if(a.length == 0){
  270. display.showPopup("auto-install-plugins", "All installation finished.");
  271. }else{
  272. var url = a.shift();
  273. var path = userscript.pluginDir + userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  274. if(plugins.context[path] === undefined){
  275. userscript.installPluginFromURL(url, function(){inst(a);});
  276. }else{
  277. inst(a);
  278. }
  279. }
  280. }
  281. inst(urls);
  282. }, 'Install plugins automatically if not installed yet.');
  283. ext.add('put-aside-this-page', function (ev, arg) {
  284. var n = gBrowser.mCurrentTab._tPos;
  285. gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);
  286. if (n != 0) {
  287. gBrowser.selectedTab = gBrowser.mTabs[n];
  288. }
  289. }, 'put aside this page');
  290. ext.add('send-escape', function (ev, arg) {
  291. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  292. }, 'escape');
  293. ext.add("open-hatebu-comment", function (ev, arg) {
  294. if (window.loadURI) {
  295. loadURI("javascript:location.href='http://b.hatena.ne.jp/entry?mode=more&url='+escape(location.href);");
  296. }
  297. }, 'hatebu');
  298. ext.add("fullscreen-page",function (ev) {
  299. getBrowser().selectedTab = getBrowser().addTab("http://home.tiscali.nl/annejan/swf/timeline.swf");
  300. BrowserFullScreen();
  301. }, "fullscreen page");
  302. ext.add("focus-on-content", function(){
  303. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  304. gBrowser.focus();
  305. content.focus();
  306. }, "forcus on content");
  307. ext.add("hide-sidebar", function(){
  308. var sidebarBox = document.getElementById("sidebar-box");
  309. if (!sidebarBox.hidden) {
  310. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  311. }
  312. }, "hide-sidebar");
  313. ext.add("close-and-next-tab", function (ev, arg) {
  314. var n = gBrowser.mCurrentTab._tPos;
  315. BrowserCloseTabOrWindow();
  316. gBrowser.selectedTab = gBrowser.mTabs[n];
  317. }, "close and focus to next tab");
  318. //////////////////////////////////////
  319. //
  320. ext.add("restart-firefox-add-menu", function(){
  321. const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  322. var cmdelm = document.createElementNS(XUL_NS, "command");
  323. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  324. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  325. var commandset = document.getElementById("mainCommandSet");
  326. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  327. commandset.appendChild(cmdelm);
  328. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  329. menuelm.setAttribute("label", "Restart Firefox");
  330. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  331. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  332. var menu = document.getElementById("menu_FilePopup");
  333. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  334. menu.appendChild(menuelm);
  335. }, "add restart firefox menu");
  336. //////////////////////////////////////
  337. // restart firefox
  338. // http://keysnail.g.hatena.ne.jp/Shinnya/20100723/1279878815
  339. ext.add("restart-firefox",function (ev) {
  340. const nsIAppStartup = Components.interfaces.nsIAppStartup;
  341. // Notify all windows that an application quit has been requested.
  342. var os = Components.classes["@mozilla.org/observer-service;1"]
  343. .getService(Components.interfaces.nsIObserverService);
  344. var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  345. .createInstance(Components.interfaces.nsISupportsPRBool);
  346. os.notifyObservers(cancelQuit, "quit-application-requested", null);
  347. // Something aborted the quit process.
  348. if (cancelQuit.data)
  349. return;
  350. // Notify all windows that an application quit has been granted.
  351. os.notifyObservers(null, "quit-application-granted", null);
  352. // Enumerate all windows and call shutdown handlers
  353. var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  354. .getService(Components.interfaces.nsIWindowMediator);
  355. var windows = wm.getEnumerator(null);
  356. while (windows.hasMoreElements()) {
  357. var win = windows.getNext();
  358. if (("tryToClose" in win) && !win.tryToClose())
  359. return;
  360. }
  361. Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
  362. .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
  363. }, "restart firefox");
  364. /////////////////////////////////////////
  365. // copy feed url
  366. ext.add("copy-url", function () {
  367. const doc = content.document;
  368. let feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  369. for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]',
  370. 'link[type="application/atom+xml"]'])))];
  371. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1");
  372. for (i = 0; i < feeds.length; i++)
  373. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  374. feeds.unshift([window.content.document.title,window.content.location.href]);
  375. prompt.selector(
  376. {
  377. message : "Select Feed",
  378. collection : feeds,
  379. callback : function (i) {
  380. if (i >= 0)
  381. command.setClipboardText(feeds[i][1]);
  382. }
  383. }
  384. );
  385. }, "Copy url or feed url of current page");
  386. ///////////////////////////////////////
  387. // keysnail z menu
  388. ext.add("keysnail-setting-dialog", function(){
  389. KeySnail.openPreference();
  390. }, "keysnail setting dialog");
  391. ext.add("keysnail-plugin-manager", function(){
  392. userscript.openPluginManager();
  393. }, "keysnail plugin manager");
  394. ext.add("firefox-open-addon-manager", function(){
  395. BrowserOpenAddonsMgr();
  396. }, "firefox addon manager");
  397. ext.add("keysnail-reload-init-file", function(){
  398. userscript.reload();
  399. }, "keysnail reload init file");
  400. ext.add("keysnail-z-menu",function(){
  401. var list = [["keysnail-setting-dialog"],
  402. ["keysnail-plugin-manager"],
  403. ["forefox-open-addon-manager"],
  404. ["keysnail-reload-init-file"],
  405. // ["check-for-plugins-update"],
  406. ["restart-firefox"]
  407. ];
  408. prompt.selector(
  409. {
  410. message : "open setting dialog",
  411. collection : list,
  412. callback : function (i) {
  413. ext.exec(list[i][0]);
  414. }
  415. });
  416. },"open keysnail z menu");
  417. ///////////////////////////////////
  418. // search web
  419. ext.add("query-then-engine", function () {
  420. prompt.reader({message : "Search Word?:",
  421. callback : function (q) {
  422. if (q) {
  423. prompt.selector({ message : "search \"" + q + "\" with?",
  424. collection : plugins.options["search-url-list"],
  425. width : [20,80],
  426. callback : function (i) {
  427. getBrowser().selectedTab = getBrowser().addTab(plugins.options["search-url-list"][i][1].replace("%r",q).replace("%q",encodeURIComponent(q)));
  428. },
  429. });
  430. };
  431. },
  432. initialInput : content.document.getSelection() || "",
  433. });
  434. }, "enter search word and then select engine");
  435. /////////////////////////////////////
  436. // closed tab list
  437. ext.add("list-closed-tabs", function () {
  438. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  439. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  440. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  441. var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  442. if (!closedTabs.length)
  443. return void display.echoStatusBar("No recently closed tab.", 2000);
  444. prompt.selector(
  445. {
  446. message : "select tab to undo:",
  447. collection : closedTabs,
  448. flags : [ICON | IGNORE, 0, 0],
  449. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  450. });
  451. }, "List closed tabs");
  452. // ext.add("echo-closed-tabs", function () {
  453. // var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
  454. // var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  455. // // var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))];
  456. // var lasttab = json.decode(ss.getClosedTabData(window))[0];
  457. // dump = ""
  458. // for (var i in lasttab) { dump += lasttab[i] + "\n"; }
  459. // confirm(dump);
  460. // }, "List closed tabs");
  461. ///////////////////////////////
  462. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  463. ext.add("list-tab-history", function () {
  464. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  465. var tabHistory = [];
  466. var sessionHistory = gBrowser.webNavigation.sessionHistory;
  467. if (sessionHistory.count < 1)
  468. return void display.echoStatusBar("Tab history not exist", 2000);
  469. var curIdx = sessionHistory.index;
  470. for (var i = 0; i < sessionHistory.count; i++) {
  471. var entry = sessionHistory.getEntryAtIndex(i, false);
  472. if (!entry)
  473. continue;
  474. try {
  475. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  476. .getService(Ci.nsIFaviconService)
  477. .getFaviconForPage(entry.URI).spec;
  478. } catch (ex) {}
  479. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  480. }
  481. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  482. if (tabHistory[thIdx][3] == curIdx) break;
  483. }
  484. prompt.selector(
  485. {
  486. message : "select history in tab",
  487. collection : tabHistory,
  488. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  489. header : ["Title", "URL"],
  490. initialIndex : thIdx,
  491. callback : function(i) { if (i >= 0) gBrowser.webNavigation.gotoIndex(tabHistory[i][3]); }
  492. });
  493. }, 'List tab history');
  494. //}}%PRESERVE%
  495. // ========================================================================= //
  496. // ========================= Special key settings ========================== //
  497. key.quitKey = "ESC";
  498. key.helpKey = "<f1>";
  499. key.escapeKey = "C-q";
  500. key.macroStartKey = "";
  501. key.macroEndKey = "";
  502. key.universalArgumentKey = "C-u";
  503. key.negativeArgument1Key = "C--";
  504. key.negativeArgument2Key = "C-M--";
  505. key.negativeArgument3Key = "M--";
  506. key.suspendKey = "Not defined";
  507. // ================================= Hooks ================================= //
  508. hook.setHook('KeySnailInitialized', function () {
  509. ext.exec("shiitake-enable-style");
  510. });
  511. hook.setHook('KeyBoardQuit', function (aEvent) {
  512. ext.exec("hide-sidebar");
  513. let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  514. gBrowser.focus();
  515. content.focus();
  516. command.closeFindBar();
  517. if (util.isCaretEnabled()) {
  518. command.resetMark(aEvent);
  519. } else {
  520. goDoCommand("cmd_selectNone");
  521. }
  522. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  523. });
  524. hook.setHook('Unload', function () {
  525. util.getBrowserWindows().some(function (win) {
  526. if (win === window) {
  527. return false;
  528. }
  529. const ks = win.KeySnail;
  530. share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate);
  531. ks.setUpPluginUpdaterDelegator();
  532. return true;
  533. });
  534. });
  535. // ============================= Key bindings ============================== //
  536. key.setGlobalKey('C-<right>', function () {
  537. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  538. }, 'ひとつ右のタブへ');
  539. key.setGlobalKey('C-<left>', function () {
  540. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  541. }, 'ひとつ左のタブへ');
  542. key.setGlobalKey('C-<up>', function () {
  543. var browser = getBrowser();
  544. if (browser.mCurrentTab.previousSibling) {
  545. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  546. } else {
  547. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  548. }
  549. }, '選択中のタブを右へ');
  550. key.setGlobalKey('C-<down>', function () {
  551. var browser = getBrowser();
  552. if (browser.mCurrentTab.nextSibling) {
  553. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  554. } else {
  555. browser.moveTabTo(browser.mCurrentTab, 0);
  556. }
  557. }, '選択中のタブを左へ');
  558. key.setGlobalKey('C-h', function (ev, arg) {
  559. return;
  560. }, 'ignore');
  561. key.setGlobalKey('<delete>', function (ev, arg) {
  562. let (elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  563. gBrowser.focus();
  564. content.focus();
  565. }, 'コンテンツへフォーカス', true);
  566. key.setGlobalKey('C-p', function (ev, arg) {
  567. return !document.getElementById("keysnail-prompt").hidden &&
  568. document.getElementById("keysnail-prompt-textbox").focus();
  569. }, 'KeySnail のプロンプトへフォーカス', true);
  570. key.setViewKey('J', function (ev) {
  571. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  572. }, 'ひとつ右のタブへ');
  573. key.setViewKey('K', function (ev) {
  574. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  575. }, 'ひとつ左のタブへ');
  576. key.setViewKey('o', function (ev, arg) {
  577. ext.exec("hok-start-foreground-mode", arg, ev);
  578. }, 'Start Hit a Hint foreground mode', true);
  579. key.setViewKey('c', function (ev) {
  580. command.interpreter();
  581. }, 'JavaScript のコードを評価');
  582. key.setViewKey('D', function (ev, arg) {
  583. ext.exec("dig-url", arg, ev);
  584. }, 'dig url with selector', true);
  585. key.setViewKey('x', function (aEvent, aArg) {
  586. ext.select(aArg, aEvent);
  587. }, 'エクステ一覧');
  588. key.setViewKey(['t', 'm'], function (ev, arg) {
  589. if (window.loadURI) {
  590. loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;");
  591. }
  592. }, 'open with tweetmeme');
  593. key.setViewKey(['t', 'w'], function (ev, arg) {
  594. ext.exec("twitter-client-tweet", arg, ev);
  595. }, 'つぶやく', true);
  596. key.setViewKey(['t', 'p'], function (ev, arg) {
  597. ext.exec("twitter-client-tweet-this-page", arg, ev);
  598. }, 'このページのタイトルと URL を使ってつぶやく', true);
  599. key.setViewKey([['u'], ['<left>']], function (ev) {
  600. goDoCommand("cmd_scrollPageUp");
  601. }, '一画面分スクロールアップ');
  602. key.setViewKey('g', function () {
  603. goDoCommand("cmd_scrollTop");
  604. }, 'ページ先頭へ移動');
  605. key.setViewKey('G', function () {
  606. goDoCommand("cmd_scrollBottom");
  607. }, 'ページ末尾へ移動');
  608. key.setViewKey('r', function (aEvent) {
  609. BrowserReload();
  610. }, '再読み込み');
  611. key.setViewKey('m', function (ev, arg) {
  612. _fi.toogle();
  613. }, 'fetchimiをトグル');
  614. key.setViewKey('p', function (ev, arg) {
  615. if (window.loadURI) {
  616. loadURI("javascript:var%20b=document.body;var%20POSTEROUS___bookmarklet_domain='http://posterous.com';var%20d=new%20Date();var%20e=(new%20Date(d.getFullYear(),d.getMonth(),d.getDate())).getTime();if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.type='text/javascript');void(z.src='http://posterous.com/javascripts/bookmarklet2.js?'+e);void(b.appendChild(z));}else{}");
  617. }
  618. }, 'posterousに投稿');
  619. key.setViewKey('SPC', function (ev, arg) {
  620. MultipleTabService.toggleSelection(gBrowser.mCurrentTab);
  621. gBrowser.mTabContainer.advanceSelectedTab(1, true);
  622. }, 'タブの選択をトグルして次のタブ');
  623. key.setViewKey('S-SPC', function (ev, arg) {
  624. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  625. gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  626. }, 'タブの選択をトグルして前のタブ');
  627. key.setViewKey('z', function (ev, arg) {
  628. ext.exec("keysnail-z-menu", arg, ev);
  629. }, 'open keysnail setting menu', true);
  630. key.setViewKey('C-SPC', function (ev, arg) {
  631. MultipleTabService.toggleSelection(gBrowser.selectedTab);
  632. }, 'タブの選択をトグル');
  633. key.setViewKey('e', function () {
  634. command.focusElement(command.elementsRetrieverTextarea, 0);
  635. }, '最初のインプットエリアへフォーカス', true);
  636. key.setViewKey('S', function (ev, arg) {
  637. if (window.loadURI) {
  638. 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{}");
  639. }
  640. }, 'google reader share');
  641. key.setViewKey('!', function (ev, arg) {
  642. shell.input();
  643. }, 'Command system');
  644. key.setViewKey('R', function () {
  645. BrowserReloadSkipCache();
  646. }, '更新(キャッシュを無視)');
  647. key.setViewKey('<backspace>', function () {
  648. BrowserBack();
  649. }, '戻る');
  650. key.setViewKey('S-<backspace>', function () {
  651. BrowserForward();
  652. }, '進む');
  653. key.setViewKey('q', function (ev, arg) {
  654. ext.exec("query-then-engine", arg, ev);
  655. }, 'enter search word and then select engine', true);
  656. key.setViewKey('/', function () {
  657. command.iSearchForward();
  658. }, 'インクリメンタル検索', true);
  659. key.setViewKey('?', function (ev) {
  660. command.iSearchForwardKs(ev);
  661. }, 'Emacs ライクなインクリメンタル検索', true);
  662. key.setViewKey('a', function (ev, arg) {
  663. allTabs.open();
  664. }, 'alltabs.open');
  665. key.setViewKey([['<right>'], ['d']], function (ev) {
  666. goDoCommand("cmd_scrollPageDown");
  667. }, '一画面スクロールダウン');
  668. key.setViewKey([['<prior>'], ['<next>']], function (ev, arg) {
  669. return;
  670. }, 'ignore');
  671. key.setViewKey(':', function (ev, arg) {
  672. return !document.getElementById("keysnail-prompt").hidden &&
  673. document.getElementById("keysnail-prompt-textbox").focus();
  674. }, 'KeySnail のプロンプトへフォーカス', true);
  675. key.setViewKey('H', function (ev) {
  676. var browser = getBrowser();
  677. if (browser.mCurrentTab.previousSibling) {
  678. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  679. } else {
  680. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  681. }
  682. }, '選択中のタブを左へ');
  683. key.setViewKey('0', function (ev) {
  684. BrowserCloseTabOrWindow();
  685. }, 'タブ / ウィンドウを閉じる');
  686. key.setViewKey('C', function (ev, arg) {
  687. ext.exec("linksnail", arg, ev);
  688. }, 'LinkSnail', true);
  689. key.setViewKey('C-<backspace>', function (ev, arg) {
  690. ext.exec("list-tab-history", arg, ev);
  691. }, 'List tab history', true);
  692. key.setViewKey('I', function (ev, arg) {
  693. ext.exec("instapaper-post-page-with-comment", arg, ev);
  694. }, 'post page and comment', true);
  695. key.setViewKey('T', function (ev, arg) {
  696. ext.exec("mstranslator-open-prompt", arg, ev);
  697. }, 'MSTranslator - Open prompt', true);
  698. key.setViewKey('j', function (ev) {
  699. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  700. }, '一行スクロールダウン');
  701. key.setViewKey('k', function (ev) {
  702. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  703. }, '一行スクロールアップ');
  704. key.setViewKey('l', function (ev) {
  705. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  706. }, '右へスクロール');
  707. key.setViewKey('h', function (ev) {
  708. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  709. }, '左へスクロール');
  710. key.setViewKey('L', function (ev) {
  711. var browser = getBrowser();
  712. if (browser.mCurrentTab.nextSibling) {
  713. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  714. } else {
  715. browser.moveTabTo(browser.mCurrentTab, 0);
  716. }
  717. }, '選択中のタブを右へ');
  718. key.setViewKey('U', function (ev) {
  719. undoCloseTab();
  720. }, '閉じたタブを元に戻す');
  721. key.setEditKey('C-<tab>', function (ev) {
  722. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  723. }, '次のテキストエリアへフォーカス');