added updateall btn to marketplace

This commit is contained in:
2025-12-20 00:13:10 +01:00
parent a26f03f024
commit 90231f6608
12 changed files with 340 additions and 152 deletions

View File

@@ -1,9 +1,11 @@
const ORIGINAL_MARKETPLACE_URL = 'https://git.waifuboard.app/ItsSkaiya/WaifuBoard-Extensions/raw/branch/main/marketplace.json';
const MARKETPLACE_JSON_URL = `/api/proxy?url=${encodeURIComponent(ORIGINAL_MARKETPLACE_URL)}`;
const INSTALLED_EXTENSIONS_API = '/api/extensions';
const UPDATE_EXTENSIONS_API = '/api/extensions/update';
const marketplaceContent = document.getElementById('marketplace-content');
const filterSelect = document.getElementById('extension-filter');
const updateAllBtn = document.getElementById('btn-update-all');
const modal = document.getElementById('customModal');
const modalTitle = document.getElementById('modalTitle');
@@ -32,6 +34,10 @@ async function loadMarketplace() {
if (filterSelect) {
filterSelect.addEventListener('change', () => renderGroupedView());
}
if (updateAllBtn) {
updateAllBtn.onclick = handleUpdateAll;
}
} catch (error) {
console.error('Error loading marketplace:', error);
marketplaceContent.innerHTML = `<div class="error-msg">Error al cargar el marketplace.</div>`;
@@ -45,11 +51,49 @@ function initTabs() {
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
currentTab = tab.dataset.tab;
if (updateAllBtn) {
if (currentTab === 'installed') {
updateAllBtn.classList.remove('hidden');
} else {
updateAllBtn.classList.add('hidden');
}
}
renderGroupedView();
};
});
}
async function handleUpdateAll() {
const originalText = updateAllBtn.innerText;
try {
updateAllBtn.disabled = true;
updateAllBtn.innerText = 'Updating...';
const res = await fetch(UPDATE_EXTENSIONS_API, { method: 'POST' });
if (!res.ok) throw new Error('Update failed');
const data = await res.json();
if (data.updated && data.updated.length > 0) {
const list = data.updated.join(', ');
window.NotificationUtils.success(`Updated: ${list}`);
await loadMarketplace();
} else {
window.NotificationUtils.info('Everything is up to date.');
}
} catch (error) {
console.error('Update All Error:', error);
window.NotificationUtils.error('Failed to perform bulk update.');
} finally {
updateAllBtn.disabled = false;
updateAllBtn.innerText = originalText;
}
}
function renderGroupedView() {
marketplaceContent.innerHTML = '';
const activeFilter = filterSelect.value;
@@ -58,7 +102,6 @@ function renderGroupedView() {
let listToRender = [];
if (currentTab === 'marketplace') {
for (const [id, data] of Object.entries(marketplaceMetadata)) {
listToRender.push({
id,
@@ -67,7 +110,6 @@ function renderGroupedView() {
});
}
} else {
for (const [id, data] of Object.entries(marketplaceMetadata)) {
if (installedExtensions.includes(id.toLowerCase())) {
listToRender.push({ id, ...data, isInstalled: true });
@@ -90,9 +132,7 @@ function renderGroupedView() {
listToRender.forEach(ext => {
const type = ext.type || 'Other';
if (activeFilter !== 'All' && type !== activeFilter) return;
if (!groups[type]) groups[type] = [];
groups[type].push(ext);
});
@@ -127,7 +167,7 @@ function createCard(ext) {
const card = document.createElement('div');
card.className = `extension-card ${ext.nsfw ? 'nsfw-ext' : ''} ${ext.broken ? 'broken-ext' : ''}`;
const iconUrl = `https://www.google.com/s2/favicons?domain=${ext.domain}&sz=128`
const iconUrl = `https://www.google.com/s2/favicons?domain=${ext.domain}&sz=128`;
let buttonHtml = '';
if (ext.isInstalled) {
@@ -187,9 +227,9 @@ async function handleInstall(ext) {
if (res.ok) {
installedExtensions.push(ext.id.toLowerCase());
renderGroupedView();
showModal('Success', `${ext.name} installed!`);
window.NotificationUtils.success(`${ext.name} installed!`);
}
} catch (e) { showModal('Error', 'Install failed.'); }
} catch (e) { window.NotificationUtils.error('Install failed.'); }
}
function promptUninstall(ext) {
@@ -206,8 +246,9 @@ async function handleUninstall(ext) {
if (res.ok) {
installedExtensions = installedExtensions.filter(id => id !== ext.id.toLowerCase());
renderGroupedView();
window.NotificationUtils.info(`${ext.name} uninstalled.`);
}
} catch (e) { showModal('Error', 'Uninstall failed.'); }
} catch (e) { window.NotificationUtils.error('Uninstall failed.'); }
}
function showSkeletons() {