Guest User

Untitled

a guest
Oct 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. function parseUrnik() {
  2. const weekDays = ['MON', 'TUE', 'WED', 'THU', 'FRI'];
  3.  
  4. const getSubjectName = (fullName) => {
  5. const nameCutStart = fullName.search(new RegExp('[^a-zA-Z0-9]'));
  6. return fullName.substring(0, nameCutStart);
  7. }
  8.  
  9. const allocateds = document.querySelectorAll('.allocated');
  10.  
  11. return [...allocateds].map(el => {
  12. // Name from the cell
  13. const fullName = el.querySelector('.activity').innerHTML;
  14. const subject = getSubjectName(fullName);
  15. // Additional info from cell
  16. const classroom = el.querySelector('.classroom').innerHTML;
  17. const teacher = el.querySelector('.teacher').innerHTML;
  18. const length = el.attributes.getNamedItem('rowSpan').value;
  19. const type = el.classList.contains('P') ? 'P' : 'LV';
  20. const day = [...el.classList].filter(className => weekDays.indexOf(className) != -1)[0];
  21.  
  22. // Get hour by looking at parent
  23. const hour = el.parentElement.querySelector('.hour').innerHTML;
  24.  
  25. return {
  26. 'fullName': fullName,
  27. 'subject': subject,
  28. 'classroom': classroom,
  29. 'teacher': teacher,
  30. 'length': length,
  31. 'type': type,
  32. 'day': day,
  33. 'hour': hour,
  34. };
  35. });
  36. }
Add Comment
Please, Sign In to add comment