Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

_keysnail.js 31 KiB

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