mirror of
https://github.com/lebr0nli/slader-extension.git
synced 2025-05-10 18:42:17 +00:00
Use Fetch instead of XMLHTTPRequest
This commit is contained in:
parent
4e4f94ffae
commit
ea4755fd30
|
@ -12,6 +12,11 @@ function renderBypass()
|
||||||
katex_css.setAttribute('href','https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.css ');
|
katex_css.setAttribute('href','https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.css ');
|
||||||
document.head.appendChild(katex_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.
|
// Clear the "hidden explanation" out and replace it with a blank explanation area.
|
||||||
// The innermost item is ".s1i7awl8"
|
// The innermost item is ".s1i7awl8"
|
||||||
document.querySelector('main .mwhvwas').innerHTML = '<div class="c18oith1 sladerBypass"><div class="s1oluvjw"><h4 class="h1cwp1lk">Explanation</h4><div class="as7m9cv snqbbas"><div data-testid="ExplanationsSolution" class="e1sw891e"><div class="s1i7awl8"></div></div></div></div></div>';
|
document.querySelector('main .mwhvwas').innerHTML = '<div class="c18oith1 sladerBypass"><div class="s1oluvjw"><h4 class="h1cwp1lk">Explanation</h4><div class="as7m9cv snqbbas"><div data-testid="ExplanationsSolution" class="e1sw891e"><div class="s1i7awl8"></div></div></div></div></div>';
|
||||||
|
@ -19,9 +24,6 @@ function renderBypass()
|
||||||
|
|
||||||
// Render new stuff
|
// 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.
|
// Is this an abomination? Yes.
|
||||||
// Does it work? Also yes.
|
// Does it work? Also yes.
|
||||||
//
|
//
|
||||||
|
@ -29,8 +31,8 @@ function renderBypass()
|
||||||
//
|
//
|
||||||
// I don't want to talk about it.
|
// I don't want to talk about it.
|
||||||
//
|
//
|
||||||
var b = data.match(/(?<=window.Quizlet\["questionDetailsPageData"] = ).+?(?=; QLoad\("Quizlet.questionDetailsPageData")/gm);
|
var json = data.match(/(?<=window.Quizlet\["questionDetailsPageData"] = ).+?(?=; QLoad\("Quizlet.questionDetailsPageData")/gm);
|
||||||
if (!b)
|
if (!json)
|
||||||
{
|
{
|
||||||
if (window.location.toString().includes('quizlet.com/explanations/textbook-solutions'))
|
if (window.location.toString().includes('quizlet.com/explanations/textbook-solutions'))
|
||||||
{
|
{
|
||||||
|
@ -48,7 +50,7 @@ function renderBypass()
|
||||||
|
|
||||||
|
|
||||||
// Parse JSON data
|
// Parse JSON data
|
||||||
var qDetails = JSON.parse(b[0]);
|
var qDetails = JSON.parse(json[0]);
|
||||||
|
|
||||||
// Display JSON data as answer
|
// Display JSON data as answer
|
||||||
qDetails.question.solutions.forEach(solution => {
|
qDetails.question.solutions.forEach(solution => {
|
||||||
|
@ -103,15 +105,20 @@ function renderBypass()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function doFetch(url)
|
||||||
|
|
||||||
// Handle GET request
|
|
||||||
function httpGet(url)
|
|
||||||
{
|
{
|
||||||
var req = new XMLHttpRequest();
|
const response = await fetch(url, {
|
||||||
req.open( "GET", url, false ); // false -> synchronous request
|
method: 'GET', // *GET, POST, PUT, DELETE, etc.
|
||||||
req.send( null );
|
mode: 'cors', // no-cors, *cors, same-origin
|
||||||
return req.responseText;
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue