User:Polygnotus/Scripts/GetAPIBatch.js: Difference between revisions

Content deleted Content added
No edit summary
 
(One intermediate revision by the same user not shown)
Line 24:
color: red;
}
#next-button, #view-article-button {
font-size: 0.9rem;
padding: 0.3rem 0.7rem;
cursor: pointer;
margin-right: 0.5rem;
}
#debug-info {
Line 51 ⟶ 50:
<div id="article-name"></div>
<button id="next-button">Next Word</button>
<button id="view-article-button">View Article</button>
<div id="debug-info"></div>
`;
Line 64 ⟶ 62:
this.typoDisplayElement = document.getElementById('typo-display');
this.nextButton = document.getElementById('next-button');
this.viewArticleButton = document.getElementById('view-article-button');
this.debugElement = document.getElementById('debug-info');
this.articleNameElement = document.getElementById('article-name');
 
this.nextButton.addEventListener('click', () => this.displayNextWorddisplayNextWordAndNavigate());
this.viewArticleButton.addEventListener('click', () => this.viewWikipediaArticle());
 
this.fetchWords();
Line 97 ⟶ 93:
}
 
async displayNextWorddisplayNextWordAndNavigate() {
if (this.currentIndex >= this.words.length) {
await this.fetchWords();
Line 107 ⟶ 103:
this.typoDisplayElement.textContent = `Typo: ${currentWord.typo}`;
this.articleNameElement.textContent = `Article: ${currentWord.articleName}`;
margin-right: 0.5rem;
this.navigateToWikipedia(currentWord.articleName);
}
this.currentIndex++;
 
Line 123 ⟶ 122:
}
 
viewWikipediaArticlenavigateToWikipedia(articleName) {
ifconst (this.words.lengthencodedArticleName >= 0 && thisencodeURIComponent(articleName.currentIndexreplace(/ >/g, 0'_') {);
const currentWordarticleUrl = this`https://en.words[thiswikipedia.currentIndex - 1]org/wiki/${encodedArticleName}`;
window.open(articleUrl, '_blank');
const encodedArticleName = encodeURIComponent(currentWord.articleName.replace(/ /g, '_'));
const articleUrl = `https://en.wikipedia.org/wiki/${encodedArticleName}`;
window.open(articleUrl, '_blank');
}
}