The problem I have run into seems like it has a simple answer. I want to have my website do the simple task of grabbing a piece of text from a webpage.
I basically want my code to look like...
var str = TextFromWebPage;
The text I want to "grab" is on http://dasd-sharepoint.dasd.org/Schools/STEMAcademy/Pages/default.aspx
If you look on the page (try Control F and search for the current date, Ex: "May-9-2013:") for a list of the next five dates. I want to take that list and use it in variables in Javascript.
So my prefered end result would be
var str = new Array("May-9-2013: “F” Day", "May-10-2013: “G” Day", "May-13-2013: “H” Day", "May-14-2013: “I” Day", "May-15-2013: “J” Day", "May-16-2013: “K” Day");
Purpose: Basically for school I'm always checking the time. So instead of doing the math I make a quick little program that look at the current time vs the time the current class ends. In my school however we have different "letter days" which means class lengths are different on different days. Letter days are based on a 12 day cycle which means. Monday through Friday could be A-E but that would mean the following week Monday would then be F-J. Not to mention if there is a snow day or a day off. So instead of using a calendar I figured there has to be a way I can grab this data from that district webpage and utilize it in the code to automatically check what letter day it is.
Thanks for any and all help!
Here is my code for what I'm doing...
<!DOCTYPE html>
<html>
<head>
//<link rel="stylesheet" type="text/css" href="graphics.css">
<script>
//==========| Data |==========
//These array lists contain the times the class periods start, end, and their title
var Ptest = new Array("starts: 07:25 ends: 15:00 title: Testing", "starts: 07:25 ends: 30:00 title: Testing");
var P14 = new Array("starts: 07:25 ends: 09:00 title: Pd: 1", "starts: 09:04 ends: 10:34 title: Pd: 2", "starts: 10:38 ends: 11:08 title: Lunch", "starts: 11:12 ends: 12:42 title: Pd: 3", "starts: 12:46 ends: 14:23 title: Pd: 4");
var P17 = new Array("starts: 07:25 ends: 08:20 title: Pd: 1", "starts: 08:24 ends: 09:14 title: Pd: 2", "starts: 09:18 ends: 10:08 title: Pd: 3", "starts: 10:12 ends: 11:02 title: Pd: 4", "starts: 11:06 ends: 11:36 title: Lunch", "starts: 11:40 ends: 12:30 title: Pd: 5", "starts: 12:34 ends: 13:24 title: Pd: 6", "starts: 13:28 ends: 14:23 title: Pd: 7");
var P57 = new Array("starts: 07:25 ends: 09:00 title: Pd: 5", "starts: 09:04 ends: 10:34 title: Pd: 6", "starts: 10:38 ends: 11:08 title: Lunch", "starts: 11:12 ends: 12:42 title: Pd: 7", "starts: 12:46 ends: 13:36 title: Advisory", "starts: 13:40 ends: 14:23 title: Seminar");
//---------------------------------
//==========| Variables |==========
var input = P17; //What set of data to use
var currentSlot = 0; //What the current Period is
var over = false; //If the current school day if over
//---------------------------------
//==========| Actions |==========
window.onload=function() {
setInterval(function() {refresh();}, 1); //Loop
}
//---------------------------------
//==========| Core Functions |==========
function refresh() {
display();
updateClock();
}
function display() {
var currentTime = getTime();
var timeInSec = ((parseInt(currentTime.slice(0,2)))*3600)+((parseInt(currentTime.slice(3,5)))*60)+(parseInt(currentTime.slice(6,8)));
if (currentSlot >= input.length) {over = true;}
if (over == false) {
var data = input[currentSlot];
var nextSlot = input[currentSlot + 1];
var PdEndTime = ((parseInt(data.slice(20,23)))*3600)+((parseInt(data.slice(23,25)))*60);
var PdStart = data.slice(8,13);
var PdEnd = data.slice(20,25);
var PdTitle = data.slice(32,data.length);
if (nextSlot!==undefined) {
var NPdStart = nextSlot.slice(8,13);
var NPdEnd = nextSlot.slice(20,25);
var NPdTitle = nextSlot.slice(32,nextSlot.length);
}
var timeLeft = PdEndTime - timeInSec;
var hLeft = Math.floor(timeLeft / 3600);
var mLeft = Math.floor(timeLeft / 60);
var sLeft = Math.floor(timeLeft % 60);
if (hLeft > 0) {mLeft = mLeft - (hLeft*60);}
hLeft = add0(hLeft);
mLeft = add0(mLeft);
sLeft = add0(sLeft);
if (timeInSec > PdEndTime) {currentSlot++;}
document.getElementById("display").innerHTML = PdTitle+" ends at "+PdEnd+", in "+hLeft+":"+mLeft+":"+sLeft;
}
else {document.getElementById("display").innerHTML = "School is over!";}
}
//---------------------------------
//==========| Misc Functions |==========
function getTime() {
var clock = new Date();
var h = clock.getHours();
var m = clock.getMinutes();
var s = clock.getSeconds();
h = add0(h);
m = add0(m);
s = add0(s);
return h+":"+m+":"+s;
}
function updateClock() {
document.getElementById("clock").innerHTML = getTime();
}
function add0(i) {
if (i < 10) {
i = "0"+i;
}
return i;
}
function changeInput(newInput) {
input = newInput;
currentSlot = 0;
}
//---------------------------------
</script>
</head>
<body>
<p id="clock" class="textCenter"></p>
<p id="display" class="textCenter"></p>
<p class="textCenter">
<input type="button" onClick="changeInput(P14)" value="1-4 Block">
<input type="button" onClick="changeInput(P17)" value="1-7 Normal">
<input type="button" onClick="changeInput(P57)" value="5-7 Block">
</p>
</body>
</html>
I want it to simply automatically check what letter day it is so You don't have to have the users click the buttons. For example A-day = 1-7, B-Day = 1-4, C-day = 1-7, D-day = 5-7