Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/use url for convert #19

Merged
24 changes: 17 additions & 7 deletions src/js/convert.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
/**
* Find all elements with the p tag and for each one,
* get the inner text for that tag, to be used as the content
* for the post request to get the text in Bionic Reading format.
*
* Make a request to convert the entire page into Bionic Reading format
* convert the response into a DOM tree and get all of the p tags
* get all of the p tags on the page originally and
* replace the innerHTML with the innerHTML of the corresponding response p tag
*/
async function convertPage() {
let apiKey = await readLocalStorage('apiKey');
let fixation = await readLocalStorage('fixation');
let saccade = await readLocalStorage('saccade');

const parser = new DOMParser();
const response = await requestBionic(
apiKey,
document.URL,
fixation,
saccade,
true
);
const responseText = parser
.parseFromString(response, "text/html")
.getElementsByTagName("p");

let arrayText = document.getElementsByTagName("p");
for (let i = 0; i < arrayText.length; i++) {
let innerText = arrayText[i].innerText;
let text = await requestBionic(apiKey, innerText, fixation, saccade, true)
arrayText[i].innerHTML = text;
arrayText[i].innerHTML = responseText[i].innerHTML;
}
}

Expand Down