From ea4755fd3078b3dffb79dd4fdd82d4ba51163ab5 Mon Sep 17 00:00:00 2001 From: EthanHarv Date: Tue, 13 Jul 2021 14:54:44 -0500 Subject: [PATCH] Use Fetch instead of XMLHTTPRequest --- slader-limit-bypass/js/quizlet_bypass.js | 35 ++++++++++++++---------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/slader-limit-bypass/js/quizlet_bypass.js b/slader-limit-bypass/js/quizlet_bypass.js index d1bbeab..5ddadbb 100644 --- a/slader-limit-bypass/js/quizlet_bypass.js +++ b/slader-limit-bypass/js/quizlet_bypass.js @@ -12,6 +12,11 @@ function renderBypass() katex_css.setAttribute('href','https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.css '); document.head.appendChild(katex_css); + // Get the webpage data, devoid of any headers or cookies. Acts as if the user is not logged in at all. + doFetch(window.location).then(data => { processData(data); }) + +} +function processData(data){ // Clear the "hidden explanation" out and replace it with a blank explanation area. // The innermost item is ".s1i7awl8" document.querySelector('main .mwhvwas').innerHTML = '

Explanation

'; @@ -19,9 +24,6 @@ function renderBypass() // Render new stuff - // Get the webpage data, devoid of any headers or cookies. Acts as if the user is not logged in at all. - var data = httpGet(window.location); - // Is this an abomination? Yes. // Does it work? Also yes. // @@ -29,8 +31,8 @@ function renderBypass() // // I don't want to talk about it. // - var b = data.match(/(?<=window.Quizlet\["questionDetailsPageData"] = ).+?(?=; QLoad\("Quizlet.questionDetailsPageData")/gm); - if (!b) + var json = data.match(/(?<=window.Quizlet\["questionDetailsPageData"] = ).+?(?=; QLoad\("Quizlet.questionDetailsPageData")/gm); + if (!json) { if (window.location.toString().includes('quizlet.com/explanations/textbook-solutions')) { @@ -48,7 +50,7 @@ function renderBypass() // Parse JSON data - var qDetails = JSON.parse(b[0]); + var qDetails = JSON.parse(json[0]); // Display JSON data as answer qDetails.question.solutions.forEach(solution => { @@ -103,15 +105,20 @@ function renderBypass() }); }; - - -// Handle GET request -function httpGet(url) +async function doFetch(url) { - var req = new XMLHttpRequest(); - req.open( "GET", url, false ); // false -> synchronous request - req.send( null ); - return req.responseText; + const response = await fetch(url, { + method: 'GET', // *GET, POST, PUT, DELETE, etc. + mode: 'cors', // no-cors, *cors, same-origin + cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached + credentials: 'omit', // include, *same-origin, omit + headers: { + }, + redirect: 'follow', // manual, *follow, error + referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url + body: null // body data type must match "Content-Type" header + }); + return response.text(); }