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

Content deleted Content added
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1:
// Wikipedia List Generator - Special:BlankPage/Listgen
const handleSearchAction = async function() {
const query = $('#search-input').val().trim();
if (!query) {
updateStatus('Please enter a search query.');
return;
}
setOperationState(true);
OPERATION_STATE.currentOperation = 'search';
const includeUrls = $('#include-urls').is(':checked');
const statusCallback = (msg) => updateStatus(msg);
try {
const items = await fetchSearchResults(query, statusCallback);
if (OPERATION_STATE.shouldStop) {
updateStatus('Operation stopped by user.');
return;// Wikipedia List Generator - Special:BlankPage/Listgen
// Universal Wikipedia List Copier adapted for dedicated blank page interface
 
Line 27 ⟶ 9:
// Set up the page
$('#firstHeading').text('Wikipedia List Generator');
document.title = 'Wikipedia List Generator';
setupListGeneratorInterface();
}
Line 326 ⟶ 309:
let totalCategories = 0;
while (queue.length > 0) &&{
! if (OPERATION_STATE.shouldStop) {
statusCallback('Operation stopped by user.');
break;
}
const currentCategory = queue.shift();
const categoryKey = `Category:${currentCategory}`;
Line 336 ⟶ 324:
statusCallback(`Getting items from "${currentCategory}" (processed ${totalCategories} categories, found ${allItems.length} items, queue: ${queue.length})...`);
if (OPERATION_STATE.shouldStop) break;
const currentItems = await fetchCategoryMembers(currentCategory, statusCallback);
if (OPERATION_STATE.shouldStop) break;
allItems.push(...currentItems);
if (OPERATION_STATE.shouldStop) break;
const subcategories = await fetchCategorySubcategories(currentCategory, statusCallback);
if (OPERATION_STATE.shouldStop) break;
for (const subcategory of subcategories) {
if (OPERATION_STATE.shouldStop) break;
if (!visited.has(subcategory)) {
queue.push(subcategory.replace('Category:', ''));
Line 349 ⟶ 343:
return [...new Set(allItems)];
}
 
async function fetchCategorySubcategoriesRecursive(categoryTitle, statusCallback) {
const visited = new Set();
const allSubcategories = [];
const queue = [`Category:${categoryTitle}`];
while (queue.length > 0) {
if (OPERATION_STATE.shouldStop) {
statusCallback('Operation stopped by user.');
break;
}
const currentCategory = queue.shift();
if (visited.has(currentCategory)) continue;
visited.add(currentCategory);
statusCallback(`Exploring subcategories (found ${allSubcategories.length} categories, queue: ${queue.length})...`);
if (OPERATION_STATE.shouldStop) break;
const categoryNameForApi = currentCategory.replace('Category:', '');
const directSubcategories = await fetchCategorySubcategories(categoryNameForApi, statusCallback);
if (OPERATION_STATE.shouldStop) break;
for (const subcategory of directSubcategories) {
if (OPERATION_STATE.shouldStop) break;
if (!visited.has(subcategory)) {
allSubcategories.push(subcategory);
queue.push(subcategory);
}
}
}
return [...new Set(allSubcategories)];
}
 
async function fetchCategoryBothRecursive(categoryTitle, statusCallback) {
const visited = new Set();
const allItems = [];
const allSubcategories = [];
const queue = [categoryTitle];
let totalCategories = 0;
while (queue.length > 0) {
if (OPERATION_STATE.shouldStop) {
statusCallback('Operation stopped by user.');
break;
}
const currentCategory = queue.shift();
const categoryKey = `Category:${currentCategory}`;
if (visited.has(categoryKey)) continue;
visited.add(categoryKey);
totalCategories++;
statusCallback(`Getting items and subcategories from "${currentCategory}" (processed ${totalCategories} categories, found ${allItems.length} items, ${allSubcategories.length} subcategories, queue: ${queue.length})...`);
if (OPERATION_STATE.shouldStop) break;
const [currentItems, directSubcategories] = await Promise.all([
fetchCategoryMembers(currentCategory, statusCallback),
fetchCategorySubcategories(currentCategory, statusCallback)
]);
if (OPERATION_STATE.shouldStop) break;
allItems.push(...currentItems);
for (const subcategory of directSubcategories) {
if (OPERATION_STATE.shouldStop) break;
if (!visited.has(subcategory)) {
allSubcategories.push(subcategory);
queue.push(subcategory.replace('Category:', ''));
}
}
}
return [...new Set([...allItems, ...allSubcategories])];
}
 
// ===== UTILITY FUNCTIONS =====
 
const updateStatus = function(message) {
$('#status-text').html(message);
};
 
// ===== UI SETUP =====
Line 361 ⟶ 440:
</div>
<div id="listgen-tabs" style="margin-bottom: 20px0px;">
<button class="listgen-tab active" data-tab="category">Category ToolsCategories</button>
<button class="listgen-tab" data-tab="backlinks">BacklinksWhatlinkshere</button>
<button class="listgen-tab" data-tab="prefix">Prefix Search</button>
<button class="listgen-tab" data-tab="search">Search Results</button>
Line 373 ⟶ 452:
<div class="input-group">
<label for="category-input">Category name (without "Category:" prefix):</label>
<input type="text" id="category-input" placeholder="e.g., American novelists" style="width: 300px100%; padding: 5px8px; box-sizing: border-box;">
</div>
<div class="button-group">
Line 391 ⟶ 470:
<div class="input-group">
<label for="backlinks-input">Page title:</label>
<input type="text" id="backlinks-input" placeholder="e.g., United States" style="width: 300px100%; padding: 5px8px; box-sizing: border-box;">
</div>
<div class="button-group">
Line 406 ⟶ 485:
<div class="input-group">
<label for="prefix-input">Page title with namespace prefix (if any):</label>
<input type="text" id="prefix-input" placeholder="e.g., List of, User:Jimbo, Template:Infobox" style="width: 400px100%; padding: 5px8px; box-sizing: border-box;">
<div style="font-size: 12px; color: #666; margin-top: 5px;">
Examples: "List of" (mainspace), "User:Jimbo" (user namespace), "Template:Infobox" (template namespace)
Line 422 ⟶ 501:
<div class="input-group">
<label for="search-input">Search query:</label>
<input type="text" id="search-input" placeholder="e.g., American authors" style="width: 300px100%; padding: 5px8px; box-sizing: border-box;">
</div>
<div class="button-group">
Line 578 ⟶ 657:
OPERATION_STATE.shouldStop = true;
OPERATION_STATE.isPaused = false;
updateStatus('StoppingStop requested - operation will halt after current request...');
setOperationState(false);
};
 
Line 657 ⟶ 735:
setOperationState(false);
}
};;;;
 
const handleBacklinksAction = async function(type) {
Line 721 ⟶ 799:
setOperationState(false);
}
};
 
const handlePrefixAction = async function() {
Line 801 ⟶ 879:
setOperationState(false);
}
};
 
const handleSearchAction = async function() {
Line 845 ⟶ 923:
setOperationState(false);
}
}
 
// Recursive category methods
async function fetchCategorySubcategoriesRecursive(categoryTitle, statusCallback) {
const visited = new Set();
const allSubcategories = [];
const queue = [`Category:${categoryTitle}`];
while (queue.length > 0 && !OPERATION_STATE.shouldStop) {
const currentCategory = queue.shift();
if (visited.has(currentCategory)) continue;
visited.add(currentCategory);
statusCallback(`Exploring subcategories (found ${allSubcategories.length} categories, queue: ${queue.length})...`);
const categoryNameForApi = currentCategory.replace('Category:', '');
const directSubcategories = await fetchCategorySubcategories(categoryNameForApi, statusCallback);
for (const subcategory of directSubcategories) {
if (!visited.has(subcategory)) {
allSubcategories.push(subcategory);
queue.push(subcategory);
}
}
}
return [...new Set(allSubcategories)];
}
 
async function fetchCategoryBothRecursive(categoryTitle, statusCallback) {
const visited = new Set();
const allItems = [];
const allSubcategories = [];
const queue = [categoryTitle];
let totalCategories = 0;
while (queue.length > 0 && !OPERATION_STATE.shouldStop) {
const currentCategory = queue.shift();
const categoryKey = `Category:${currentCategory}`;
if (visited.has(categoryKey)) continue;
visited.add(categoryKey);
totalCategories++;
statusCallback(`Getting items and subcategories from "${currentCategory}" (processed ${totalCategories} categories, found ${allItems.length} items, ${allSubcategories.length} subcategories, queue: ${queue.length})...`);
const [currentItems, directSubcategories] = await Promise.all([
fetchCategoryMembers(currentCategory, statusCallback),
fetchCategorySubcategories(currentCategory, statusCallback)
]);
allItems.push(...currentItems);
for (const subcategory of directSubcategories) {
if (!visited.has(subcategory)) {
allSubcategories.push(subcategory);
queue.push(subcategory.replace('Category:', ''));
}
}
}
return [...new Set([...allItems, ...allSubcategories])];
}
 
const updateStatus = function(message) {
$('#status-text').html(message);
};