-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (60 loc) · 2.2 KB
/
script.js
File metadata and controls
70 lines (60 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function ready(quarterStart) { // Load the function after DOM ready.
if(!document.getElementById("list-id-table")) return;
var tt = document.getElementById("list-id-table").rows;
var table = [];
for (var i = 1; i < tt.length; i++) {
var r = [];
for (var j = 0; j < 22; j++) {
var temp = tt[i].cells[j]
if((j == 9 || j == 10) && temp.hasChildNodes()){
temp = temp.childNodes[0];
}
r.push(temp.innerHTML);
}
table.push(r);
}
var dLookup = {'MO':1, 'TU': 2, 'WE':3, 'TH':4, 'FR':5};
var tpattern = "(.*):(.*)(a|p)-(.*):(.*)(a|p)";
var cal = ics();
for (var i = 0; i < table.length; i++) {
var subject, description, location, begin, end, count, rrule, byday, timeDetails;
var beginDate = new Date(quarterStart);
subject = table[i][0].trim();
if(subject == "") continue;
description = table[i][1].trim();
location = table[i][9] + table[i][10];
byday = table[i][7].split(/(?=[A-Z])/);
byday = byday.map(function(x){
switch(x) {
case 'M': return 'MO';
case 'W': return 'WE';
case 'F': return 'FR';
default: return x.toUpperCase();
}
})
count = 10*byday.length;
timeDetails = table[i][8].trim().match(tpattern);
if(timeDetails[3]=='p' && timeDetails[1]!='12') { timeDetails[1] = String(parseInt(timeDetails[1])+12);}
if(timeDetails[6]=='p' && timeDetails[4]!='12') { timeDetails[4] = String(parseInt(timeDetails[4])+12);}
beginDate.setDate(beginDate.getDate() + (dLookup[byday[0]] - beginDate.getDay()) % 7);
begin = beginDate.setHours(timeDetails[1],timeDetails[2]);
end = beginDate.setHours(timeDetails[4],timeDetails[5]);
rrule = {"freq":"WEEKLY", "count":count, "byday":byday};
console.log("adding event: "+subject+ " in " + location + " at " + begin.toString()+ " to "+ end.toString());
console.log("Repeat every " + byday);
cal.addEvent(subject, description, location, begin, end, rrule);
}
cal.download("webreg");
}
// document.onload = ready();
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab? "from a content_scripts" + sender.tab.url: "from the extension");
if(request.ok == "ok"){
ready(request.date);
}
else {
sendResponse({ack:"nck"});
}
}
);