/*!
 * Youbi Checker for Photoshop
 * Copyright iwb.jp
 * Released under the MIT license
 * https://iwb.jp/photoshop-date-youbi-checker-jsx-script/
 */
 if(app.documents.length===0)alert("PSD\u30d5\u30a1\u30a4\u30eb\u304c\u958b\u304b\u308c\u3066\u3044\u307e\u305b\u3093\u3002");else{var df=function(txt){var result="";result=txt.replace(/[\r\n]/g,"");result=result.replace(/,/g,"");var aaa=["sun","mon","tue","wed","thu","fri","sat"];var bbb=["(\u65e5)","(\u6708)","(\u706b)","(\u6c34)","(\u6728)","(\u91d1)","(\u571f)"];for(var i=0;i<bbb.length;i++){var re=new RegExp(aaa[i],"gi");result=result.replace(re,bbb[i])}var aa=["\u4e09\u5341","\u4e8c\u5341","\u5341",
 "\u96f6","\u3007","\u4e00","\u4e8c","\u4e09","\u56db","\u4e94","\u516d","\u4e03","\u516b","\u4e5d"];var bb=["3","2","1","0","0","1","2","3","4","5","6","7","8","9"];for(var i=0;i<bb.length;i++){var re=new RegExp(aa[i],"g");result=result.replace(re,bb[i])}var a=["\uff10","\uff11","\uff12","\uff13","\uff14","\uff15","\uff16","\uff17","\uff18","\uff19"];var b=["0","1","2","3","4","5","6","7","8","9"];for(var i=0;i<b.length;i++){var re=new RegExp(a[i],"g");result=result.replace(re,b[i])}result=result.match(/(?:\d{4}[\/\.\-\u5e74])?\d{1,2}[\/\.\-\u6708]\d{1,2}\u65e5?\s?.[\u65e5\u6708\u706b\u6c34\u6728\u91d1\u571f]./g);
 return result};var dc=function(targetDocument){var now=new Date;var nowYear=now.getFullYear();var resultText="\u66dc\u65e5\u30c1\u30a7\u30c3\u30af\u7d50\u679c\n";var isError=false;var layers=targetDocument.layers;for(var layerIndex=0;layerIndex<layers.length;layerIndex++){var currentLayer=layers[layerIndex];if(currentLayer.typename==="LayerSet")dc(currentLayer);else if(currentLayer.visible&&currentLayer.kind==LayerKind.TEXT){var text=currentLayer.textItem.contents;var aaa=["sun","mon","tue","wed",
 "thu","fri","sat"];var bbb=["(\u65e5)","(\u6708)","(\u706b)","(\u6c34)","(\u6728)","(\u91d1)","(\u571f)"];for(var i=0;i<bbb.length;i++){var re=new RegExp(aaa[i],"gi");text=text.replace(re,bbb[i])}var aa=["\u4e09\u5341","\u4e8c\u5341","\u5341","\u96f6","\u3007","\u4e00","\u4e8c","\u4e09","\u56db","\u4e94","\u516d","\u4e03","\u516b","\u4e5d"];var bb=["3","2","1","0","0","1","2","3","4","5","6","7","8","9"];for(var i=0;i<bb.length;i++){var re=new RegExp(aa[i],"g");text=text.replace(re,bb[i])}var a=["\uff10",
 "\uff11","\uff12","\uff13","\uff14","\uff15","\uff16","\uff17","\uff18","\uff19"];var b=["0","1","2","3","4","5","6","7","8","9"];for(var i=0;i<b.length;i++){var re=new RegExp(a[i],"g");text=text.replace(re,b[i])}var d=text.match(/(?:\d{4}[\/\.\-\u5e74])?\d{1,2}[\/\.\-\u6708]\d{1,2}\u65e5?\s?.([\u65e5\u6708\u706b\u6c34\u6728\u91d1\u571f])./g);var day;var dv=function(d){d=String(d);d=d.replace("0","\u65e5").replace("1","\u6708").replace("2","\u706b").replace("3","\u6c34").replace("4","\u6728").replace("5",
 "\u91d1").replace("6","\u571f");return d};if(d!==null)for(var j=0;j<d.length;j++){d[j]=d[j].replace(/\.|\-/g,"/");var cd=d[j].replace(/\s+$/g,"").replace(/...$/g,"").replace(/[\u5e74\u6708]/g,"/").replace(/\u65e5/g,"").replace(/(\d{4})\/(\d{1,2})\/(\d{1,2})/g,"$2/$3/$1");var dayArr;if(~cd.indexOf("/"))dayArr=cd.split("/");if(dayArr.length===2){var nowMonth=now.getMonth()+1;var nowDate=now.getDate();if(cd.length<=5){var YEAR;if(dayArr[0]<nowMonth||dayArr[0]==nowMonth&&dayArr[1]<nowDate)YEAR=now.getFullYear()+
 1;else YEAR=now.getFullYear();cd+="/"+YEAR}}var cdd=(new Date(cd)).getDay();if(d[j].match(/\u65e5.$/g))day=0;else if(d[j].match(/\u6708.$/g))day=1;else if(d[j].match(/\u706b.$/g))day=2;else if(d[j].match(/\u6c34.$/g))day=3;else if(d[j].match(/\u6728.$/g))day=4;else if(d[j].match(/\u91d1.$/g))day=5;else if(d[j].match(/\u571f.$/g))day=6;if(cdd!==day){isError=true;resultText+=df(currentLayer.textItem.contents)[j]+"\u306f"+"("+dv(cdd)+")"+"\u304c\u6b63\u3057\u3044\u3067\u3059\u3002\n"}}}}if(layers.length!==
 1)isError?alert(resultText):alert(resultText+="\n\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002")};dc(app.activeDocument)};
