Content deleted Content added
Polygnotus (talk | contribs) get context |
Polygnotus (talk | contribs) m Polygnotus moved page User:Polygnotus/test6.js to User:Polygnotus/Scripts/GetContext.js |
||
(One intermediate revision by the same user not shown) | |||
Line 1:
function
return new Promise((resolve, reject) => {
const url = `https://en.wikipedia.org/w/api.php?action=
fetch(url)
.then(response => response.json())
.then(data => {
const
const textContent = htmlContent.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();▼
// Remove comments and nowiki tags
▲ const
.replace(/<nowiki>[\s\S]*?<\/nowiki>/g, '');
const wordRegex = new RegExp(`\\b${word}\\b`, 'gi');
Line 13 ⟶ 16:
let index = -1;
while (count < n && (match = wordRegex.exec(
count++;
if (count === n) {
Line 26 ⟶ 29:
}
const words =
const wordIndex = words.findIndex((_, i) => words.slice(0, i + 1).join(' ').length >= index);
Line 39 ⟶ 42:
}
// Run the example automatically
.then(result => {
console.log("Result:");
|