Open grimsteel opened 11 months ago
Done!
Bookmarklet 1 (run on HAC Homepage)
javascript:(function(){if(window.location.href!=='https://accesscenter.roundrockisd.org/HomeAccess/Home/WeekView'){alert("You must be on RRISD's HAC, on the Home Page.");return;}const gT=el=>el.innerText,gC=el=>(el.querySelector('div span')?.innerText||'').replace(/\(|\)/g,'').split(' ')[0].slice(0,-1),data=JSON.stringify(Array.from(document.querySelectorAll('[id=average]'),gT).map((item,index)=>({courseId:gC(document.querySelectorAll('.sg-5px-margin')[index+1]),average:parseFloat(item),credits:0.5}))),el=document.createElement('textarea');el.value=data;document.body.appendChild(el);el.select();document.execCommand('copy');document.body.removeChild(el);alert("Grades and courses copied! Go to the GPA Calculator and click on Bookmark 2.");})();
Bookmarklet 2 (run on GPA Calculator)
javascript:(function(){const currentUrl=window.location.href;if(!currentUrl.startsWith('https://gpa.ruhangupta.com')&&!currentUrl.startsWith('http://localhost:5173')){alert("You must be on the GPA Calculator (gpa.ruhangupta.com).");return;}const str=prompt("Please paste the text that you got from the first bookmarklet. It should already be copied to your clipboard.");localStorage.setItem('saved-courses',str);location.reload();})();
TODO: Add to website
This is a slightly shorter version of #1:
javascript:(()=>{if("https://accesscenter.roundrockisd.org/HomeAccess/Home/WeekView"!==window.location.href){alert("You must be on RRISD's HAC, on the Home Page.");return}let e=JSON.stringify([].map.call(document.querySelectorAll("[id=average]"),(e,r)=>({courseId:document.querySelector(`tr:nth-child(${r+1}) .sg-5px-margin div span`)?.innerText.match(/\((.+)[A-Z] - \d+\)/)?.[1]||"",average:parseFloat(e.innerText),credits:.5})));navigator.clipboard.writeText(e).then(()=>alert("Grades and courses copied! Go to the GPA Calculator and click on Bookmark 2."))})();
But I really think we should use an iframe so they only have to use 1 bookmarklet
Make an iframe
of HAC in the gpa calculator?
Make an iframe of the gpa calculator (just a minimal page that responds to window.onmessage and saves it to localstorage)
In the bookmarklet we would use postMessage to send a message to the iframe
Something like this:
const el = document.body.appendChild(document.createElement("iframe"));
el.src = "https://gpa.ruhangupta.com/hac-import.html";
el.hidden = true; // I'm not sure if this will make it not load at all. If it does, then something like width = 0, height = 0
el.onload = () => {el.contentWindow.postMessage(data, "https://gpa.ruhangupta.com");el.remove();};
Add a modal that has instructions on how to get your courses from HAC. (Something that involves pasting the course ID into the search box because that's more reliable than the course name)
We could also have a bookmarklet that people run on hac which just autoimports the courses and grades into the localstorage with an iframe
Schoology also has the section IDs so we could also theoretically have a schoology app that does it