Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
Line 67:
addTooltip(urlLabel, 'Include full Wikipedia URLs for each item in the export');
// Create status text
Line 91 ⟶ 81:
container.appendChild(urlCheckbox);
container.appendChild(urlLabel);
container.appendChild(statusText);
Line 312 ⟶ 300:
// Function to get all non-category members of a category
async function getNonCategoryMembers(categoryTitle, continueToken = null
try {
// Base API URL for non-category members (exclude namespace 14, which is Category)
// Add maxlag parameter to be respectful of server load
let apiUrl = `https://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:${encodeURIComponent(categoryTitle)}&cmnamespace=0|1|2|3|4|5|6|7|8|9|10|11|12|13|15&cmlimit=max&maxlag=5&format=json&origin=*`;
// Add continue token if provided
Line 337 ⟶ 320:
}
// Extract members
const nextContinueToken = data.continue ? data.continue.cmcontinue : null;
Line 363 ⟶ 333:
// Function to get all members of a category, handling pagination
async function getAllCategoryMembers(categoryTitle
let allMembers = [];
let continueToken = null;
Line 369 ⟶ 339:
do {
const { members, continueToken: nextToken } = await getNonCategoryMembers(categoryTitle, continueToken
allMembers = allMembers.concat(members);
continueToken = nextToken;
pagesProcessed++;
statusText.innerHTML = `Retrieved ${allMembers.length} items from "${categoryTitle}" (page ${pagesProcessed})
▲ statusText.innerHTML = `Retrieved ${allMembers.length} items from "${categoryTitle}" (page ${pagesProcessed})${redirectText}...`;
} while (continueToken);
Line 435 ⟶ 404:
// Function to recursively get all items from a category and all its subcategories
async function getAllItemsRecursive(categoryTitle
const visited = new Set();
const allItems = [];
Line 454 ⟶ 423:
totalCategories++;
statusText.innerHTML = `Getting items from "${currentCategory}" (processed ${totalCategories} categories, found ${allItems.length} items, queue: ${queue.length})
▲ statusText.innerHTML = `Getting items from "${currentCategory}" (processed ${totalCategories} categories, found ${allItems.length} items, queue: ${queue.length})${redirectText}...`;
// Get items from current category
const currentItems = await getAllCategoryMembers(currentCategory
allItems.push(...currentItems);
Line 477 ⟶ 445:
// Handle "Copy Items" button click
copyItemsBtn.addEventListener('click', async () => {
▲ statusText.innerHTML = `Gathering items from this category via API${redirectText}...`;
try {
const items = await getAllCategoryMembers(categoryName
if (items.length === 0) {
Line 494 ⟶ 460:
const copySuccess = await copyToClipboardOrDownload(formattedText, categoryName);
if (copySuccess) {
statusText.innerHTML = `Successfully copied ${items.length} items to clipboard${finalRedirectText}.`;▼
}
} catch (error) {
Line 530 ⟶ 495:
// Handle "Copy All Items" button click
copyAllItemsBtn.addEventListener('click', async () => {
statusText.innerHTML =
▲ statusText.innerHTML = `Gathering items from this category and all subcategories recursively via API${redirectText} (this may take a while)...`;
try {
Line 539 ⟶ 502:
// Get all items recursively
const { items: allItems, totalCategories } = await getAllItemsRecursive(categoryName
// Deduplicate items
Line 554 ⟶ 517:
const copySuccess = await copyToClipboardOrDownload(formattedText, categoryName + '_all_recursive');
if (copySuccess) {
▲ statusText.innerHTML = `Successfully copied ${
}
} catch (error) {
|