logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

searx.js (3853B)


  1. if(searx.autocompleter) {
  2. window.addEvent('domready', function() {
  3. new Autocompleter.Request.JSON('q', '/autocompleter', {
  4. postVar:'q',
  5. postData:{
  6. 'format': 'json'
  7. },
  8. ajaxOptions:{
  9. timeout: 5 // Correct option?
  10. },
  11. 'minLength': 4,
  12. 'selectMode': false,
  13. cache: true,
  14. delay: 300
  15. });
  16. });
  17. }
  18. (function (w, d) {
  19. 'use strict';
  20. function addListener(el, type, fn) {
  21. if (el.addEventListener) {
  22. el.addEventListener(type, fn, false);
  23. } else {
  24. el.attachEvent('on' + type, fn);
  25. }
  26. }
  27. function placeCursorAtEnd() {
  28. if (this.setSelectionRange) {
  29. var len = this.value.length * 2;
  30. this.setSelectionRange(len, len);
  31. }
  32. }
  33. addListener(w, 'load', function () {
  34. var qinput = d.getElementById('q');
  35. if (qinput !== null && qinput.value === "") {
  36. addListener(qinput, 'focus', placeCursorAtEnd);
  37. qinput.focus();
  38. }
  39. });
  40. if (!!('ontouchstart' in window)) {
  41. document.getElementsByTagName("html")[0].className += " touch";
  42. }
  43. })(window, document);
  44. var xmlHttp
  45. function GetXmlHttpObject(){
  46. var xmlHttp = null;
  47. try {
  48. // Firefox, Opera 8.0+, Safari
  49. xmlHttp = new XMLHttpRequest();
  50. }
  51. catch (e) {
  52. // Internet Explorer
  53. try {
  54. xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  55. }
  56. catch (e){
  57. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  58. }
  59. }
  60. return xmlHttp;
  61. }
  62. var timer;
  63. // Load more results
  64. function load_more(query,page){
  65. xmlHttp = GetXmlHttpObject();
  66. clearTimeout(timer);
  67. if(xmlHttp == null){
  68. alert ("Your browser does not support AJAX!");
  69. return;
  70. }
  71. favicons[page] = [];
  72. xmlHttp.onreadystatechange = function(){
  73. var loader = document.getElementById('load_more');
  74. // If 4, response OK
  75. if (xmlHttp.readyState == 4){
  76. var res = xmlHttp.responseText;
  77. clearTimeout(timer);
  78. timer = setTimeout(function(){},6000);
  79. var results = document.getElementById('results_list');
  80. var newNode = document.createElement('span');
  81. newNode.innerHTML = res;
  82. results_list.appendChild(newNode);
  83. var scripts = newNode.getElementsByTagName('script');
  84. for (var ix = 0; ix < scripts.length; ix++) {
  85. eval(scripts[ix].text);
  86. }
  87. load_images(page);
  88. document.getElementById("load_more").onclick = function() { load_more(query, (page+1)); }
  89. loader.removeAttribute("disabled");
  90. } else {
  91. loader.disabled = 'disabled';
  92. }
  93. }
  94. var url = "/";
  95. var params = "q="+query+"&pageno="+page+"&category_general=1&category_files=1&category_images=1&category_it=1&category_map=1&category_music=1&category_news=1&category_social+media=1&category_videos=1";
  96. xmlHttp.open("POST",url,true);
  97. xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  98. xmlHttp.setRequestHeader("Content-length", params.length);
  99. xmlHttp.setRequestHeader("Connection", "close");
  100. xmlHttp.send(params);
  101. }
  102. // Load the images on the canvas in the page
  103. function load_images(page){
  104. var arrayLength = favicons[page].length;
  105. for (var i = 1; i < arrayLength+1; i++) {
  106. var img = new Image();
  107. img.setAttribute("i",i)
  108. img.onload = function () {
  109. var id = 'canvas-'+page+'-'+this.getAttribute("i");
  110. var can = document.getElementById(id);
  111. var ctx = can.getContext("2d");
  112. ctx.drawImage(this, 0, 0, 16, 16);
  113. };
  114. img.src = favicons[page][i];
  115. }
  116. }