Jump to content

Մասնակից:AngelaMars/getDatesFromInfoBox.js

Վիքիպեդիայից՝ ազատ հանրագիտարանից

Ծանուցում. Հիշելուց հետո կատարված փոփոխությունները տեսնելու համար մաքրեք ձեր զննարկիչի հիշապահեստը. Mozilla / Firefox / Safari՝ Ctrl+Shift+R (Cmd+Shift+R Mac OS X-ում) Konqueror՝ F5 Opera՝ Tools→Preferences ընտրացանկից։ Internet Explorer՝ Ctrl+F5

/*var WikiAutoDates=WikiAutoDates || {}
 
 WikiAutoDates.getDatesFromInfoBox(text)
{
    men = {
 
        birthdate : {},
        deathdate : {}
    };
 
 
var k=55;
var j = text.search(/Born/i);
 
if(j == -1)
{
    j = text.search(/ծննդյան օր/i);
}
if(j == -1)
   j = text.search(/Ծնվել է`/i);
if( j == -1)
{
    j = text.search(/Ծննդյան ամսաթիվ/i);
    k = 75;
}
if( j == -1)
j = text.search(/birth_date/i);
if( j== -1)
j = text.search(/ծնունդ/i);
 
    //yete voreve mi dzev@ gtel e j-um unenq position-@
if ( j != -1)
{
    var newstring = text.slice(j,j+k); // positionic sksac inchvor yerkarutyamb string enq arandznacnum
    console.log(newstring);
}
var yearpos = newstring.search(/[0-9]{4}/); // 4 erkarutyamb tiv enq pntrum
 
if( yearpos != -1 )//yete tarin gtav
{
    var stryear = newstring.slice(yearpos, yearpos+4);
    men.birthdate.year = parseInt(stryear, 10);
}
var pos = newstring.search(/[0-9]{2}/);
if( pos == yearpos ) //ete tarin skzbum e grac
{
    var otherstr1 = newstring.slice(pos+4, newstring.length); //tarin hanel
    var otherpos1length = otherstr1.search(/[0-9]{1}/);
    var otherpos2length = otherstr1.search(/[0-9]{2}/);
    if(otherpos1length != -1 && otherpos1length == otherpos2length) //yete ka 2 yerkarutyamb tiv
    {
        var otherstr2 = otherstr1.slice(otherpos2length+2,otherstr1.length);
 
        var otherpos1length2 = otherstr2.search(/[0-9]{2}/);
        var otherpos1length1 = otherstr2.search(/[0-9]{1}/);
 
        if( otherpos1length2 != -1 && otherpos1length1 == otherpos1length2) //yete ka yevs 2 yerkarutyamb tiv (aysinqn 2 hat 2 yerk tiv)
        {
           var strmonth = otherstr1.slice(otherpos1length, otherpos1length+2);
            men.birthdate.month = parseInt(strmonth, 10);
            var strday = otherstr2.slice(otherpos1length2, otherpos1length2+2);
            men.birthdate.day = parseInt(strday, 10);
        }
        else
        if(otherpos1length1 != -1 && otherpos1length2 == -1)
        {
            var strmonth = otherstr1.slice(otherpos1length, otherpos1length+2);
            men.birthdate.month = parseInt(strmonth, 10);
            var strday = otherstr2.slice(otherpos1length1, otherpos1length1+1);
            men.birthdate.day = parseInt(strday, 10);
        }
        else
        {
        var strday = otherstr1.slice(otherpos1length, otherpos1length+1);
            men.birthdate.day = parseInt(strday, 10);
        }
 
    }
    else
    if(otherpos1length != -1 && otherpos1length != otherpos2length)
    {
        if(otherpos2length != -1)
        {
            var strmonth = otherstr1.slice(otherpos1length, otherpos1length+1);
            men.birthdate.month = parseInt(strmonth, 10);
            var strday = otherstr1.slice(otherpos2length,otherpos2length+2 );
            men.birthdate.day = parseInt(strday, 10);
        }
        else
        {
            var otherstr2 = otherstr1.slice(otherpos1length+1,otherstr1.length);
            var otherpos1length2 = otherstr2.search(/[0-9]{1}/);
            if(otherpos1length2 != -1)
            {
                var strmonth = otherstr1.slice(otherpos1length, otherpos1length+1);
                men.birthdate.month = parseInt(strmonth, 10);
                var strday = otherstr2.slice(otherpos1length2,otherpos1length2+1 );
                men.birthdate.day = parseInt(strday, 10);
            }
            else
            {
                var strday = otherstr1.slice(otherpos1length,otherpos1length+1 );
                men.birthdate.day = parseInt(strday, 10);
            }
 
        }
    }
 
  }
if(pos < yearpos && pos != -1) //yete tarin verchum e grvac
{
    var strday = newstring.slice(pos, pos+2);
    men.birthdate.day = parseInt(strday, 10);
 
    var otherstr1 = newstring.slice(pos+2,yearpos);
    var otherpos1 = otherstr1.search(/[0-9]{2}/);
    if(otherpos1 != -1)
    {
        var strmonth = otherstr1.slice(otherpos1, otherpos1+2);
        men.birthdate.month = parseInt(strmonth, 10);
    }
}
 
 
 
 
 
    var k=75;
    var j = text.search(/Մահացել է/i);
 
    if(j == -1)
    {
        j = text.search(/մահվան օր/i);
    }
 
    if( j == -1)
    {
        j = text.search(/մահվան ամսաթիվ/i);
    }
    if( j == -1)
        j = text.search(/deathdate/i);
    if( j== -1)
        j = text.search(/մահ/i);
 
    //yete voreve mi dzev@ gtel e j-um unenq position-@
    if ( j != -1)
    {
        var newstring = text.slice(j,j+k); // positionic sksac inchvor yerkarutyamb string enq arandznacnum
        console.log(newstring);
    }
    var yearpos = newstring.search(/[0-9]{4}/); // 4 erkarutyamb tiv enq pntrum
 
    if( yearpos != -1 )//yete tarin gtav
    {
        var stryear = newstring.slice(yearpos, yearpos+4);
        men.deathdate.year = parseInt(stryear, 10);
    }
    var pos = newstring.search(/[0-9]{2}/);
    if( pos == yearpos ) //ete tarin skzbum e grac
    {
        var otherstr1 = newstring.slice(pos+4, newstring.length); //tarin hanel
        var otherpos1length = otherstr1.search(/[0-9]{1}/);
        var otherpos2length = otherstr1.search(/[0-9]{2}/);
        if(otherpos1length != -1 && otherpos1length == otherpos2length) //yete ka 2 yerkarutyamb tiv
        {
            var otherstr2 = otherstr1.slice(otherpos2length+2,otherstr1.length);
 
            var otherpos1length2 = otherstr2.search(/[0-9]{2}/);
            var otherpos1length1 = otherstr2.search(/[0-9]{1}/);
 
            if( otherpos1length2 != -1 && otherpos1length1 == otherpos1length2) //yete ka yevs 2 yerkarutyamb tiv (aysinqn 2 hat 2 yerk tiv)
            {
                var strmonth = otherstr1.slice(otherpos1length, otherpos1length+2);
                men.deathdate.month = parseInt(strmonth, 10);
                var strday = otherstr2.slice(otherpos1length2, otherpos1length2+2);
                men.deathdate.day = parseInt(strday, 10);
            }
            else
            if(otherpos1length1 != -1 && otherpos1length2 == -1)
            {
                var strmonth = otherstr1.slice(otherpos1length, otherpos1length+2);
                men.deathdate.month = parseInt(strmonth, 10);
                var strday = otherstr2.slice(otherpos1length1, otherpos1length1+1);
                men.deathdate.day = parseInt(strday, 10);
            }
            else
            {
                var strday = otherstr1.slice(otherpos1length, otherpos1length+1);
                men.deathdate.day = parseInt(strday, 10);
            }
 
        }
        else
        if(otherpos1length != -1 && otherpos1length != otherpos2length)
        {
            if(otherpos2length != -1)
            {
                var strmonth = otherstr1.slice(otherpos1length, otherpos1length+1);
                men.deathdate.month = parseInt(strmonth, 10);
                var strday = otherstr1.slice(otherpos2length,otherpos2length+2 );
                men.deathdate.day = parseInt(strday, 10);
            }
            else
            {
                var otherstr2 = otherstr1.slice(otherpos1length+1,otherstr1.length);
                var otherpos1length2 = otherstr2.search(/[0-9]{1}/);
                if(otherpos1length2 != -1)
                {
                    var strmonth = otherstr1.slice(otherpos1length, otherpos1length+1);
                    men.deathdate.month = parseInt(strmonth, 10);
                    var strday = otherstr2.slice(otherpos1length2,otherpos1length2+1 );
                    men.deathdate.day = parseInt(strday, 10);
                }
                else
                {
                    var strday = otherstr1.slice(otherpos1length,otherpos1length+1 );
                    men.deathdate.day = parseInt(strday, 10);
                }
 
            }
        }
 
    }
    if(pos < yearpos && pos != -1) //yete tarin verchum e grvac
    {
        var strday = newstring.slice(pos, pos+2);
       men.deathdate.day = parseInt(strday, 10);
 
        var otherstr1 = newstring.slice(pos+2,yearpos);
        var otherpos1 = otherstr1.search(/[0-9]{2}/);
        if(otherpos1 != -1)
        {
            var strmonth = otherstr1.slice(otherpos1, otherpos1+2);
            men.deathdate.month = parseInt(strmonth, 10);
        }
    }
 
    return men;
};
 
function Click(){
    alert(text);
}