You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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