Content deleted Content added
DreamRimmer (talk | contribs) fix |
DreamRimmer (talk | contribs) expand ArbComCases |
||
Line 508:
}
function fetchArbComCases() {
return Promise.all([
localApi.get({
action: 'parse',
page: 'Template:ArbComOpenTasks/Cases',
format: 'json',
prop: 'text'
}).catch(() => ({ parse: null })),
localApi.get({
action: 'parse',
page: 'Template:ArbComOpenTasks/ClosedCases',
format: 'json',
prop: 'text'
}).catch(() => ({ parse: null }))
]).then(([openResponse, closedResponse]) => {
let html = '';
if (openResponse.parse && openResponse.parse.text) {
const openHtml = openResponse.parse.text['*'];
const openCases = parseArbComCases(openHtml, 'open');
html += createArbComTable('Open cases', openCases, 'open');
} else {
html += '<h4>Open cases</h4><p>No cases are in this period open.</p>';
}
if (closedResponse.parse && closedResponse.parse.text) {
const closedHtml = closedResponse.parse.text['*'];
const closedCases = parseArbComCases(closedHtml, 'closed');
html += createArbComTable('Recently closed cases', closedCases, 'closed');
} else {
html += '<h4>Recently closed cases</h4><p>No cases are in this period closed.</p>';
}
html += '<p><a href="https://en.wikipedia.org/wiki/Template:ArbComOpenTasks" target="_blank">See detailed statistics</a></p>';
return html;
});
}
function parseArbComCases(html, type) {
const cases = [];
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const rows = doc.querySelectorAll('table.wikitable tbody tr');
rows.forEach((row, index) => {
if (index === 0) return;
const cells = row.querySelectorAll('td');
if (cells.length === 0) return;
const firstCell = cells[0];
const link = firstCell.querySelector('a');
if (!link) return;
const caseName = link.textContent.trim();
const href = link.getAttribute('href');
const fullUrl = href.startsWith('/wiki/') ? `https://en.wikipedia.org${href}` : href;
if (type === 'open' && cells.length >= 4) {
const evidenceDeadline = cells[2] ? cells[2].textContent.trim() : '';
const pdDeadline = cells[3] ? cells[3].textContent.trim() : '';
cases.push({
name: caseName,
url: fullUrl,
evidenceDeadline: evidenceDeadline,
pdDeadline: pdDeadline
});
} else if (type === 'closed' && cells.length >= 2) {
const dateClosed = cells[1] ? cells[1].textContent.trim() : '';
cases.push({
name: caseName,
url: fullUrl,
dateClosed: dateClosed
});
}
});
return cases;
}
function createArbComTable(title, cases, type) {
let html = `<h4>${title}</h4>`;
if (cases.length === 0) {
const period = type === 'open' ? 'open' : 'closed';
html += `<p>No cases are in this period ${period}.</p>`;
return html;
}
if (type === 'open') {
html += '<table class="wikitable"><thead><tr><th>Case name</th><th>Evidence deadline</th><th>PD deadline</th></tr></thead><tbody>';
cases.forEach(caseItem => {
html += `<tr><td><i><a href="${caseItem.url}" target="_blank">${caseItem.name}</a></i></td><td>${caseItem.evidenceDeadline}</td><td>${caseItem.pdDeadline}</td></tr>`;
});
} else {
html += '<table class="wikitable"><thead><tr><th>Case name</th><th>Date closed</th></tr></thead><tbody>';
cases.forEach(caseItem => {
html += `<tr><td><i><a href="${caseItem.url}" target="_blank">${caseItem.name}</a></i></td><td>${caseItem.dateClosed}</td></tr>`;
});
}
html += '</tbody></table>';
return html;
}
function fetchRecentRfCs() {
const rfcPages = [
Line 800 ⟶ 906:
if ((section === 'all' || section === 'arbcom') && isCurrentOrLastMonth) {
fetchArbComCases().then(arbcomCasesHtml => {
resultsContainer.append(arbcomTasksHtml);
});
}
|