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

Content deleted Content added
v2
No edit summary
Line 35:
copyItemsBtn.style.cursor = 'pointer';
addTooltip(copyItemsBtn, 'Copy all articles and pages from this category only (not subcategories). Fast operation.');
// Create the "Copy Subcats from this Category" button
const copyDirectSubcatsBtn = document.createElement('button');
copyDirectSubcatsBtn.textContent = 'Copy Subcats from this Category';
copyDirectSubcatsBtn.style.marginRight = '10px';
copyDirectSubcatsBtn.style.padding = '8px 12px';
copyDirectSubcatsBtn.style.cursor = 'pointer';
addTooltip(copyDirectSubcatsBtn, 'Copy only the direct subcategories of this category (not recursive). Fast operation.');
// Create the "Copy All Items" button
const copyAllItemsBtn = document.createElement('button');
copyAllItemsBtn.textContent = 'Copy Items from this Category and All SubcategoriesSubcats (Recursive)Recursively';
copyAllItemsBtn.style.marginRight = '10px';
copyAllItemsBtn.style.padding = '8px 12px';
Line 59 ⟶ 67:
const urlLabel = document.createElement('label');
urlLabel.htmlFor = 'includeUrls';
urlLabel.textContent = 'IncludeWhole URLs';
urlLabel.style.marginLeft = '5px';
addTooltip(urlLabel, 'Include full Wikipedia URLs for each item in the export');
Line 70 ⟶ 78:
// Add buttons to container
container.appendChild(copyItemsBtn);
container.appendChild(copyDirectSubcatsBtn);
container.appendChild(copyAllItemsBtn);
container.appendChild(copySubcatsBtn);
Line 450 ⟶ 459:
if (copySuccess) {
statusText.innerHTML = `Successfully copied ${items.length} items to clipboard.`;
}
} catch (error) {
statusText.innerHTML = `Error: ${error.message}`;
console.error('Error:', error);
}
});
 
// Handle "Copy Subcats from this Category" button click
copyDirectSubcatsBtn.addEventListener('click', async () => {
statusText.innerHTML = 'Gathering direct subcategories from this category via API...';
try {
const subcategories = await getAllSubcategories(categoryName);
if (subcategories.length === 0) {
statusText.innerHTML = 'No direct subcategories found in this category.';
return;
}
const includeUrls = urlCheckbox.checked;
const formattedText = formatItems(subcategories, includeUrls);
const copySuccess = await copyToClipboardOrDownload(formattedText, categoryName + '_direct_subcats');
if (copySuccess) {
statusText.innerHTML = `Successfully copied ${subcategories.length} direct subcategories to clipboard.`;
}
} catch (error) {
Line 459 ⟶ 493:
// Handle "Copy All Items" button click
copyAllItemsBtn.addEventListener('click', async () => {
statusText.innerHTML = 'Gathering items from this category and all subcategories recursively via API (this may take a while)...';
try {