Nedan är javascriptet som används i mitt Samurize skrivbord. Går det att exekvera detta på en ASP sida? Hur anropar man skriptet?
/*****************************************************************************************\
| This GetTVscript is written by kael |
\*****************************************************************************************/
var showTime = true ;// Option to show the time in the output (true or false)
var timeDelimiter = ":" ;// Option what to separate hours and minutes with(":" "." or what you want)
var timeProgramSeparator = " " ;// Option what to separate time and program with
var noProgramYet = "Inget program" ;// The text showing when there are no program yet
var noProgramNow = "Sändningsuppehåll" ;// The text showing when there are no program right now
var noProgramEnd = "Sändningsslut" ;// The text showing when there are no program any more
//To use multiple lines in output, edit this function for your pleasure ("\r\n" is a new line)
/* // and remove this line
function GetMyTV()
{
return "SVT1: "+GetSVT1()+"\r\n"+"SVT2: "+GetSVT2()+"\r\n"+"TV3: "+GetTV3()+"\r\n"+"TV4: "+GetTV4();
}
*/ // and this one
function GetSVT1() { return GetTV_(21, 0); }
function GetBarSVT1() { return GetBar_(21); }
function GetNextSVT1() { return GetTV_(21, 1); }
function GetSVT2() { return GetTV_(22, 0); }
function GetBarSVT2() { return GetBar_(22); }
function GetNextSVT2() { return GetTV_(22, 1); }
function GetTV3() { return GetTV_(26, 0); }
function GetBarTV3() { return GetBar_(26); }
function GetNextTV3() { return GetTV_(26, 1); }
function GetTV4() { return GetTV_(27, 0); }
function GetBarTV4() { return GetBar_(27); }
function GetNextTV4() { return GetTV_(27, 1); }
function GetKanal5() { return GetTV_(10, 0); }
function GetBarKanal5() { return GetBar_(10); }
function GetNextKanal5() { return GetTV_(10, 1); }
function GetViasatActionNature() { return GetTV_(28, 0); }
function GetBarViasatActionNature() { return GetBar_(28); }
function GetNextViasatActionNature() { return GetTV_(28, 1); }
function GetZTV() { return GetTV_(42, 0); }
function GetTV_(channel, count)
{
var txt = GetPage_(channel);
if(txt.substr(0,5)=="Error") return txt;
try
{
var now = -1;
var lines = txt.split("\r\n");
for(var i=lines.length-2;i>=0;i--)
{
var time = lines[i].substring(0,5);
_time = new Date();
if((parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2)))<6) _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2))+18,parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
else _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2))-6,parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
_now = new Date();
if(_now.getHours()<6) _now.setHours(_now.getHours()+18);
else _now.setHours(_now.getHours()-6);
if(_time<_now)
{
now = i;
break;
}
}
if((now+count>=0) && (now+count<=lines.length-2))
return lines[now+count];
else
return noProgramYet;
}
catch(e)
{
return "Error parsing file";
}
}
function GetBar_(channel)
{
var txt = GetPage_(channel);
if(txt.substr(0,5)=="Error") return txt;
try
{
var now = -1;
var lines = txt.split("\r\n");
for(var i=lines.length-2;i>=0;i--)
{
var time = lines[i].substring(0,5);
_time = new Date();
if((parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2)))<6) _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2))+18,parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
else _time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2))-6,parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
_now = new Date();
if(_now.getHours()<6) _now.setHours(_now.getHours()+18);
else _now.setHours(_now.getHours()-6);
if(_time<_now)
{
now = i;
break;
}
}
if(now<0 || now>=(lines.length-2))
return 0;
var time1 = lines[now].substring(0,5);
var time1h = time1.substring(0,2);
var time1m = time1.substring(3,5);
var time2 = lines[now+1].substring(0,5);
var time2h = time2.substring(0,2);
var time2m = time2.substring(3,5);
if(time1h<6) time1h=time1h*1+18; else time1h-=6;
if(time2h<6) time2h=time2h*1+18; else time2h-=6;
var totalmins = (time2h-time1h)*60+(time2m-time1m);
var runningminutes = (_now.getHours()-time1h)*60+(_now.getMinutes()-time1m)
return runningminutes/totalmins*100;
}
catch(e)
{
return "Error parsing file";
}
}
function GetPage_(channel)
{
try
{
var fs = new ActiveXObject("Scripting.FileSystemObject");
try
{
var file=fs.GetSpecialFolder(2)+"\\"+channel+".tv";
if(fs.FileExists(file))
{
var f=fs.GetFile(file);
var filetime = new Date(f.DateLastModified);
var now = new Date();
var timeToDownload = new Date();
timeToDownload.setHours(6,15,0);
if(timeToDownload>now || filetime>timeToDownload)
{
var filen = f.OpenAsTextStream(1);
var txt = filen.ReadAll();
filen.Close();
return txt;
}
}
}
catch(e)
{
return "Error reading from file";
}
finally
{
delete filetime;
delete now;
delete timeToDownload;
}
try
{
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.Open("GET","http://www.dagenstv.com/se/chart/?cha="+channel+"&"+Math.random(),false);
http.send();
var html = fixHTMLcodes_(http.responseText);
}
catch(e)
{
return "Error downloading page";
}
finally
{
delete http;
}
try
{
var start = "\r\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
var stop = "</table>";
html = html.substr(html.indexOf(start)+start.length+50);
html = html.substr(0,html.indexOf(stop));
var txt="";
var lines = html.split("\r\n <tr>");
var endtime="";
for(var i=0;i<lines.length;i++)
{
var time = lines[i].substr(lines[i].indexOf(">")+1,5);
var program = lines[i].substr(lines[i].indexOf("charteventname")+30);
program = program.substr(0,program.indexOf("<"));
if(program.indexOf("\r\n")!=-1)
program = program.substr(0,program.indexOf("\r\n"));
if(endtime!="")
{
var _endtime = new Date();
_endtime.setHours(parseInt(endtime.substring(0,1))*10 + parseInt(endtime.substring(1,2)),parseInt(endtime.substring(3,4))*10 + parseInt(endtime.substring(4,5)),0,0);
var _time = new Date();
_time.setHours(parseInt(time.substring(0,1))*10 + parseInt(time.substring(1,2)),parseInt(time.substring(3,4))*10 + parseInt(time.substring(4,5)),0,0);
if(_endtime<_time)
{
if(showTime)
txt+=endtime.substring(0,2)+timeDelimiter+endtime.substring(3,5)+timeProgramSeparator;
txt+=noProgramNow+"\r\n";
}
}
endtime = lines[i].substr(lines[i].indexOf("</span> (")+9,5);
if(endtime.substr(2,1)!=":")
endtime = "";
if(showTime)
txt+=time.substring(0,2)+timeDelimiter+time.substring(3,5)+timeProgramSeparator;
txt+=program+"\r\n";
}
if(endtime!="")
{
var _endtime = new Date();
_endtime.setHours(parseInt(endtime.substring(0,1))*10 + parseInt(endtime.substring(1,2)),parseInt(endtime.substring(3,4))*10 + parseInt(endtime.substring(4,5)),0,0);
var _time = new Date();
_time.setHours(5,59,0);
if(_endtime<_time)
{
if(showTime)
txt+=endtime.substring(0,2)+timeDelimiter+endtime.substring(3,5)+timeProgramSeparator;
txt+=noProgramEnd+"\r\n";
}
}
}
catch(e)
{
return "Error parsing page";
}
try
{
var file=fs.CreateTextFile(file,true);
file.Write(txt);
}
catch(e)
{
return "Error writing to file";
}
finally
{
file.Close();
}
}
catch(e)
{
return "Error creating FileSystemObject";
}
finally
{
delete fs;
}
return txt;
}
function fixHTMLcodes_(str)
{
str = str.replace(/å/g, "å");
str = str.replace(/ä/g, "ä");
str = str.replace(/ö/g, "ö");
//REDIGERAT BORT EN MASSA RADER HÄR - MATTias
return str;
}



