User:Splarka/nosearchsuggest.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Splarka/nosearchsuggest. |
/* Cookie-based search suggest disable test for anon users, version [0.0.1]
Sets a cookie via URL parameter, examples:
disable search suggest: http://en.wikipedia.org/wiki/Main_Page?disableSearchSuggest=true
reenable search suggest: http://en.wikipedia.org/wiki/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[1]);
} catch (e) {
}
}
return null;
}