Add glossary methods #4

Open
KaKi87 wants to merge 15 commits from Androz2091/deepl-scraper:glossary-v2 into master
Showing only changes of commit 2f356bd5ea - Show all commits

View file

@ -114,22 +114,15 @@ module.exports = {
await page.waitForSelector(langSelect, { visible: true });
await page.click(langSelect);
try {
await page.evaluate(({
sourceLanguage,
targetLanguage
}) => {
const langButtons = Array.from(document.querySelectorAll('button[dl-test=glossary-newentry-lang-dropdown-option]'));
const button = langButtons.find((btn) => {
const childrens = Array.from(Array.from(btn.children)[1].children);
const buttonSourceLanguage = childrens[0].textContent;
const buttonTargetLanguage = childrens[2].textContent;
return buttonSourceLanguage === sourceLanguage && buttonTargetLanguage === targetLanguage;
});
button.click();
}, {
sourceLanguage,
targetLanguage
});
for(const button of await page.$$('button[dl-test=glossary-newentry-lang-dropdown-option]')){
const
_sourceLanguage = await (await (await button.$('.langCode')).getProperty('textContent')).jsonValue(),
_targetLanguage = await (await (await button.$('.langCode:nth-of-type(2)')).getProperty('textContent')).jsonValue();
if(sourceLanguage === _sourceLanguage && targetLanguage === _targetLanguage){
await button.click();
break;
}
}
}
catch(_){
throw new Error('UNSUPPORTED_GLOSSARY_LANGUAGE');