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.
 
 
 
 
 
 

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