Last active
April 30, 2024 19:21
-
-
Save Apearson75/2247c8190d797ed9427bd36e5a0c7c95 to your computer and use it in GitHub Desktop.
Mathswatch Answer Viewer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:function getCookie(e){const t=`; ${document.cookie}`.split(`; ${e}=`);if(2===t.length)return t.pop().split(";").shift()}async function getRequest(e,t){const s=await fetch(e,{headers:{accept:"*/*","accept-language":"en-GB,en-US;q=0.9,en;q=0.8","cache-control":"no-cache",pragma:"no-cache","sec-ch-ua":'"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-origin","x-csrf-token":getCookie("_csrf")},referrer:t,referrerPolicy:"strict-origin-when-cross-origin",body:null,method:"GET",mode:"cors",credentials:"include"});return await s.json()}async function getAnswers(){const e=document.querySelector("#studentmodal > div > div:nth-child(4) > div > div.questioncolumn > div > div.progressblock > div > div.col-sm-10.col-xs-8 > div > div:nth-child(1) > progressbar"),t=currentPage.split("/");let s="Answers Are:";if(100==parseInt(e.getAttribute("value"))&&7==t.length&&"assignment"==t[4]){const e=t[5],n=t[6],c=await getRequest(`https://vle.mathswatch.co.uk/duocms/api/answers?assignedwork_id=${e}`,currentPage);if("success"==c.status){c.data.forEach((e=>{e.question_id==n&&e.answer.forEach((e=>{0!=e.marks&&(e.text.constructor==Array?e.text.forEach((e=>{null!=e&&(s+=`\n${e}`)})):s+=`\n${e.text}`)}))}))}return[s,n]}return null}let currentPage=location.href;setInterval((async function(){if(currentPage!=location.href){currentPage=location.href;const[e,t]=await getAnswers(),s=document.querySelector("#studentmodal > div > div:nth-child(4) > div > div > div > div.row > div");if(null!=e){s.innerHTML="";const n=document.createElement("img");n.src=`https://vle.mathswatch.co.uk/images/questions/question${t}.png`,n.className="col-sm-offset-3 col-sm-6 col-xs-12",s.appendChild(n);const c=document.createElement("p");c.innerText+=e,c.className="col-sm-offset-3 col-sm-6 col-xs-12",c.style.fontWeight=700,c.style.fontSize="x-large",s.appendChild(c)}}}),500),console.log("Answer Viewer should be ready: ✅"),alert("Answer Viewer should be ready: ✅\nReloading the page will remove the script."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval(await (await fetch('https://gist.githubusercontent.com/Apearson75/2247c8190d797ed9427bd36e5a0c7c95/raw/fb1b3e94db7513babb8dee450e2bd478b0af9988/mini.js')).text()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCookie(name) { | |
const value = `; ${document.cookie}`; | |
const parts = value.split(`; ${name}=`); | |
if (parts.length === 2) return parts.pop().split(';').shift(); | |
} | |
async function getRequest(url, referrer) { | |
const req = await fetch(url, { | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8", | |
"cache-control": "no-cache", | |
"pragma": "no-cache", | |
"sec-ch-ua": "\"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"", | |
"sec-ch-ua-mobile": "?0", | |
"sec-ch-ua-platform": "\"Windows\"", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin", | |
"x-csrf-token": getCookie('_csrf') | |
}, | |
"referrer": referrer, | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": null, | |
"method": "GET", | |
"mode": "cors", | |
"credentials": "include" | |
}); | |
const json = await req.json(); | |
return json; | |
} | |
async function getAnswers() { | |
const progressBar = document.querySelector("#studentmodal > div > div:nth-child(4) > div > div.questioncolumn > div > div.progressblock > div > div.col-sm-10.col-xs-8 > div > div:nth-child(1) > progressbar"); | |
const parsedURL = currentPage.split('/'); | |
let answers = 'Answers Are:'; | |
if (parseInt(progressBar.getAttribute('value')) == 100 && parsedURL.length == 7 && parsedURL[4] == "assignment") { | |
const assignmentId = parsedURL[5]; | |
const questionId = parsedURL[6]; | |
const req = await getRequest(`https://vle.mathswatch.co.uk/duocms/api/answers?assignedwork_id=${assignmentId}`, currentPage); | |
if (req.status == "success") { | |
const questions = req.data; | |
questions.forEach(q => { | |
if (q.question_id == questionId) { | |
q.answer.forEach(a => { | |
if (a.marks!=0) { | |
if (a.text.constructor == Array) { | |
a.text.forEach(multipleAnswer => { | |
if (multipleAnswer != null) { | |
answers += `\n${multipleAnswer}`; | |
} | |
}) | |
} else { | |
answers += `\n${a.text}`; | |
} | |
} | |
}) | |
} | |
}); | |
} | |
return [answers, questionId]; | |
} | |
return null; | |
} | |
let currentPage = location.href; | |
setInterval(async function() | |
{ | |
if (currentPage != location.href) | |
{ | |
currentPage = location.href; | |
const [answers, questionId] = await getAnswers(); | |
const theBox = document.querySelector("#studentmodal > div > div:nth-child(4) > div > div > div > div.row > div"); | |
if (answers != null) { | |
theBox.innerHTML = ''; | |
const questionImage = document.createElement('img'); | |
questionImage.src = `https://vle.mathswatch.co.uk/images/questions/question${questionId}.png`; | |
questionImage.className="col-sm-offset-3 col-sm-6 col-xs-12"; | |
theBox.appendChild(questionImage); | |
const answerThing = document.createElement('p'); | |
answerThing.innerText += answers; | |
answerThing.className="col-sm-offset-3 col-sm-6 col-xs-12"; | |
answerThing.style.fontWeight = 700; | |
answerThing.style.fontSize = "x-large" | |
theBox.appendChild(answerThing); | |
} | |
} | |
}, 500); | |
console.log("Answer Viewer should be ready: ✅"); | |
alert("Answer Viewer should be ready: ✅\nReloading the page will remove the script."); |
Oh it hasn't for me.
Sent from Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Apearson75 ***@***.***>
Sent: Thursday, January 25, 2024 10:11:46 PM
To: Apearson75 ***@***.***>
Cc: Comment ***@***.***>
Subject: Re: Apearson75/mini.js
@Apearson75 commented on this gist.
________________________________
does this actually work
yeah
—
Reply to this email directly, view it on GitHub<https://gist.github.com/Apearson75/2247c8190d797ed9427bd36e5a0c7c95#gistcomment-4851621> or unsubscribe<https://github.com/notifications/unsubscribe-auth/BEZVH3CFSD63ZXRLQIQCHJTYQLKCFBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTENJRG43DCMBWU52HE2LHM5SXFJTDOJSWC5DF>.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
not work because the api doesnt cointain the answer, is there any solution?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah