settings.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /// Misc
  2. session_pref("general.useragent.compatMode.firefox", true);
  3. session_pref("general.useragent.extra.conkeror", "");
  4. session_pref('browser.history_expire_days', 30);
  5. session_pref("browser.enable_automatic_image_resizing", true);
  6. session_pref("browser.dom.window.dump.enabled", false);
  7. session_pref("full-screen-api.enabled", true);
  8. if (current_profile == "tor") {
  9. session_pref("network.proxy.type", 1);
  10. session_pref("network.proxy.socks_remote_dns", true);
  11. session_pref("network.proxy.socks", "localhost");
  12. session_pref("network.proxy.socks_port", 9050);
  13. } else {
  14. homepage = "https://bbs.archlinux.org/search.php?action=show_recent";
  15. }
  16. hints_auto_exit_delay = 200;
  17. minibuffer_read_url_select_initial = true;
  18. isearch_scroll_center_vertically = true;
  19. // the method of loading url (from argument) when conkeror
  20. // is opened again (externally)
  21. url_remoting_fn = load_url_in_new_buffer;
  22. can_kill_last_buffer = false;
  23. download_buffer_automatic_open_target = OPEN_NEW_BUFFER_BACKGROUND;
  24. // require("clicks-in-new-buffer.js");
  25. clicks_in_new_buffer_button = 1; // middle button
  26. clicks_in_new_buffer_target = OPEN_NEW_BUFFER_BACKGROUND;
  27. function update_save_path (info) {
  28. // Set download directory.
  29. // cwd = info.target_file.parent;
  30. cwd = make_file("~/tmp");
  31. }
  32. add_hook("download_added_hook", update_save_path);
  33. // adblockplus
  34. //require("adblockplus.js");
  35. interactive("adblockplus-filters",
  36. "Show the Adblock Plus filter settings dialog.",
  37. function (I) {
  38. make_chrome_window("chrome://adblockplus/content/ui/filters.xul");
  39. });
  40. ////////////////////////////////////////////////////////////////
  41. /// External programs
  42. editor_shell_command = "emacsclient";
  43. set_protocol_handler("mailto", find_file_in_path("mailto"));
  44. set_protocol_handler("magnet", find_file_in_path("magnet2torrent"));
  45. content_handlers.set("application/x-bittorrent", content_handler_open_default_viewer);
  46. external_content_handlers.set("application/pdf", "zathura");
  47. external_content_handlers.set("application/x-bittorrent", "torrent_job");
  48. ////////////////////////////////////////////////////////////////
  49. /// Interacting with org-mode
  50. function org_store_link (url, title, window) {
  51. var cmd_str = '\"org-protocol://store-link?url='+url+'&title='+title+'\"';
  52. if (window != null) {
  53. window.minibuffer.message('Issuing ' + cmd_str);
  54. }
  55. shell_command_blind('emacsclient ' + cmd_str);
  56. shell_command_blind('emacsclient -s server-emms ' + cmd_str);
  57. }
  58. interactive("org-store-link", "Store url and title via org-protocol",
  59. function (I) {
  60. org_store_link(encodeURIComponent(I.buffer.display_uri_string),
  61. encodeURIComponent(I.buffer.document.title),
  62. I.window);
  63. });
  64. ////////////////////////////////////////////////////////////////
  65. /// Blocking focus
  66. // <http://conkeror.org/Focus>
  67. function focusblock (buffer) {
  68. var s = Components.utils.Sandbox(buffer.top_frame);
  69. s.document = buffer.document.wrappedJSObject;
  70. Components.utils.evalInSandbox(
  71. "(function () {\
  72. function nothing () {}\
  73. if (! document.forms)\
  74. return;\
  75. for (var i = 0, nforms = document.forms.length; i < nforms; i++) {\
  76. for (var j = 0, nels = document.forms[i].elements.length; j < nels; j++)\
  77. document.forms[i].elements[j].focus = nothing;\
  78. }\
  79. })();",
  80. s);
  81. }
  82. add_hook('content_buffer_progress_change_hook', focusblock);
  83. ////////////////////////////////////////////////////////////////
  84. /// Javascript
  85. interactive("toggle-js", "toggle javascript",
  86. function (I) {
  87. var pref = "javascript.enabled";
  88. var val = get_pref(pref);
  89. val = !val;
  90. session_pref(pref, val);
  91. I.window.minibuffer.show("JavaScript is " + (val ? "ON" : "OFF"));
  92. });
  93. ////////////////////////////////////////////////////////////////
  94. /// Buffers
  95. interactive("switch-to-other-buffer",
  96. "Switch to the previously active buffer",
  97. function (I) {
  98. var blist = I.window.buffers.buffer_history;
  99. if (blist.length > 1)
  100. switch_to_buffer(I.window, blist[1]);
  101. });
  102. // Restore killed buffers: <http://conkeror.org/Tips#Restore_Killed_Buffer_Url>
  103. var kill_buffer_original = kill_buffer_original || kill_buffer;
  104. var killed_buffer_urls = [];
  105. kill_buffer = function (buffer, force) {
  106. if (buffer.display_uri_string) {
  107. killed_buffer_urls.push(buffer.display_uri_string);
  108. }
  109. kill_buffer_original(buffer,force);
  110. };
  111. interactive("restore-killed-buffer-url",
  112. "Restore a previously killed buffer",
  113. function restore_killed_buffer_url (I) {
  114. if (killed_buffer_urls.length !== 0) {
  115. var url = yield I.minibuffer.read(
  116. $prompt = "Restore killed url:",
  117. $completer = new all_word_completer($completions = killed_buffer_urls, $require_match = true),
  118. $default_completion = killed_buffer_urls[killed_buffer_urls.length - 1],
  119. $auto_complete = "url",
  120. $auto_complete_initial = true,
  121. $auto_complete_delay = 0,
  122. $require_match = true);
  123. load_url_in_new_buffer(url);
  124. }
  125. else {
  126. I.window.minibuffer.message("No killed buffers");
  127. }
  128. });
  129. ////////////////////////////////////////////////////////////////
  130. /// Finding urls, history
  131. // add history items in "find-url"
  132. url_completion_use_history = true;
  133. define_browser_object_class(
  134. "history-url", null,
  135. function (I, prompt) {
  136. check_buffer (I.buffer, content_buffer);
  137. var result = yield I.buffer.window.minibuffer.read_url(
  138. $prompt = prompt, $use_webjumps = false, $use_history = true, $use_bookmarks = false);
  139. yield co_return (result);
  140. });
  141. interactive("find-url-from-history",
  142. "Find a page from history in the current buffer",
  143. alternates(follow_current_buffer, follow_new_buffer, follow_new_window),
  144. $browser_object = browser_object_history_url)
  145. interactive("follow-next",
  146. "Follow 'next' link",
  147. alternates(follow_current_buffer, follow_new_buffer, follow_new_window),
  148. $browser_object = browser_object_relationship_next);
  149. interactive("follow-previous",
  150. "Follow 'previous' link",
  151. alternates(follow_current_buffer, follow_new_buffer, follow_new_window),
  152. $browser_object = browser_object_relationship_previous);
  153. interactive("find-alternate-select-url", "Edit the current URL in the minibuffer",
  154. "find-url",
  155. $browser_object =
  156. define_browser_object_class("alternate-url", null,
  157. function (I, prompt) {
  158. check_buffer(I.buffer, content_buffer);
  159. var result = yield I.buffer.window.minibuffer.read_url(
  160. $prompt = prompt,
  161. $select = true,
  162. $initial_value = I.buffer.display_uri_string);
  163. yield co_return(result);
  164. }),
  165. $prompt = "Find url");
  166. ////////////////////////////////////////////////////////////////
  167. /// Webjumps & searches
  168. wikipedia_webjumps_format = "wikipedia-%s";
  169. define_wikipedia_webjumps("en", "ru", "fr");
  170. define_webjump("emacswiki",
  171. "http://www.google.com/cse?cx=004774160799092323420%3A6-ff2s0o6yi"+
  172. "&q=%s&sa=Search&siteurl=emacswiki.org%2F",
  173. $alternative="http://www.emacswiki.org/");
  174. define_webjump("archwiki", "https://wiki.archlinux.org/index.php?search=%s",
  175. $alternative="http://www.archlinux.org");
  176. define_webjump("arch-package", "https://www.archlinux.org/packages/?sort=&q=%s&maintainer=&flagged=",
  177. $alternative="https://www.archlinux.org/packages");
  178. define_webjump("youtube", "http://www.youtube.com/results?search_query=%s&search=Search",
  179. $alternative="https://www.youtube.com/feed/subscriptions");
  180. define_webjump("youtube-user", "http://youtube.com/profile_videos?user=%s");
  181. define_webjump("stackoverflow", "http://stackoverflow.com/search?q=%s",
  182. $alternative="http://stackoverflow.com");
  183. define_webjump("python2", "http://docs.python.org/search.html?q=%s");
  184. define_webjump("python3", "http://docs.python.org/py3k/search.html?q=%s",
  185. $alternative="http://docs.python.org/3/library");
  186. define_webjump("pypi", "https://pypi.python.org/pypi?:action=search&term=%s&submit=search",
  187. $alternative="https://pypi.python.org/pypi");
  188. define_webjump("mana", "https://www.themanaworld.org/index.php/Special:Search/%s",
  189. $alternative="https://www.themanaworld.org/index.php");
  190. define_webjump("ip", "http://www.ip-address.org/lookup/ip-locator.php?track=%s",
  191. $alternative="http://www.ip-address.org/");
  192. define_webjump("multitran", "http://www.multitran.ru/c/M.exe?CL=1&s=%s");
  193. // french - http://www.multitran.ru/c/m.exe?l1=4&l2=2&CL=1&a=0
  194. define_webjump("yandex", "http://yandex.ru/yandsearch?text=%s");
  195. define_webjump("github", "http://github.com/search?q=%s&type=Everything",
  196. $alternative="https://github.com/notifications");
  197. // selection searches
  198. function create_selection_search(webjump, key) {
  199. interactive(
  200. "internet-search-" + webjump,
  201. "Search for selected string with " + webjump,
  202. function (I) {
  203. var term;
  204. if (I.buffer.top_frame.getSelection() == "")
  205. term = yield I.minibuffer.read_url($prompt = "Search with " + webjump + ":",
  206. $select = false,
  207. $initial_value = webjump + " ");
  208. else
  209. term = webjump + " " + I.buffer.top_frame.getSelection();
  210. browser_object_follow(I.buffer, OPEN_NEW_BUFFER, term);
  211. });
  212. define_key(content_buffer_normal_keymap, key, "internet-search-" + webjump);
  213. interactive(
  214. "internet-search-" + webjump + "-prompted",
  215. "Search for a string with " + webjump,
  216. function (I) {
  217. var term = yield I.minibuffer.read_url($prompt = "Search with " + webjump + ":",
  218. $select = false,
  219. $initial_value = webjump + " ");
  220. browser_object_follow(I.buffer, OPEN_NEW_BUFFER, term);
  221. });
  222. }
  223. create_selection_search("google" , "M-S G");
  224. create_selection_search("duckduckgo" , "M-S d");
  225. create_selection_search("github" , "M-S g");
  226. create_selection_search("conkeror" , "M-S c");
  227. create_selection_search("emacswiki" , "M-S e");
  228. create_selection_search("archwiki" , "M-S a");
  229. create_selection_search("arch-package" , "M-S A");
  230. create_selection_search("wikipedia-en" , "M-S w e");
  231. create_selection_search("wikipedia-ru" , "M-S w r");
  232. create_selection_search("multitran" , "M-S M");
  233. create_selection_search("mana" , "M-S m");
  234. create_selection_search("ip" , "M-S i");
  235. create_selection_search("yandex" , "M-S Y");
  236. create_selection_search("youtube" , "M-S y");
  237. create_selection_search("stackoverflow" , "M-S s");
  238. create_selection_search("python3" , "M-S p");