🏠 Home 

Greasy Fork is available in English.

Almascript - Unreported Absense Helper

Show homeroom for unreported absenses

  1. // ==UserScript==
  2. // @name Almascript - Unreported Absense Helper
  3. // @namespace https://greasyfork.org/en/users/8332-sreyemnayr
  4. // @version 2019.8.27.1
  5. // @description Show homeroom for unreported absenses
  6. // @author Ryan Meyers
  7. // @author You
  8. // @match https://sges.getalma.com/reports/school-attendance?date=*
  9. // @grant none
  10. // ==/UserScript==
  11. function clearBody(body) {
  12. body = body.replace(/src=/g,"data-src=");
  13. body = body.replace(/<link/g, "nolink");
  14. return body;
  15. }
  16. async function fetchAndUpdate(node) {
  17. const updateNode = node;
  18. // https://sges.getalma.com/reports/school-attendance?date=2019-08-27&status=255
  19. // https://sges.getalma.com/student/5d165b14749ea438fa6dc7ff/attendance?week=2019-W35
  20. // https://sges.getalma.com/home/get-student-schedule?studentId=5d165b14749ea438fa6dc7ff&date=2019-08-28
  21. var url=node.href.replace(/student\//g, "home/get-student-schedule?studentId=");
  22. url = url.replace(/\/attendance.*/g,"&"+document.location.search.replace(/\?/g,"&"));
  23. if (["PS1","PS2","PK3"].indexOf(updateNode.parentElement.parentElement.children[2].innerText.trim()) <= -1) {
  24. console.log(updateNode.parentElement.parentElement.children[2].innerText);
  25. fetch(url)
  26. .then(function(response) {
  27. return response.json();
  28. })
  29. .then(function(body) {
  30. body = clearBody(body.Message.html);
  31. var parser = new DOMParser();
  32. var doc = parser.parseFromString(body, "text/html");
  33. var n = nodesFromXpath("//div[@class='class-info']", doc);
  34. //console.log(n[0]);
  35. //console.log(node.textContent.trim());
  36. //var newNode = document.createElement("div");
  37. //newNode.classList.add("pill");
  38. //newNode.innerHTML =
  39. // '<i class="far fa-times-circle" style="color:#eb6841;"></i>' +
  40. // node.textContent.trim();
  41. updateNode.parentElement.parentElement.children[4].append(n[0]);
  42. });
  43. }
  44. }
  45. function nodesFromXpath(xpath, doc=document) {
  46. // var xpath = "//tr[td[text()='No Record']]/td[2]/a";
  47. var r###lt = document.evaluate(
  48. xpath,
  49. doc,
  50. null,
  51. XPathR###lt.ANY_TYPE,
  52. null
  53. );
  54. var node,
  55. nodes = [];
  56. while ((node = r###lt.iterateNext())) {
  57. nodes.push(node);
  58. }
  59. return nodes;
  60. }
  61. async function doIncomplete() {
  62. for (let node of nodesFromXpath("//tr[td[span[@class='attendance-nottaken']]]/td[2]/a[1]")) {
  63. await fetchAndUpdate(node);
  64. //console.log(node);
  65. }
  66. }
  67. (async function() {
  68. 'use strict';
  69. var newStyle = document.createElement("style");
  70. newStyle.innerHTML = `
  71. .pill {
  72. background-color: #fff;
  73. padding: .5em;
  74. border-radius: 5px;
  75. display: inline-block;
  76. cursor: default;
  77. margin-top: 1em;
  78. font-size: 8pt;
  79. }
  80. .pure-button-pdf { color: #eb6841; background: #fff; padding: 0.1em;}
  81. .pdfIcon { margin-left:2px; margin-right:2px;}
  82. .lds-circle { display: inline-block; transform: translateZ(1px); }
  83. .lds-circle { display: inline-block; animation: lds-circle 2.4s cubic-bezier(0, 0.2, 0.8, 1) infinite; }
  84. @keyframes lds-circle { 0%, 100% { animation-timing-function: cubic-bezier(0.5, 0, 1, 0.5); } 0% { transform: rotateY(0deg); } 50% { transform: rotateY(1800deg); animation-timing-function: cubic-bezier(0, 0.5, 0.5, 1); } 100% { transform: rotateY(3600deg); } }
  85. .class-info {
  86. flex-grow:1;
  87. padding-right: 0.75em;
  88. }
  89. .class-grade {
  90. flex: 0 0 50px;
  91. text-align: center;
  92. font-size: 1.5em;
  93. color: #888;
  94. }
  95. .class-grade small {
  96. display: block;
  97. font-size: .6em;
  98. }
  99. .class-info > span {
  100. font-size: .9em;
  101. color: #888;
  102. margin-right: 1em;
  103. white-space: nowrap;
  104. }
  105. .class-name {
  106. margin: 0 0 0.2em 0;
  107. font-size: 1em;
  108. }
  109. `;
  110. document.getElementsByTagName("head")[0].append(newStyle);
  111. await doIncomplete();
  112. // Your code here...
  113. })();