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

Content deleted Content added
No edit summary
No edit summary
Line 1:
 
(function() {
'use strict';
Line 31 ⟶ 30:
font-size: 0.7rem;
color: #666;
}
#article-name {
margin-top: 0.5rem;
font-style: italic;
}
`;
Line 42 ⟶ 45:
<div id="word-display">Click 'Next Word' to start</div>
<button id="next-button">Next Word</button>
<div id="article-name"></div>
<div id="debug-info"></div>
`;
Line 54 ⟶ 58:
this.nextButton = document.getElementById('next-button');
this.debugElement = document.getElementById('debug-info');
this.articleNameElement = document.getElementById('article-name');
 
this.nextButton.addEventListener('click', () => this.displayNextWord());
Line 63 ⟶ 68:
try {
const response = await fetch('http://localhost:8082/output', {
mode: 'cors', // This line is added to explicitly request CORS
});
if (!response.ok) {
Line 69 ⟶ 74:
}
const newWords = await response.json();
this.words = [...this.words, ...newWords.map(this.parseWordString)];
this.updateDebugInfo();
} catch (error) {
Line 76 ⟶ 81:
this.displayElement.textContent = 'Unable to fetch words. See debug info.';
}
}
 
parseWordString(wordString) {
const parts = wordString.split('|');
return {
word: parts[0],
articleName: parts[2] || 'Unknown Article'
};
}
 
Line 84 ⟶ 97:
 
if (this.words.length > 0) {
this.displayElement.textContentconst currentWord = this.words[this.currentIndex];
this.displayElement.textContent = currentWord.word;
this.articleNameElement.textContent = `Article: ${currentWord.articleName}`;
this.currentIndex++;
 
Line 94 ⟶ 109:
} else {
this.displayElement.textContent = 'No words available. Check debug info.';
this.articleNameElement.textContent = '';
}