- 帖子
- 31
- 积分
- 42
- 技术
- 1
- 捐助
- 0
- 注册时间
- 2011-7-27
|
3楼
发表于 2012-11-20 00:13
| 只看该作者
Main();
function Main()
{
while(1)
{
var clock=new Clock();
clock.Main();
}
}
function Clock()
{
this.TimeList=new Array();
//Public methods
this.GetCommand=function()
{
var cmdstr=InputBox("请设定提醒时间(中英文标点皆可): "+
'如:"10,3;12;12:30:22;30,2" 表示:'+
"先每十分钟提醒一次,提醒三次;然后"+
"12分钟提醒一次,只提醒一次;12:30:22提醒"+
"一次;然后每三十分钟提醒一次,提醒两次","时间设定:","10,5");
if(cmdstr=="")WScript.Quit();
return cmdstr;
}
this.DellCommand=function(str)
{
var re=/;/g;str=str.replace(re,";");
re=/:/g;str=str.replace(re,":");
re=/,/g;str=str.replace(re,",");
re=null;
var now=new Date(),ms=0,s="";
s=now.getYear()+"/"+(now.getMonth()+1)+"/"+now.getDate()+" ";
var list=str.split(";");
for(i=0;i<list.length;i++)
{
if(list[i].indexOf(":")>=0)
this.TimeList[this.TimeList.length]=new Date(s+list[i]);
if(list[i].indexOf(",")>=0)
{
var x=list[i].split(",");
for(j=0;j<new Number(x[1]);j++)
{
ms+=60000*x[0];
this.TimeList[this.TimeList.length]=new Date(now.getTime()+ms);
}
}
if((list[i].indexOf(":")==-1)&&(list[i].indexOf(",")==-1))
{
ms+=60000*list[i];
this.TimeList[this.TimeList.length]=new Date(now.getTime()+ms);
}
}
this.TimeList.sort();
}
this.Wait=function(t)
{
while(1)
{
var now=new Date();
if(now.getTime()>=t.getTime())
{
this.Warning();
break;
}
else
WScript.Sleep(200);
};
}
this.Warning=function()
{
var ws=new ActiveXObject("WScript.Shell"),now=new Date();
var btn=ws.Popup("老大,时间到了!"+String.fromCharCode(13,10,13,10)+
"现在时间是:"+now.toLocaleString(),5,"提醒:",65);
if(btn==2) WScript.Quit();
}
this.Main=function()
{
var cmdstr=this.GetCommand();
this.DellCommand(cmdstr);
for(var i in this.TimeList)
this.Wait(this.TimeList[i]);
}
//Private methods
function InputBox(prompt, title, def)
{
if(title == undefined) title = "";
if(def == undefined) def = "";
var re=/\"/g;prompt=prompt.replace(re,'"+"');
var sc = new ActiveXObject("MSScriptControl.ScriptControl");
var code = 'InputBox("'+ prompt + '","' + title + '","' + def + '")';
sc.Language = "VBScript";
result = sc.Eval(code);
sc=null;
if(result != undefined) return result;
else return "";
}
} |
|