MediaWiki:Gadget-syllabusTimetableLinks.js: Difference between revisions
From Warwick Wiki
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
var thisWeekNum; | var thisWeekNum; | ||
var thisWeekYear; | var thisWeekYear; | ||
const weeks = data.weeks; | const weeks = data.weeks; | ||
var i = 0; | var i = 0; | ||
Line 19: | Line 17: | ||
i++; | i++; | ||
} | } | ||
var nextWeekNum; | |||
var nextWeekYear; | |||
foundWeek = false; | foundWeek = false; | ||
while (i < weeks.length && !foundWeek) { | while (i < weeks.length && !foundWeek) { | ||
Line 33: | Line 33: | ||
var thisWeekTT = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=' + thisWeekNum + '">This week</a>'; | var thisWeekTT = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=' + thisWeekNum + '">This week</a>'; | ||
var nextWeekTT = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' +nextWeekYear + '/roomtimetable.asp?id=' + id + '&week=' + nextWeekNum + '">Next week</a>'; | var nextWeekTT = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' +nextWeekYear + '/roomtimetable.asp?id=' + id + '&week=' + nextWeekNum + '">Next week</a>'; | ||
$(obj).html('<b>Timetables</b><br/>' + thisWeekTT + ' ' + nextWeekTT); | |||
var nextYear = String(Number(thisWeekYear.slice(0,2)) + 1) + String(Number(thisWeekYear.slice(2)) + 1); | |||
var termHolidaysTTs; | |||
if (1 <= thisWeekNum && 10 >= thisWeekNum) { | |||
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=1-10">This term</a><br/><a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=11-14">Next vacation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=15-24">Next term</a>'; | |||
} else if (11 <= thisWeekNum && 14 >= thisWeekNum) { | |||
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=11-14">This vaccation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=15-24">Next term</a>'; | |||
} else if (15 <= thisWeekNum && 24 >= thisWeekNum) { | |||
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=15-24">This term</a><br/><a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=25-29">Next vacation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=30-39">Next term</a>'; | |||
} else if (25 <= thisWeekNum && 29 >= thisWeekNum) { | |||
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=25-29">This vaccation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=30-39">Next term</a>'; | |||
} else if (30 <= thisWeekNum && 39 >= thisWeekNum) { | |||
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=30-39">This term</a><br/><a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=40-53">Next vacation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + nextYear + '/roomtimetable.asp?id=' + id + '&week=1-10">Next term</a>'; | |||
} else if (40 <= thisWeekNum && 53 >= thisWeekNum) { | |||
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=40-53">This vaccation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + nextYear + '/roomtimetable.asp?id=' + id + '&week=1-10">Next term</a>'; | |||
} | |||
$(obj).html('<b>Timetables</b><br/>' + thisWeekTT + ' ' + nextWeekTT + '<br/>' + termHolidaysTTs); | |||
}); | }); | ||
}); | }); | ||
}); | }); |
Latest revision as of 14:23, 31 August 2025
mw.hook('wikipage.content').add(function(){
const today = new Date();
$.getJSON( "https://warwick-wiki.containers.uwcs.co.uk/wiki/MediaWiki:Tabula-weeks.json?action=raw", function( data ) {
var thisWeekNum;
var thisWeekYear;
const weeks = data.weeks;
var i = 0;
var foundWeek = false;
while (i < weeks.length && !foundWeek) {
var startDate = new Date(weeks[i].start);
var endDate = new Date(weeks[i].end + "T24:00:00Z");
if (weeks[i].weekNumber > 0 && startDate < today && endDate >= today) {
thisWeekNum = weeks[i].weekNumber;
thisWeekYear = weeks[i].academicYear.replace("/", "");
foundWeek = true;
}
i++;
}
var nextWeekNum;
var nextWeekYear;
foundWeek = false;
while (i < weeks.length && !foundWeek) {
if (weeks[i].weekNumber > 0) {
nextWeekNum = weeks[i].weekNumber;
nextWeekYear = weeks[i].academicYear.replace("/", "");
foundWeek = true;
}
i++;
}
$('.syllabus-timetable-links').each(function(i, obj) {
var id = $(obj).data('syllabus-id');
var thisWeekTT = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=' + thisWeekNum + '">This week</a>';
var nextWeekTT = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' +nextWeekYear + '/roomtimetable.asp?id=' + id + '&week=' + nextWeekNum + '">Next week</a>';
var nextYear = String(Number(thisWeekYear.slice(0,2)) + 1) + String(Number(thisWeekYear.slice(2)) + 1);
var termHolidaysTTs;
if (1 <= thisWeekNum && 10 >= thisWeekNum) {
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=1-10">This term</a><br/><a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=11-14">Next vacation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=15-24">Next term</a>';
} else if (11 <= thisWeekNum && 14 >= thisWeekNum) {
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=11-14">This vaccation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=15-24">Next term</a>';
} else if (15 <= thisWeekNum && 24 >= thisWeekNum) {
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=15-24">This term</a><br/><a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=25-29">Next vacation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=30-39">Next term</a>';
} else if (25 <= thisWeekNum && 29 >= thisWeekNum) {
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=25-29">This vaccation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=30-39">Next term</a>';
} else if (30 <= thisWeekNum && 39 >= thisWeekNum) {
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=30-39">This term</a><br/><a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=40-53">Next vacation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + nextYear + '/roomtimetable.asp?id=' + id + '&week=1-10">Next term</a>';
} else if (40 <= thisWeekNum && 53 >= thisWeekNum) {
termHolidaysTTs = '<a href="https://timetablingmanagement.warwick.ac.uk/SWS' + thisWeekYear + '/roomtimetable.asp?id=' + id + '&week=40-53">This vaccation</a> <a href="https://timetablingmanagement.warwick.ac.uk/SWS' + nextYear + '/roomtimetable.asp?id=' + id + '&week=1-10">Next term</a>';
}
$(obj).html('<b>Timetables</b><br/>' + thisWeekTT + ' ' + nextWeekTT + '<br/>' + termHolidaysTTs);
});
});
});