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 45 KiB

il y a 13 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 13 ans
il y a 11 ans
il y a 13 ans
il y a 11 ans
il y a 11 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 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 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 11 ans
il y a 13 ans
il y a 9 ans
il y a 9 ans
il y a 9 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 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 11 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 12 ans
il y a 12 ans
il y a 12 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 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 12 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 13 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 12 ans
il y a 11 ans
il y a 11 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 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 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 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 12 ans
il y a 13 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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. // Original is at https://gist.github.com/Griever/62715
  13. ext.add("open-bookmarks-in-new-tab", function(){
  14. // this makes all clicks open in new tab.
  15. // return;
  16. // test if firefox 12
  17. if (12 > parseFloat(Cc['@mozilla.org/xre/app-info;1'].
  18. getService(Ci.nsIXULAppInfo).version)) {
  19. return;
  20. }
  21. // I cannot fully understand what happen but keysnail emit error
  22. // *after* initialization of firefox finished successfully and I assured
  23. // that new tabs open as I expect when clicking bookmarks, for example,
  24. // when I try to tweet using the twitter keysnail plugin, with error
  25. // message saying "whereToOpenLink is undefined.".
  26. // if no modifier key pressed open in new tab.
  27. try {
  28. var whereToOpenLink_org = new String(window.whereToOpenLink.toString());
  29. window.whereToOpenLink = eval(
  30. "(" +
  31. whereToOpenLink_org.replace(
  32. '{',
  33. '{ if(!e || ' +
  34. '(!e.ctrlKey && !e.shiftKey && !e.metaKey && ' +
  35. '!(e.altKKey && !ignoreAlt))) ' +
  36. 'return "tab";'
  37. ) +
  38. ")"
  39. );
  40. } catch (e if e instanceof TypeError) {
  41. return;
  42. }
  43. // This is useless because this makes reload open new tab.
  44. // window.whereToOpenLink = function(e, ib, ia){ return "tab"; };
  45. }, "open in new tab");
  46. // ext.exec("open-bookmarks-in-new-tab");
  47. //////////////////////////////////////
  48. //// sitelocalkeymap
  49. var local = {};
  50. plugins.options["site_local_keymap.local_keymap"] = local;
  51. function fake(k, i) function(){ key.feed(k, i); };
  52. function pass(k, i) [k, fake(k, i)];
  53. function ignore(k, i) [k, null];
  54. // ext.add("ext-name", function () {}, "ext description");
  55. // style.register("");
  56. // local["^http://"] = [['a', function(ev, arg){}],];
  57. ///////////////////////////////////////////
  58. //// firefox
  59. // style.register("#bookmarksPanel > hbox,#history-panel > hbox {" +
  60. // "display: none !important;}" +
  61. // " //#urlbar-container{max-width: 500px !important;}");
  62. // style.register( //not work
  63. // <><![CDATA[
  64. // input,textarea {
  65. // font-family: monospace !important;
  66. // }
  67. // ]]></>.toString()
  68. // );
  69. style.register(
  70. '@-moz-document ' +
  71. 'url-prefix(\"http://www.tumblr.com/\"), ' +
  72. 'url-prefix(\"https://www.tumblr.com/\") ' +
  73. '{ #pagination {' +
  74. 'position: fixed;' +
  75. 'bottom: 50px;' +
  76. 'right: 100px;' +
  77. 'padding-right: 0px !important' +
  78. '} }' , style.XHTML);
  79. ///////////////////////////////////
  80. //search engine
  81. plugins.options["search-url-list"] = [
  82. ["DuckDuckGo", "https://duckduckgo.com/?q=%q"],
  83. ["Bing", "http://bing.com/search?q=%q"],
  84. ["Google", "http://google.com/search?q=%q"],
  85. ["Yahoo Realtime",
  86. "http://realtime.search.yahoo.co.jp/search?rkf=1&ei=UTF-8&p=%q"],
  87. ["Twitter Search", "http://twitter.com/search?q=%q&lang=all"],
  88. ["Tospy", "http://topsy.com/s?allow_lang=ja&q=%q"],
  89. ["2ch syoboi.jp", "http://ff2ch.syoboi.jp/?q=%q"],
  90. ["2ch-ranking","http://2ch-ranking.net/search.php?q=%q&imp=and&order=time"],
  91. //["2ch ttsearch", "http://ttsearch.net/s2.cgi?k=%q&o=r"],
  92. ["I\'m feelig lucky!", "http://www.google.co.jp/search?q=%q&btnI=kudos"],
  93. ["Uncyclopedia", "http://ja.uncyclopedia.info/wiki/%q"],
  94. ["Wikipedia", "http://ja.wikipedia.org/wiki/%q"],
  95. ["nicovideo.jp", "http://www.nicovideo.jp/search/%q"],
  96. ["alc", "http://eow.alc.co.jp/%q/UTF-8/"],
  97. ["google map",
  98. "http://maps.google.co.jp/maps?hl=ja&q=%q&um=1&ie=UTF-8&sa=N&tab=wl"],
  99. ["Weblio", "http://www.weblio.jp/content_find?query=%q"],
  100. ["ShoutCast", "http://www.shoutcast.com/Internet-Radio/%q"],
  101. ["Delicious 10sr", "http://delicious.com/10sr/%q"],
  102. ["Open raw", "%r"]
  103. ];
  104. plugins.options["my-keysnail-bookmarks"] = [
  105. "twitter.com"
  106. ];
  107. // sitelocal keymap
  108. //////////////////////////////////////////
  109. // 2ch chaika
  110. // change chaika port every time firefox starts
  111. util.setIntPref("extensions.chaika.server_port.firefox",
  112. 8800 + Math.floor(Math.random() * 30));
  113. local["^http://127.0.0.1:88"] = [
  114. ['k', function(ev, arg){
  115. curl = window.content.location.href;
  116. kurl = curl.replace(/http:.*thread\/(.*\/).*/, "chaika://post/$1");
  117. window.content.location.href = kurl;
  118. }
  119. ]
  120. ];
  121. local["^http://w2.p2.2ch.net/p2/read.php"] = [
  122. ['k', function(ev, arg){
  123. var url = window.content.location.href;
  124. var pt = /host=(.*?)&bbs=(.*?)&key=(.*?)&ls=/ ;
  125. var result = url.match(pt);
  126. var k = format("chaika://post/http://%s/test/read.cgi/%s/%s/",
  127. result[1], result[2], result[3]);
  128. window.content.location.href = k;
  129. }
  130. ]
  131. ];
  132. /////////////////////////////////////////
  133. // feedly
  134. local["^https?://(www\.|cloud\.|)feedly\.com/"] = [
  135. ['d', null],
  136. ['j', null],
  137. ['k', null],
  138. ['n', null],
  139. ['p', null],
  140. ['o', null],
  141. ['b', null],
  142. ['S', null],
  143. ['s', null],
  144. ['?', null],
  145. ['r', null],
  146. ['g', null],
  147. // ['x', function(ev, arg){
  148. // ev.target.dispatchEvent(key.stringToKeyEvent("g", true));
  149. // }],
  150. // ['l', function(ev, arg){
  151. // var host = window.content.location.host;
  152. // if (host === "cloud.feedly.com" || host === "feedly.com") {
  153. // window.content.location.href = "http://" + host + "/#latest";
  154. // } else if (host === "www.feedly.com") {
  155. // window.content.location.href = "http://" + host + "/home#latest";
  156. // }
  157. // }],
  158. ['a', null],
  159. [['t', 'p'], function(ev, arg){
  160. ev.target.dispatchEvent(key.stringToKeyEvent("t", true));
  161. }],
  162. [['t', 'w'], function(ev, arg){
  163. ext.exec("twitter-client-tweet", arg, ev);
  164. }]
  165. ];
  166. /////////////////////////////////////////
  167. //nicovideo
  168. // http://dic.nicovideo.jp/id/4858151
  169. local["^http://(www|tw|es|de|)\.nicovideo\.jp\/(watch|playlist)"] = [
  170. // ["i", function(ev, arg){ ext.exec("nicoinfo", arg); }],
  171. ["SPC", function(ev, arg){ ext.exec("nicopause", arg); }],
  172. ["f", function(ev, arg){ ext.exec("nicosize", arg); }],
  173. ["F", function(ev, arg){ ext.exec("nicosize", arg); }],
  174. // ["o", function(ev, arg){ ext.exec("nicommentvisible", arg); }],
  175. // ["m", function(ev, arg){ ext.exec("nicomute", arg); }],
  176. // [".", function(ev, arg){ ext.exec("nicovolumeIncrement", arg); }],
  177. // [",", function(ev, arg){ ext.exec("nicovolumeDecrement", arg); }],
  178. // ['f', function(ev, arg){
  179. // curl = window.content.location.href;
  180. // kurl = curl.replace(/nicovideo.jp/, "nicovideofire.jp");
  181. // window.content.location.href = kurl;
  182. // }]
  183. ];
  184. /////////////////////////////////////////
  185. // tumblr/dashboard
  186. local["^http://www.tumblr.com/dashboard"] = [
  187. // ["C-<left>", function(ev, arg){
  188. // gBrowser.mTabContainer.advanceSelectedTab(-1, true);
  189. // }],
  190. // ["C-<right>", function(ev, arg){
  191. // gBrowser.mTabContainer.advanceSelectedTab(1, true);
  192. // }],
  193. ["<left>", function(ev, arg){
  194. window.content.location.href = "http://www.tumblr.com/dashboard";
  195. }],
  196. ["<right>", null],
  197. ["J", function(ev, arg){
  198. if (window.loadURI) {
  199. 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;}())");
  200. }
  201. }]
  202. ];
  203. ///////////////////////////////////////////
  204. // plugin option
  205. plugins.options["builtin_commands_ext.ext_list"] = [
  206. "focus-to-prompt",
  207. "open-url-from-clipboard",
  208. "restart-firefox"
  209. ];
  210. plugins.options["instapaper.close_after_post"] = true;
  211. plugins.options["instapaper.initial_comment_function"] = function(){
  212. var now = new Date();
  213. return "[" + now.toString() + "]";
  214. };
  215. //////////////////////////////////////////
  216. // yatc
  217. style.register("#keysnail-twitter-client-container{ display:none !important; }");
  218. plugins.options["twitter_client.popup_new_statuses"] = false;
  219. plugins.options["twitter_client.automatically_begin"] = false;
  220. plugins.options["twitter_client.automatically_begin_list"] = false;
  221. plugins.options["twitter_client.timeline_count_beginning"] = 0;
  222. plugins.options["twitter_client.timeline_count_every_updates"] = 0;
  223. plugins.options["twitter_client.tweet_keymap"] = {
  224. "C-RET" : "prompt-decide",
  225. "RET" : ""
  226. };
  227. plugins.options["twitter_client.jmp_id"] = "10sr";
  228. plugins.options["twitter_client.jmp_key"] =
  229. "R_c51f889a77cb4b4e993ed868f65083f5";
  230. plugins.options["twitter_client.use_jmp"] = true;
  231. ////////////////////////////////////////////
  232. // my exts and functions
  233. var autoSaveTabList = (function(){
  234. const PREF_PREFIX = "extensions.keysnail.plugins.autosavetablist.";
  235. const PREF_DSTDIR = "dstdir";
  236. const PREF_ENABLED = "enabled";
  237. // use plugin option to set
  238. // in sec
  239. var default_timer_interval = 60 * 5;
  240. // "/" for unix system
  241. const DIR_DELIM = userscript.directoryDelimitter;
  242. var __timer = null;
  243. var __last_tab_list = null;
  244. function selectDirectory(title){
  245. // open dialog and return nsILocalFile object
  246. // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsILocalFile
  247. // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFilePicker
  248. // this function blocks.
  249. var nsIFilePicker = Components.interfaces.nsIFilePicker;
  250. var fp = Components.classes["@mozilla.org/filepicker;1"].
  251. createInstance(nsIFilePicker);
  252. fp.init(window, title, nsIFilePicker.modeGetFolder);
  253. // block
  254. var res = fp.show();
  255. if (res !== nsIFilePicker.returnOK) {
  256. return null;
  257. }
  258. return fp.file;
  259. }
  260. function selectFile(title){
  261. // open dialog and return nsILocalFile object
  262. // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsILocalFile
  263. // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFilePicker
  264. // this function blocks.
  265. var nsIFilePicker = Components.interfaces.nsIFilePicker;
  266. var fp = Components.classes["@mozilla.org/filepicker;1"].
  267. createInstance(nsIFilePicker);
  268. fp.init(window, title, nsIFilePicker.modeOpen);
  269. // block
  270. var res = fp.show();
  271. if (res !== nsIFilePicker.returnOK) {
  272. return null;
  273. }
  274. return fp.file;
  275. }
  276. function setup(){
  277. // set destination directory
  278. var dstdir = selectDirectory("Select Directory to Save Tab List");
  279. if (! dstdir) { return; }
  280. if (! dstdir.isWritable()) {
  281. display.notify("Directory is not writable");
  282. return;
  283. }
  284. util.setUnicharPref(PREF_PREFIX + PREF_DSTDIR, dstdir.path);
  285. }
  286. function genFileName(){
  287. function formatCurrent(){
  288. var d = new Date();
  289. function pad(n){
  290. return n < 10 ? '0' + n.toString() : n.toString()
  291. }
  292. return [
  293. d.getFullYear().toString(),
  294. pad(d.getMonth() + 1),
  295. pad(d.getDate()),
  296. "-",
  297. pad(d.getHours()),
  298. pad(d.getMinutes()),
  299. pad(d.getSeconds())
  300. ].join("");
  301. }
  302. return "tablist." + formatCurrent() + ".lst";
  303. }
  304. function getTabList(){
  305. // returns list of urls of current tabs.
  306. return [(function(){
  307. var browser = tab.linkedBrowser;
  308. var win = browser.contentWindow;
  309. // var title = tab.label;
  310. var url = win.location.href;
  311. return url;
  312. })() for each (tab in Array.slice(gBrowser.mTabContainer.childNodes))];
  313. // Array.slice is required?
  314. }
  315. function saveCurrentList(){
  316. var dstdir = util.getUnicharPref(PREF_PREFIX + PREF_DSTDIR);
  317. if (! dstdir) {
  318. display.showPopup("AutoSaveTabList",
  319. "Dest dir is not set yet. Run astl-setup first");
  320. return;
  321. }
  322. var filename = genFileName();
  323. var tab_list = getTabList().join("\n") + "\n"
  324. if (tab_list !== __last_tab_list) {
  325. util.writeTextFile(
  326. tab_list,
  327. dstdir + userscript.directoryDelimiter + filename
  328. );
  329. display.showPopup("AutoSaveTabList",
  330. "Tab List saved: " + filename);
  331. __last_tab_list = tab_list;
  332. }
  333. }
  334. function openFromFile(){
  335. var file = selectFile();
  336. if (file) {
  337. openFromLFSplittedString(util.readTextFile(file.path));
  338. }
  339. }
  340. function openFromClipboard(){
  341. openFromLFSplittedString(command.getClipboardText());
  342. }
  343. function openFromLFSplittedString(str){
  344. var urls = str.split("\n");
  345. for (var i = 0; i < urls.length; i++) {
  346. if (urls[i].match(/^http/)) {
  347. window.openUILinkIn(urls[i], "tab");
  348. }
  349. }
  350. }
  351. function enableTimer(ev, sec){
  352. disableTimer();
  353. sec = sec || default_timer_interval;
  354. __timer = window.setInterval(saveCurrentList, sec * 1000);
  355. display.showPopup("AutoSaveTabList",
  356. "Auto save enabled for every " + sec.toString() + " sec");
  357. }
  358. function disableTimer(){
  359. if (__timer) {
  360. window.clearInterval(__timer);
  361. __timer = null;
  362. display.showPopup("AutoSaveTabList",
  363. "Auto save disabled");
  364. } else {
  365. display.showPopup("AutoSaveTabList",
  366. "Auto save timer is not set yet !");
  367. }
  368. }
  369. function isEnabled(){
  370. return util.getBoolPref(PREF_PREFIX + PREF_ENABLED, false);
  371. }
  372. function enable(){
  373. util.setBoolPref(PREF_PREFIX + PREF_ENABLED, true);
  374. enableTimer();
  375. }
  376. function disable(){
  377. util.setBoolPref(PREF_PREFIX + PREF_ENABLED, false);
  378. disableTimer();
  379. }
  380. function init(){
  381. // Intended to be called on startup
  382. if (isEnabled()) {
  383. enableTimer();
  384. } else {
  385. disableTimer();
  386. }
  387. }
  388. return {
  389. selectDirectory: selectDirectory,
  390. setup: setup,
  391. getTabList: getTabList,
  392. saveCurrentList: saveCurrentList,
  393. openFromClipboard: openFromClipboard,
  394. openFromFile: openFromFile,
  395. enableTimer: enableTimer,
  396. disableTimer: disableTimer,
  397. isEnabled: isEnabled,
  398. enable: enable,
  399. disable: disable,
  400. init: init
  401. };
  402. })();
  403. ext.add("astl-setup", autoSaveTabList.setup, "Auto save tab list - Setup");
  404. ext.add("astl-open-from-clipboard", autoSaveTabList.openFromClipboard, "Auto save tab list - Open tabs from clipboard");
  405. ext.add("astl-open-from-file", autoSaveTabList.openFromFile, "Auto save tab list - Open tabs from local file");
  406. ext.add("astl-save-current", autoSaveTabList.saveCurrentList,
  407. "Auto save tab list - Save current list");
  408. //ext.add("astl-enable-timer", autoSaveTabList.enableTimer, "Auto save tab list - Enable periodic timer");
  409. //ext.add("astl-disable-timer", autoSaveTabList.disableTimer, "Auto save tab list - Disable periodic timer");
  410. ext.add("astl-enable", autoSaveTabList.enable, "Auto save tab list - Enable");
  411. ext.add("astl-disable", autoSaveTabList.disable, "Auto save tab list - Disable");
  412. ext.add("astl-init", autoSaveTabList.init, "Auto save tab list - Initalize");
  413. if (autoSaveTabList.isEnabled()) {
  414. //ext.exec("astl-init");
  415. // I cannot understand AT ALL but calling init() breaks something only my one
  416. // environment: Firefox on Windows7
  417. autoSaveTabList.init();
  418. }
  419. var echoTabInfo = (function(){
  420. var currenttab;
  421. function _display(msg){
  422. display.prettyPrint(msg, {
  423. timeout: 1500,
  424. style: {
  425. "font-size": "18px",
  426. "font-family": "monospace"
  427. }
  428. });
  429. }
  430. function __display(msg){
  431. display.echoStatusBar(msg);
  432. }
  433. function echo(){
  434. var newtab = getBrowser().mCurrentTab;
  435. if (currenttab === newtab) {
  436. return;
  437. }
  438. currenttab = newtab;
  439. var len = getBrowser().tabs.length;
  440. var idx = currenttab._tPos;
  441. var title = window.content.document.title;
  442. var url = window.content.location.href;
  443. var doc = content ? content.document : document;
  444. var dBody = doc.body;
  445. if (dBody && !util.isFrameSetWindow(content)) {
  446. // if page has been prepared
  447. _display(
  448. "[" +
  449. (idx + 1).toString() + "/" +
  450. len.toString() + "] " +
  451. title + " <" +
  452. decodeURIComponent(url) + ">"
  453. );
  454. }
  455. }
  456. return {
  457. echo: echo
  458. };
  459. })();
  460. ext.add("open-remote-init-file", function(ev, arg){
  461. const URL = "https://raw.github.com/10sr/dotfiles/master/_keysnail.js";
  462. window.openUILinkIn(URL, "tab");
  463. }, "Open remote initialization file");
  464. var updateInitFile = (function(){
  465. const URL = "https://raw.github.com/10sr/dotfiles/master/_keysnail.js";
  466. // content/modules/userscript.js
  467. // copy file from aFile
  468. function placeFile(aFile, force) {
  469. var dstdir = util.getUnicharPref("extensions.keysnail.userscript.location");
  470. if (dstdir === "") {
  471. throw util.getLocaleString("failedToInstallFile", [aFile.leafName]) + " :: " + x;
  472. }
  473. try
  474. {
  475. // calc dir from path
  476. let destinationDir = util.openFile(dstdir);
  477. let destinationFile = util.openFile(dstdir);
  478. destinationFile.append(aFile.leafName);
  479. if (destinationFile.exists())
  480. {
  481. if (util.hashFile(aFile) === util.hashFile(destinationFile))
  482. {
  483. // no need to install this file
  484. return destinationFile;
  485. }
  486. let confirmed = force ||
  487. util.confirm(
  488. util.getLocaleString("overWriteConfirmationTitle"),
  489. util.getLocaleString("overWriteConfirmation",
  490. [destinationFile.path])
  491. );
  492. if (!confirmed) {
  493. throw util.getLocaleString("canceledByUser");
  494. }
  495. }
  496. aFile.moveTo(destinationDir, "");
  497. return destinationFile;
  498. }
  499. catch (x)
  500. {
  501. throw util.getLocaleString("failedToInstallFile",
  502. [aFile.leafName]) +
  503. " :: " + x;
  504. }
  505. }
  506. function updateFile() {
  507. util.httpGet(URL, false, function (req) {
  508. if (req.status !== 200) {
  509. util.message(req.responseText);
  510. }
  511. try {
  512. let name = util.getLeafNameFromURL(URL);
  513. let file = userscript.writeTextTmp(name, req.responseText);
  514. let installed = placeFile(file);
  515. util.message(installed.path + " installed");
  516. display.showPopup("update-init-file",
  517. installed.path + " installed")
  518. } catch (x) {
  519. util.message(
  520. "An error occured while installing required scripts :: " +
  521. x.message
  522. );
  523. display.showPopup(
  524. "update-init-file",
  525. "An error occured while installing required scripts :: " +
  526. x.message
  527. );
  528. }
  529. });
  530. }
  531. return {
  532. updateFile: updateFile
  533. };
  534. })();
  535. ext.add("update-init-file", updateInitFile.updateFile, "update init file");
  536. var importExportBookmarks = (function(){
  537. function getOrganizer(){
  538. // [How to call for Firefox bookmark dialog? - Stack Overflow]
  539. // (http://stackoverflow.com/questions/9158187/how-to-call-for-firefox-bookmark-dialog)
  540. Components.utils.import("resource://gre/modules/Services.jsm");
  541. var organizer = Services.wm.getMostRecentWindow("Places:Organizer");
  542. if (!organizer) {
  543. // No currently open places window,
  544. // so open one with the specified mode.
  545. openDialog("chrome://browser/content/places/places.xul",
  546. "",
  547. "chrome,toolbar=yes,dialog=no,resizable",
  548. "AllBookmarks");
  549. return null;
  550. } else {
  551. return organizer;
  552. }
  553. }
  554. ext.add("export-bookmarks", function(ev, arg){
  555. var organizer = getOrganizer();
  556. if (organizer) {
  557. organizer.PlacesOrganizer.exportBookmarks();
  558. }
  559. }, "export bookmarks");
  560. ext.add("import-bookmarks", function(ev, arg){
  561. var organizer = getOrganizer();
  562. if (organizer) {
  563. organizer.PlacesOrganizer.importBookmarks();
  564. }
  565. }, "import bookmarks");
  566. return {
  567. getOrganizer: getOrganizer
  568. };
  569. })();
  570. ext.add("my-index-html", function(ev, arg){
  571. homepath = util.getEnv("HOME");
  572. file = ".index.html";
  573. if (homepath) {
  574. path = "file://" + homepath + "/" + file;
  575. window.openUILinkIn(path, "tab");
  576. }
  577. }, "open my index.html");
  578. ext.add("strong-fullscreen", function(){
  579. var elemids = [
  580. "navigator-toolbox"
  581. ];
  582. BrowserFullScreen();
  583. var isfullscreen = window.fullScreen;
  584. for(var i = 0; i < elemids.length; i++){
  585. var elem = document.getElementById(elemids[i]);
  586. if(elem){
  587. if(isfullscreen){
  588. elem.style.display = "none";
  589. }else{
  590. elem.style.display = null;
  591. }
  592. }
  593. }
  594. var tabs = document.getElementById("verticaltabs-box");
  595. if(tabs){
  596. var pref_key = "extensions.verticaltabs.width";
  597. var pref_key_bak = pref_key + "_bak";
  598. if(isfullscreen){
  599. var width_orig = util.getIntPref(pref_key);
  600. util.setIntPref(pref_key_bak, width_orig);
  601. util.setIntPref(pref_key, 0);
  602. tabs.setAttribute("width", "0");
  603. }else if(parseInt(tabs.getAttribute("width") || "") === 0){
  604. var width_bak = util.getIntPref(pref_key_bak);
  605. util.setIntPref(pref_key, width_bak);
  606. tabs.setAttribute("width", width_bak.toString());
  607. }
  608. }
  609. }, "go fullscreen with hiding toolbar and tabbar");
  610. ext.add("bookmark-delicious", function(){
  611. f= 'http://www.delicious.com/save?url=' +
  612. encodeURIComponent(window.content.location.href) +
  613. '&title=' + encodeURIComponent(document.title) +
  614. '&notes=' + encodeURIComponent(
  615. '' + (window.getSelection ?
  616. window.getSelection() : (
  617. document.getSelection ?
  618. document.getSelection() :
  619. document.selection.createRange().text))) + '&v=6&';
  620. a = function(){
  621. if(! window.open(
  622. f + 'noui=1&jump=doclose',
  623. 'deliciousuiv6',
  624. 'location=1,links=0,scrollbars=0,toolbar=0,width=710,height=660')){
  625. location.href = f + 'jump=yes';
  626. }
  627. };
  628. if(/Firefox/.test(navigator.userAgent)){
  629. setTimeout(a,0);
  630. }else{
  631. a();
  632. }
  633. }, "bookmark delicious");
  634. ext.add('view-page-source', function(){
  635. window.content.location.href = "view-source:" +
  636. window.content.location.href;
  637. }, 'view page source');
  638. ext.add('my-setpref', function(){
  639. util.setPrefs(
  640. {
  641. "browser.bookmarks.max_backups":0,
  642. "browser.cache.memory.capacity":16384,
  643. "browser.download.manager.closeWhenDone":true,
  644. "browser.download.useDownloadDir":false,
  645. "browser.fullscreen.autohide":false,
  646. "browser.search.openintab":true,
  647. "browser.sessionhistory.max_total_viewers":8,
  648. "browser.sessionstore.restore_on_demand":true,
  649. "browser.tabs.closeWindowWithLastTab":false,
  650. "browser.tabs.loadDivertedInBackground": true,
  651. "browser.urlbar.autocomplete.enabled":false,
  652. "browser.urlbar.trimURLs":false,
  653. "browser.fixup.alternate.enabled": false,
  654. "dom.disable_window_open_feature.location": false,
  655. "dom.max_script_run_time": 30,
  656. "extensions.chaika.bbsmenu.open_new_tab":true,
  657. "extensions.chaika.bbsmenu.open_single_click":false,
  658. "extensions.chaika.board.open_new_tab":true,
  659. "extensions.chaika.board.open_single_click":false,
  660. "extensions.foxage2ch.openThreadInTab":true,
  661. "extensions.saveimageinfolder.general-duplicatefilenamevalue":1,
  662. "extensions.saveimageinfolder.general-fileprefixvalue":
  663. "%yyyy%%MM%%dd%-%hh%%mm%%ss%_",
  664. "extensions.saveimageinfolder.usecache":true,
  665. "extensions.tabutils.openTabNext":1,
  666. "extensions.tabutils.openUrlInTab":false,
  667. "extensions.tabutils.styles.current":
  668. "{\"bold\":true,\"italic\":false,\"underline\":true,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#000000\",\"bgColor\":false,\"bgColorCode\":\"#000000\",\"outline\":false,\"outlineColorCode\":\"#000000\"}",
  669. "extensions.tabutils.styles.unread":
  670. "{\"bold\":false,\"italic\":false,\"underline\":false,\"strikethrough\":false,\"color\":true,\"colorCode\":\"#CC0000\",\"bgColor\":false,\"bgColorCode\":\"undefined\",\"outline\":false,\"outlineColorCode\":\"undefined\"}",
  671. "extensions.tabutils.TFS_Enable":false,
  672. // Always select right tab on close
  673. "extensions.tabutils.selectOnClose":10,
  674. "extensions.yass.edgetype":0,
  675. "extensions.yass.selectedpreset":"red",
  676. "font.default.x-western":"sans-serif",
  677. "gecko.handlerService.schemes.mailto.1.name":"Gmail",
  678. "general.warnOnAboutConfig":false,
  679. "keyword.URL":"http://www.bing.com/search?q=",
  680. "browser.search.defaultenginename":"Bing",
  681. "browser.search.defaulturl":"http://www.bing.com/search?q=",
  682. "network.dns.disableIPv6":true,
  683. "refcontrol.actions":
  684. "@DEFAULT=@FORGE www.heartrails.com=@NORMAL www.pixiv.net=@NORMAL",
  685. "scrapbook.tabs.open":true
  686. }
  687. );
  688. if(/^Linux/.test(navigator.platform)){
  689. util.setPrefs(
  690. {
  691. "browser.cache.disk.parent_directory":"/tmp",
  692. "browser.cache.disk.capacity":524288
  693. }
  694. );
  695. }
  696. display.showPopup("Keysnail", "My prefs done.");
  697. }, 'my setpref');
  698. ext.add('auto-install-plugins', function(ev, arg){
  699. var urls = [
  700. 'https://raw.github.com/mooz/keysnail/master/plugins/yet-another-twitter-client-keysnail.ks.js',
  701. 'https://raw.github.com/mooz/keysnail/master/plugins/site-local-keymap.ks.js',
  702. 'https://raw.github.com/mooz/keysnail/master/plugins/hok.ks.js',
  703. 'https://github.com/mooz/keysnail/raw/master/plugins/builtin-commands-ext.ks.js',
  704. 'https://raw.github.com/azu/KeySnail-Plugins/master/JSReference/js-referrence.ks.js',
  705. 'https://raw.github.com/gongo/keysnail_plugin/master/linksnail.ks.js',
  706. 'https://raw.githubusercontent.com/azu/keysnail-plugin/master/nicontroller.ks.js',
  707. 'https://raw.github.com/10sr/keysnail-plugin/master/shiitake.ks.js',
  708. 'https://raw.github.com/10sr/keysnail-plugin/master/dig-url.ks.js',
  709. 'https://raw.github.com/10sr/keysnail-plugin/master/instapaper.ks.js',
  710. 'https://raw.github.com/10sr/keysnail-plugin/master/pixiv_autojump.ks.js',
  711. 'https://raw.github.com/10sr/keysnail-plugin/master/list-current-urls.ks.js',
  712. 'https://gist.githubusercontent.com/10sr/1976942/raw/firefox-addon-manager.ks.js',
  713. 'https://gist.githubusercontent.com/958/1450594/raw/mstranslator.ks.js'
  714. ];
  715. function inst(a){
  716. if(a.length == 0){
  717. display.showPopup("auto-install-plugins",
  718. "All installation finished.");
  719. }else{
  720. var url = a.shift();
  721. var path = userscript.pluginDir +
  722. userscript.directoryDelimiter + url.match(/[^/]+$/)[0];
  723. if(plugins.context[path] === undefined){
  724. userscript.installPluginFromURL(url, function(){inst(a);});
  725. }else{
  726. inst(a);
  727. }
  728. }
  729. }
  730. inst(urls);
  731. }, 'Install plugins automatically if not installed yet.');
  732. ext.add('put-aside-this-page', function (ev, arg) {
  733. var n = getBrowser().mCurrentTab._tPos;
  734. getBrowser().moveTabTo(getBrowser().mCurrentTab, 0);
  735. if (n != 0) {
  736. getBrowser().selectedTab = getBrowser().mTabs[n];
  737. }
  738. }, 'put aside this page');
  739. ext.add('send-escape', function (ev, arg) {
  740. ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true));
  741. }, 'escape');
  742. ext.add("open-hatebu-comment", function (ev, arg) {
  743. var url = window.content.location.href.replace(/^[^/]*\/\//, "");
  744. window.content.location.href = "http://b.hatena.ne.jp/entry/" + url;
  745. }, 'hatebu');
  746. // ext.add("focus-on-content", function(){
  747. // let(elem = document.commandDispatcher.focusedElement) elem && elem.blur();
  748. // gBrowser.focus();
  749. // content.focus();
  750. // }, "forcus on content");
  751. ext.add("hide-sidebar", function(){
  752. var sidebarBox = document.getElementById("sidebar-box");
  753. if (!sidebarBox.hidden) {
  754. toggleSidebar(sidebarBox.getAttribute("sidebarcommand"));
  755. }
  756. }, "hide-sidebar");
  757. ext.add("close-and-next-tab", function (ev, arg) {
  758. var n = getBrowser().mCurrentTab._tPos;
  759. getBrowser().removeCurrentTab();
  760. getBrowser().selectedTab = getBrowser().mTabs[n];
  761. }, "close and focus to next tab");
  762. //////////////////////////////////////
  763. //
  764. ext.add("restart-firefox-add-menu", function(){
  765. const XUL_NS =
  766. "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  767. var cmdelm = document.createElementNS(XUL_NS, "command");
  768. cmdelm.setAttribute("id", "my_cmd_restartFirefoxKs");
  769. cmdelm.setAttribute("oncommand", "ext.exec('restart-firefox');");
  770. var commandset = document.getElementById("mainCommandSet");
  771. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  772. commandset.appendChild(cmdelm);
  773. var menuelm = document.createElementNS(XUL_NS, "menuitem");
  774. menuelm.setAttribute("label", "Restart Firefox");
  775. menuelm.setAttribute("id", "my_menu_restartFirefoxKs");
  776. menuelm.setAttribute("command", "my_cmd_restartFirefoxKs");
  777. var menu = document.getElementById("menu_FilePopup");
  778. // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem"));
  779. menu.appendChild(menuelm);
  780. }, "add restart firefox menu");
  781. /////////////////////////////////////////
  782. // feed url
  783. ext.add("feed-add-to-feedly", function(){
  784. var url = window.content.location.href;
  785. window.content.location.href =
  786. "http://cloud.feedly.com/#subscription%2Ffeed%2F" +
  787. encodeURIComponent(url);
  788. }, "Add current feed to feedly");
  789. var feedUtils = (function(){
  790. var feedhandler = "http://cloud.feedly.com/#subscription%2Ffeed%2F%s";
  791. function getFeeds(){
  792. const doc = content.document;
  793. var feeds = [[e.getAttribute("title"), e.getAttribute("href")]
  794. for ([, e] in Iterator(doc.querySelectorAll([
  795. 'link[type="application/rss+xml"]',
  796. 'link[type="application/atom+xml"]'
  797. ])))];
  798. var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,
  799. "$1");
  800. for (i = 0; i < feeds.length; i++)
  801. if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1];
  802. // feeds.unshift([window.content.document.title,
  803. // window.content.location.href]);
  804. return feeds;
  805. };
  806. ext.add("copy-feed-url", function () {
  807. var feeds = getFeeds();
  808. if (! feeds.length) {
  809. display.echoStatusBar("No feed found.");
  810. return;
  811. }
  812. prompt.selector({
  813. message : "Select Feed",
  814. collection : feeds,
  815. callback : function (i) {
  816. if (i >= 0) {
  817. command.setClipboardText(feeds[i][1]);
  818. }
  819. }
  820. });
  821. }, "Copy url or feed url of current page");
  822. ext.add("open-feed", function () {
  823. var feeds = getFeeds();
  824. if (! feeds.length) {
  825. display.echoStatusBar("No feed found.");
  826. return;
  827. }
  828. prompt.selector({
  829. message : "Select Feed",
  830. collection : feeds,
  831. callback : function (i) {
  832. if (i < 0) {
  833. return;
  834. }
  835. var feedurl = feeds[i][1];
  836. if (feedhandler) {
  837. window.openUILinkIn(
  838. feedhandler.replace("%s", feedurl),
  839. "tab"
  840. );
  841. } else {
  842. window.openUILinkIn(feedurl, "tab");
  843. }
  844. }
  845. });
  846. }, "Copy url or feed url of current page");
  847. return {
  848. getFeeds: getFeeds
  849. };
  850. })();
  851. ///////////////////////////////////////
  852. // keysnail z menu
  853. ext.add("keysnail-setting-dialog", function(){
  854. KeySnail.openPreference();
  855. }, "keysnail setting dialog");
  856. ext.add("keysnail-plugin-manager", function(){
  857. userscript.openPluginManager();
  858. }, "keysnail plugin manager");
  859. ext.add("firefox-open-addon-manager", function(){
  860. BrowserOpenAddonsMgr();
  861. }, "firefox addon manager");
  862. ext.add("keysnail-reload-init-file", function(){
  863. userscript.reload();
  864. }, "keysnail reload init file");
  865. ext.add("keysnail-z-menu",function(){
  866. var list = [["keysnail-setting-dialog"],
  867. ["keysnail-plugin-manager"],
  868. ["firefox-open-addon-manager"],
  869. ["keysnail-reload-init-file"],
  870. // ["check-for-plugins-update"],
  871. ["restart-firefox"]
  872. ];
  873. prompt.selector(
  874. {
  875. message : "open setting dialog",
  876. collection : list,
  877. callback : function (i) {
  878. ext.exec(list[i][0]);
  879. }
  880. });
  881. },"open keysnail z menu");
  882. ///////////////////////////////////
  883. // search web
  884. ext.add("query-then-engine", function () {
  885. prompt.reader({
  886. message : "Search Word?:",
  887. group : "query_word",
  888. // completer : completer.matcher.header(share.friendsCache || []),
  889. initialInput : content.document.getSelection() || "",
  890. callback : function (q) {
  891. if (q) {
  892. prompt.selector({
  893. message : "search \"" + q + "\" with?",
  894. collection : plugins.options["search-url-list"],
  895. width : [20,80],
  896. callback : function (i) {
  897. getBrowser().selectedTab =
  898. getBrowser().addTab(
  899. plugins.options["search-url-list"][i][1].
  900. replace("%r",q).replace(
  901. "%q",encodeURIComponent(q)
  902. )
  903. )
  904. ;
  905. }
  906. });
  907. };
  908. }
  909. });
  910. }, "enter search word and then select engine");
  911. /////////////////////////////////////
  912. // closed tab list
  913. ext.add("list-closed-tabs", function () {
  914. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  915. var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(
  916. Ci.nsISessionStore
  917. );
  918. var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  919. var closedTabs = [[tab.image || fav, tab.title, tab.url]
  920. for each (tab in json.decode(ss.getClosedTabData(window)))
  921. ];
  922. if (!closedTabs.length)
  923. return void display.echoStatusBar("No recently closed tab.", 2000);
  924. prompt.selector(
  925. {
  926. message : "select tab to undo:",
  927. collection : closedTabs,
  928. flags : [ICON | IGNORE, 0, 0],
  929. callback : function (i) { if (i >= 0) window.undoCloseTab(i); }
  930. });
  931. }, "List closed tabs");
  932. ///////////////////////////////
  933. // http://malblue.tumblr.com/post/349001250/tips-japanese-keysnail-github
  934. ext.add("list-tab-history", function () {
  935. const fav = "chrome://mozapps/skin/places/defaultFavicon.png";
  936. var tabHistory = [];
  937. var sessionHistory = getBrowser().webNavigation.sessionHistory;
  938. if (sessionHistory.count < 1)
  939. return void display.echoStatusBar("Tab history not exist", 2000);
  940. var curIdx = sessionHistory.index;
  941. for (var i = 0; i < sessionHistory.count; i++) {
  942. var entry = sessionHistory.getEntryAtIndex(i, false);
  943. if (!entry)
  944. continue;
  945. try {
  946. var iconURL = Cc["@mozilla.org/browser/favicon-service;1"]
  947. .getService(Ci.nsIFaviconService)
  948. .getFaviconForPage(entry.URI).spec;
  949. } catch (ex) {}
  950. tabHistory.push([iconURL || fav, entry.title, entry.URI.spec, i]);
  951. }
  952. for (var thIdx = 0; thIdx < tabHistory.length; thIdx++) {
  953. if (tabHistory[thIdx][3] == curIdx) break;
  954. }
  955. prompt.selector(
  956. {
  957. message : "select history in tab",
  958. collection : tabHistory,
  959. flags : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
  960. header : ["Title", "URL"],
  961. initialIndex : thIdx,
  962. callback : function(i) {
  963. if (i >= 0)
  964. getBrowser().webNavigation.gotoIndex(tabHistory[i][3]);
  965. }
  966. });
  967. }, 'List tab history');
  968. //}}%PRESERVE%
  969. // ========================================================================= //
  970. // ========================= Special key settings ========================== //
  971. key.quitKey = "ESC";
  972. key.helpKey = "<f1>";
  973. key.escapeKey = "C-q";
  974. key.macroStartKey = "";
  975. key.macroEndKey = "";
  976. key.universalArgumentKey = "C-u";
  977. key.negativeArgument1Key = "C--";
  978. key.negativeArgument2Key = "C-M--";
  979. key.negativeArgument3Key = "M--";
  980. key.suspendKey = "Not defined";
  981. // ================================= Hooks ================================= //
  982. hook.setHook('KeyBoardQuit', function (aEvent) {
  983. // ext.exec("hide-sidebar");
  984. let(elem = document.commandDispatcher.focusedElement) {elem && elem.blur()};
  985. getBrowser().focus();
  986. content.focus();
  987. command.closeFindBar();
  988. if (util.isCaretEnabled()) {
  989. command.resetMark(aEvent);
  990. } else {
  991. goDoCommand("cmd_selectNone");
  992. }
  993. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  994. });
  995. hook.setHook('Unload', function () {
  996. util.getBrowserWindows().some(function (win) {
  997. if (win === window) {
  998. return false;
  999. }
  1000. const ks = win.KeySnail;
  1001. share.pluginUpdater = ks.getPluginUpdater(
  1002. share.pluginUpdater.pluginsWithUpdate);
  1003. ks.setUpPluginUpdaterDelegator();
  1004. return true;
  1005. });
  1006. });
  1007. hook.setHook('LocationChange', function (aNsURI) {
  1008. echoTabInfo.echo();
  1009. });
  1010. // ============================= Key bindings ============================== //
  1011. key.setGlobalKey('C-<up>', function () {
  1012. var browser = getBrowser();
  1013. if (browser.mCurrentTab.previousSibling) {
  1014. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  1015. } else {
  1016. browser.moveTabTo(browser.mCurrentTab,
  1017. browser.mTabContainer.childNodes.length - 1);
  1018. }
  1019. }, '選択中のタブを右へ');
  1020. key.setGlobalKey('C-<down>', function () {
  1021. var browser = getBrowser();
  1022. if (browser.mCurrentTab.nextSibling) {
  1023. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  1024. } else {
  1025. browser.moveTabTo(browser.mCurrentTab, 0);
  1026. }
  1027. }, '選択中のタブを左へ');
  1028. key.setGlobalKey('<delete>', function (ev, arg) {
  1029. let (elem = document.commandDispatcher.focusedElement) {elem && elem.blur()};
  1030. getBrowser().focus();
  1031. content.focus();
  1032. }, 'コンテンツへフォーカス', true);
  1033. key.setGlobalKey('<f11>', function (ev, arg) {
  1034. ext.exec("strong-fullscreen", arg, ev);
  1035. }, 'go fullscreen with hiding toolbar and tabbar', true);
  1036. key.setGlobalKey('<end>', function (ev) {
  1037. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  1038. }, 'ひとつ右のタブへ');
  1039. key.setGlobalKey('<home>', function (ev) {
  1040. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  1041. }, 'ひとつ左のタブへ');
  1042. key.setGlobalKey('<next>', function (ev) {
  1043. let browser = getBrowser();
  1044. if (browser.mCurrentTab.nextSibling) {
  1045. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  1046. } else {
  1047. browser.moveTabTo(browser.mCurrentTab, 0);
  1048. }
  1049. }, '選択中のタブを右へ');
  1050. key.setGlobalKey('<prior>', function (ev) {
  1051. let browser = getBrowser();
  1052. if (browser.mCurrentTab.previousSibling) {
  1053. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  1054. } else {
  1055. browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
  1056. }
  1057. }, '選択中のタブを左へ');
  1058. key.setViewKey('0', function (ev) {
  1059. BrowserCloseTabOrWindow();
  1060. }, 'タブ / ウィンドウを閉じる');
  1061. key.setViewKey('l', function (ev) {
  1062. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  1063. }, 'ひとつ右のタブへ');
  1064. key.setViewKey('h', function (ev) {
  1065. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  1066. }, 'ひとつ左のタブへ');
  1067. key.setViewKey('o', function (ev, arg) {
  1068. ext.exec("hok-start-foreground-mode", arg, ev);
  1069. }, 'Start Hit a Hint foreground mode', true);
  1070. key.setViewKey('c', function (ev) {
  1071. command.interpreter();
  1072. }, 'JavaScript のコードを評価');
  1073. key.setViewKey('D', function (ev, arg) {
  1074. ext.exec("dig-url", arg, ev);
  1075. }, 'dig url with selector', true);
  1076. key.setViewKey('x', function (aEvent, aArg) {
  1077. ext.select(aArg, aEvent);
  1078. }, 'エクステ一覧');
  1079. key.setViewKey(['t', 'w'], function (ev, arg) {
  1080. ext.exec("twitter-client-tweet", arg, ev);
  1081. }, 'つぶやく', true);
  1082. key.setViewKey(['t', 'p'], function (ev, arg) {
  1083. ext.exec("twitter-client-tweet-this-page", arg, ev);
  1084. }, 'このページのタイトルと URL を使ってつぶやく', true);
  1085. key.setViewKey([['u'], ['S-SPC']], function (ev) {
  1086. goDoCommand("cmd_scrollPageUp");
  1087. }, '一画面分スクロールアップ');
  1088. key.setViewKey('g', function () {
  1089. goDoCommand("cmd_scrollTop");
  1090. }, 'ページ先頭へ移動');
  1091. key.setViewKey('G', function () {
  1092. goDoCommand("cmd_scrollBottom");
  1093. }, 'ページ末尾へ移動');
  1094. key.setViewKey('r', function (aEvent) {
  1095. BrowserReload();
  1096. }, '再読み込み');
  1097. key.setViewKey('z', function (ev, arg) {
  1098. ext.exec("keysnail-z-menu", arg, ev);
  1099. }, 'open keysnail setting menu', true);
  1100. key.setViewKey('e', function () {
  1101. command.focusElement(command.elementsRetrieverTextarea, 0);
  1102. }, '最初のインプットエリアへフォーカス', true);
  1103. key.setViewKey('S', function (ev, arg) {
  1104. if (window.loadURI) {
  1105. 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{}");
  1106. }
  1107. }, 'google reader share');
  1108. key.setViewKey('!', function (ev, arg) {
  1109. shell.input();
  1110. }, 'Command system');
  1111. key.setViewKey('R', function () {
  1112. BrowserReloadSkipCache();
  1113. }, '更新(キャッシュを無視)');
  1114. key.setViewKey('<backspace>', function () {
  1115. BrowserBack();
  1116. }, '戻る');
  1117. key.setViewKey('S-<backspace>', function () {
  1118. BrowserForward();
  1119. }, '進む');
  1120. key.setViewKey('q', function (ev, arg) {
  1121. ext.exec("query-then-engine", arg, ev);
  1122. }, 'enter search word and then select engine', true);
  1123. key.setViewKey('/', function () {
  1124. command.iSearchForward();
  1125. }, 'インクリメンタル検索', true);
  1126. key.setViewKey('?', function (ev) {
  1127. command.iSearchForwardKs(ev);
  1128. }, 'Emacs ライクなインクリメンタル検索', true);
  1129. key.setViewKey('a', function (ev, arg) {
  1130. allTabs.open();
  1131. }, 'alltabs.open');
  1132. key.setViewKey([['d'], ['SPC']], function (ev) {
  1133. goDoCommand("cmd_scrollPageDown");
  1134. }, '一画面スクロールダウン');
  1135. key.setViewKey(':', function (ev, arg) {
  1136. return !document.getElementById("keysnail-prompt").hidden &&
  1137. document.getElementById("keysnail-prompt-textbox").focus();
  1138. }, 'KeySnail のプロンプトへフォーカス', true);
  1139. key.setViewKey('B', function (ev) {
  1140. var browser = getBrowser();
  1141. if (browser.mCurrentTab.previousSibling) {
  1142. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
  1143. } else {
  1144. browser.moveTabTo(browser.mCurrentTab,
  1145. browser.mTabContainer.childNodes.length - 1);
  1146. }
  1147. }, '選択中のタブを左へ');
  1148. key.setViewKey('C', function (ev, arg) {
  1149. ext.exec("linksnail", arg, ev);
  1150. }, 'LinkSnail', true);
  1151. key.setViewKey('C-<backspace>', function (ev, arg) {
  1152. ext.exec("list-tab-history", arg, ev);
  1153. }, 'List tab history', true);
  1154. key.setViewKey('I', function (ev, arg) {
  1155. ext.exec("instapaper-post-page-with-comment", arg, ev);
  1156. }, 'post page and comment', true);
  1157. key.setViewKey('T', function (ev, arg) {
  1158. ext.exec("mstranslator-open-prompt", arg, ev);
  1159. }, 'MSTranslator - Open prompt', true);
  1160. key.setViewKey('f', function (ev, arg) {
  1161. ext.exec('strong-fullscreen', arg, ev);
  1162. }, 'go fullscreen with hiding toolbar and tabbar', true);
  1163. key.setViewKey('F', function (ev) {
  1164. var browser = getBrowser();
  1165. if (browser.mCurrentTab.nextSibling) {
  1166. browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
  1167. } else {
  1168. browser.moveTabTo(browser.mCurrentTab, 0);
  1169. }
  1170. }, '選択中のタブを右へ');
  1171. key.setViewKey('U', function (ev, arg) {
  1172. ext.exec("list-closed-tabs", arg, ev);
  1173. }, 'List closed tabs', true);
  1174. key.setViewKey('j', function (ev) {
  1175. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  1176. }, '一行スクロールダウン');
  1177. key.setViewKey('k', function (ev) {
  1178. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  1179. }, '一行スクロールアップ');
  1180. key.setViewKey('p', function (ev, arg) {
  1181. ext.exec('pocket-add-current', arg, ev);
  1182. }, 'Add current page', true);
  1183. key.setViewKey('P', function (ev, arg) {
  1184. ext.exec('pocket-open-latest', arg, ev);
  1185. }, 'Open last saved page', true);
  1186. key.setEditKey('C-<tab>', function (ev) {
  1187. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  1188. }, '次のテキストエリアへフォーカス');
  1189. key.setEditKey('C-a', function (ev) {
  1190. command.beginLine(ev);
  1191. }, '行頭へ移動');
  1192. key.setEditKey('C-e', function (ev) {
  1193. command.endLine(ev);
  1194. }, '行末へ');
  1195. key.setEditKey('C-d', function (ev) {
  1196. goDoCommand("cmd_deleteCharForward");
  1197. }, '次の一文字削除');
  1198. key.setEditKey('C-b', function (ev) {
  1199. command.previousChar(ev);
  1200. }, '一文字左へ移動');
  1201. key.setEditKey('C-f', function (ev) {
  1202. command.nextChar(ev);
  1203. }, '一文字右へ移動');
  1204. key.setEditKey('C-h', function (ev) {
  1205. goDoCommand("cmd_deleteCharBackward");
  1206. }, '前の一文字を削除');
  1207. key.setEditKey('C-k', function (ev) {
  1208. command.killLine(ev);
  1209. }, 'カーソルから先を一行カット (Kill line)');
  1210. key.setEditKey('C-l', function (ev) {
  1211. command.recenter(ev);
  1212. }, 'カーソル位置が画面の中央へ来るようスクロール', true);
  1213. key.setEditKey('C-n', function (ev) {
  1214. command.nextLine(ev);
  1215. }, '一行下へ');
  1216. key.setEditKey('C-p', function (ev) {
  1217. command.previousLine(ev);
  1218. }, '一行上へ');
  1219. key.setEditKey('C-o', function (ev) {
  1220. command.openLine(ev);
  1221. }, '行を開く (Open line)');
  1222. key.setGlobalKey('C-<right>', function (ev) {
  1223. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  1224. }, 'ひとつ右のタブへ');
  1225. key.setGlobalKey('C-<left>', function (ev) {
  1226. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  1227. }, 'ひとつ左のタブへ');