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

.keysnail.js 30 KiB

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