Difference between revisions of "MediaWiki:Common.js"

From Fall of Eden
Jump to navigation Jump to search
Line 1: Line 1:
var cookies;
+
function readCookie(e,t,n,r){if(cookies){return cookies[e]}t=document.cookie.split("; ");cookies={};for(r=t.length-1;r>=0;r--){n=t[r].split("=");cookies[n[0]]=n[1]}return cookies[e]}function checkAge(e){var t=readCookie("ageCheck");if(!t){window.location.href="age.html?url="+encodeURIComponent(e)}return t}function setCookie(e,t,n,r){var i=new Date;i.setTime(i.getTime()+n*24*60*60*1e3);var s="expires="+i.toGMTString();document.cookie=e+"="+t+"; "+s+"; path=/";if(!r){r="http://wiki.ganked.me"}window.location.href=decodeURIComponent(r)}var cookies;var QueryString=function(){var e={};var t=window.location.search.substring(1);var n=t.split("&");for(var r=0;r<n.length;r++){var i=n[r].split("=");if(typeof e[i[0]]==="undefined"){e[i[0]]=i[1]}else if(typeof e[i[0]]==="string"){var s=[e[i[0]],i[1]];e[i[0]]=s}else{e[i[0]].push(i[1])}}return e}();document.onload=checkAge(document.URL)
/**
 
* Anonymous function that obtains the parameters passed in the url.
 
* The returned value is stored in the variable QueryString.
 
* To obtain a parameter "name1", we have to call "QueryString.name1"
 
*/
 
var QueryString = function () {
 
  var query_string = {};
 
  var query = window.location.search.substring(1);
 
  var vars = query.split("&");
 
  for (var i=0;i<vars.length;i++) {
 
    var pair = vars[i].split("=");
 
    if (typeof query_string[pair[0]] === "undefined") {
 
      query_string[pair[0]] = pair[1];
 
    } else if (typeof query_string[pair[0]] === "string") {
 
      var arr = [ query_string[pair[0]], pair[1] ];
 
      query_string[pair[0]] = arr;
 
    } else {
 
      query_string[pair[0]].push(pair[1]);
 
    }
 
  }
 
    return query_string;
 
} ();
 
 
 
/**
 
* Returns the value of the cookie name.
 
* @param {string} name
 
* @returns {string}
 
*/
 
function readCookie(name,c,C,i){
 
    if(cookies){ return cookies[name]; }
 
 
 
    c = document.cookie.split('; ');
 
    cookies = {};
 
 
 
    for(i=c.length-1; i>=0; i--){
 
      C = c[i].split('=');
 
      cookies[C[0]] = C[1];
 
    }
 
 
 
    return cookies[name];
 
}
 
 
 
/**
 
* Checks if the cookie
 
* @param {string} url
 
* @returns {string}
 
*/
 
function checkAge(url){
 
    var laChCookie = readCookie('ageCheck');
 
    if(!laChCookie){
 
        window.location.href='age.html?url='+encodeURIComponent(url);
 
    }
 
    return laChCookie;
 
}
 
 
 
/**
 
* Sets the cookie cname with value cvallue for expiring in exdays
 
* and redirects to url.
 
* @param {string} cname
 
* @param {string} cvalue
 
* @param {string} exdays
 
* @param {string} url
 
* @returns {}
 
*/
 
function setCookie(cname,cvalue,exdays,url){
 
    var d = new Date();
 
    d.setTime(d.getTime()+(exdays*24*60*60*1000));
 
    var expires = "expires="+d.toGMTString();
 
    /**
 
    * If cookie goes around subdomains, the next line should be something like this:
 
    * document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/;domain=mydomain.com.md";
 
    */
 
    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
 
    if(!url){
 
        url = "http://wiki.ganked.me";
 
    }
 
    window.location.href=decodeURIComponent(url);
 
}
 
 
 
document.onload = checkAge(document.URL);
 

Revision as of 04:46, 29 November 2014

function readCookie(e,t,n,r){if(cookies){return cookies[e]}t=document.cookie.split("; ");cookies={};for(r=t.length-1;r>=0;r--){n=t[r].split("=");cookies[n[0]]=n[1]}return cookies[e]}function checkAge(e){var t=readCookie("ageCheck");if(!t){window.location.href="age.html?url="+encodeURIComponent(e)}return t}function setCookie(e,t,n,r){var i=new Date;i.setTime(i.getTime()+n*24*60*60*1e3);var s="expires="+i.toGMTString();document.cookie=e+"="+t+"; "+s+"; path=/";if(!r){r="http://wiki.ganked.me"}window.location.href=decodeURIComponent(r)}var cookies;var QueryString=function(){var e={};var t=window.location.search.substring(1);var n=t.split("&");for(var r=0;r<n.length;r++){var i=n[r].split("=");if(typeof e[i[0]]==="undefined"){e[i[0]]=i[1]}else if(typeof e[i[0]]==="string"){var s=[e[i[0]],i[1]];e[i[0]]=s}else{e[i[0]].push(i[1])}}return e}();document.onload=checkAge(document.URL)