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.
 
 
 
 
 
 

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