User:Splarka/nosearchsuggest.js

In this article, we are going to address the topic of User:Splarka/nosearchsuggest.js from different perspectives and angles, with the aim of providing a comprehensive and complete view on this topic. We will analyze its impact in different contexts, its evolution over time, as well as the different opinions and positions that exist on the matter. User:Splarka/nosearchsuggest.js is a topic of current relevance that arouses great interest and debate, which is why it is essential to address it in a rigorous and exhaustive manner. Through this article, we aim to offer our readers a detailed and enriching vision of User:Splarka/nosearchsuggest.js, with the aim of contributing to the knowledge and understanding of this particular topic.
/* Cookie-based search suggest disable test for anon users, version 

Sets a cookie via URL parameter, examples:
  disable search suggest: http://en.wikipedia.orghttps://wikifreehand.com/en/Main_Page?disableSearchSuggest=true
 reenable search suggest: http://en.wikipedia.orghttps://wikifreehand.com/en/Main_Page?enableSearchSuggest=true

Would need to be placed in the site-wide JS (possibly conditional on wgUserName) and links
to the enable/disable provided (possibly on Special:Search).

Hacky and probably unneeded if https://bugzilla.wikimedia.org/show_bug.cgi?id=13848 is done.
*/

if(getCookie('noSearchSuggest') == 'true') { 
  //disable init of search suggest (hacky)
  function os_initHandlers() {}
}
if(queryString('disableSearchSuggest')) setCookie('noSearchSuggest','true')
if(queryString('enableSearchSuggest')) setCookie('noSearchSuggest','false')

function setCookie(cookieName, cookieValue) {
 var today = new Date();
 var expire = new Date();
 var nDays = 365;
 expire.setTime(today.getTime() + (3600000 * 24 * nDays));
 document.cookie = cookieName + "=" + escape(cookieValue) + ";path=/"  + ";expires="+expire.toGMTString();
}

function getCookie(cookieName) {
  var start = document.cookie.indexOf(cookieName + "=");
  if (start == -1) return "";
  var len = start + cookieName.length + 1;
  if ((!start) && (cookieName != document.cookie.substring(0,cookieName.length))) {
    return '';
  }
  var end = document.cookie.indexOf(";",len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len, end));
}

function queryString(p) {
  var re = RegExp('' + p + '=(*)');
  var matches;
  if (matches = re.exec(document.location)) {
    try { 
      return decodeURI(matches);
    } catch (e) {
    }
  }
  return null;
}