Մասնակից:HrantKhachatrian/getDatesFromArticleText.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.getDatesFromArticleText = function (text) {
//debugger;
var DayObject=function() {
this.day=null;
this.manth=null;
this.year=null;
};
var men={
birth:new DayObject, //ծննդյան տվյալներ
death:new DayObject //մահվան տվյալներ
};
var IndexFirstText=text.indexOf("'''");
var IndexLastText=text.indexOf("==");
var textbiog=text.substring(IndexFirstText,IndexLastText-1); //առանձնացնում ենք կենսագրությունը
var IndexTrait=textbiog.indexOf("-"); //ծննդյան և մահվան տարեթվերը աեանձնացնող - ի ինդեքսը
var Index_II_1_1=textbiog.indexOf("[[");
var Index_II_2_1=textbiog.indexOf("]]");
var textManth=textbiog.substring(Index_II_1_1+2,Index_II_2_1);
var ManthDay=textManth.split(" "); //եթե պռոբել կա կտրում է ըստ նրա
if(ManthDay[1]===null){ // եթե պռոբելից հետո դատարկ է,այսինքն ամսաթիվ չի
var lengManth=0;
for(i=0;i<=9;i++){
if(ManthDay[0].search(i)!=-1){ //եթե այդ հատվածի մեջ թիվ կա
lengManth++;
}
}
if(lengManth){
men.birth.year=ManthDay[0];
}
}else{
men.birth.day=ManthDay[1];
switch(ManthDay[0]){
case "Հունվար":men.birth.manth=1;break;
case "Փետրվար":men.birth.manth=2;break;
case "Մարտ":men.birth.manth=3;break;
case "Ապրիլ":men.birth.manth=4;break;
case "Մայիս":men.birth.manth=5;break;
case "Հունիս":men.birth.manth=6;break;
case "Հուլիս":men.birth.manth=7;break;
case "Օգոստոս":men.birth.manth=8;break;
case "Սեպտեմբեր":men.birth.manth=9;break;
case "Հոկտեմբեր":men.birth.manth=10;break;
case "Նոյեմբեր":men.birth.manth=11;break;
case "Դեկտեմբեր":men.birth.manth=12;break;
default :men.birth.manth=null;
}
}
var textbiog_1=textbiog.substring(Index_II_2_1+2); //առաջին ]]-ից հետո կտրում ենք որպեսզի անցնենք հաջորդ [[-ին
var Index_II_1_2=textbiog_1.indexOf("[[");
var Index_II_2_2=textbiog_1.indexOf("]]");
var textYear=textbiog_1.substring(Index_II_1_2+2,Index_II_2_2);
var Year=textYear.split(" ");
if(Year[1]===null){
var lengYear=Year[0].much(/d/);
if(lengYear.length()){
men.birth.year=Year[0];
}
}else{
men.birth.day=Year[1];
switch(Year[0]){
case "Հունվար":men.birth.manth=1;break;
case "Փետրվար":men.birth.manth=2;break;
case "Մարտ":men.birth.manth=3;break;
case "Ապրիլ":men.birth.manth=4;break;
case "Մայիս":men.birth.manth=5;break;
case "Հունիս":men.birth.manth=6;break;
case "Հուլիս":men.birth.manth=7;break;
case "Օգոստոս":men.birth.manth=8;break;
case "Սեպտեմբեր":men.birth.manth=9;break;
case "Հոկտեմբեր":men.birth.manth=10;break;
case "Նոյեմբեր":men.birth.manth=11;break;
case "Դեկտեմբեր":men.birth.manth=12;break;
default :men.birth.manth=null;
}
}
var textNextTriat=textbiog.substring(IndexTrait);
var Index1_II_1_1=textNextTriat.indexOf("[[");
var Index1_II_2_1=textNextTriat.indexOf("]]");
var textManthDeath=textbiog.substring(Index1_II_1_1+2,Index1_II_2_1);
var ManthDayDeath=textManthDeath.split(" ");
if(ManthDayDeath[1]===null){ // եթե պռոբելից հետո դատարկ է,այսինքն ամսաթիվ չի
var lengManthDeath=0;
for(i=0;i<=9;i++){
if(ManthDayDeath[0].search(i)!=-1){ //եթե այդ հատվածի մեջ թիվ կա
lengManthDeath++;
}
}
if(lengManthDeath){
men.death.year=ManthDayDeath[0];
}
}else{
men.birth.day=ManthDayDeath[0];
switch(ManthDayDeath[1]){
case "Հունվար":men.death.manth=1;break;
case "Փետրվար":men.death.manth=2;break;
case "Մարտ":men.death.manth=3;break;
case "Ապրիլ":men.death.manth=4;break;
case "Մայիս":men.death.manth=5;break;
case "Հունիս":men.death.manth=6;break;
case "Հուլիս":men.death.manth=7;break;
case "Օգոստոս":men.death.manth=8;break;
case "Սեպտեմբեր":men.death.manth=9;break;
case "Հոկտեմբեր":men.death.manth=10;break;
case "Նոյեմբեր":men.death.manth=11;break;
case "Դեկտեմբեր":men.death.manth=12;break;
default :men.death.manth=null;
}
}
var textNextTriat_1=textNextTriat.substring(Index1_II_2_1+3);
var Index1_II_1_2=textNextTriat_1.indexOf("[[");
var Index1_II_2_2=textNextTriat_1.indexOf("]]");
var textYearDeath=textNextTriat_1.substring( Index1_II_1_2+2, Index1_II_2_2);
var YearDeath=textYearDeath.split(" ");
if(YearDeath[1]){
men.death.day=YearDeath[1];
switch (YearDeath[0]){
case "Հունվար":men.death.manth=1;break;
case "Փետրվար":men.death.manth=2;break;
case "Մարտ":men.death.manth=3;break;
case "Ապրիլ":men.death.manth=4;break;
case "Մայիս":men.death.manth=5;break;
case "Հունիս":men.death.manth=6;break;
case "Հուլիս":men.death.manth=7;break;
case "Օգոստոս":men.death.manth=8;break;
case "Սեպտեմբեր":men.death.manth=9;break;
case "Հոկտեմբեր":men.death.manth=10;break;
case "Նոյեմբեր":men.death.manth=11;break;
case "Դեկտեմբեր":men.death.manth=12;break;
default :men.death.manth=null;
}
}else {
/*
var lengYearDeath=0;
for(i=0;i<=9;i++){
if(YearDeath[0].search(i)!=-1){
lengYearDeath++;
}
}
*/
if(YearDeath[0].search(/[0-9]/)!=-1 ){
men.death.year=YearDeath[0];
}
}
return men;
}
function Click(){
alert(text);
}