Smazání parametrů a příznaků

Pozor — proměnná limit

Skript smaže až limit parametrů a příznaků (výchozí: 1000). Před spuštěním upravte hodnotu dle potřeby. Akce je nevratná.

JavaScript — vložte do konzole
async function deleteFilterParamsSequentially() {
    // Grab CSRF token from Shoptet's hidden input
    const csrfInput = document.querySelector('input[name="__csrf__"]');
    if (!csrfInput) {
        console.error("CSRF token not found — are you on the Shoptet admin page?");
        return;
    }
    const csrfToken = csrfInput.value;

    // Collect all items upfront so page reloads don't matter
    const buttons = Array.from(document.querySelectorAll('a.delete-item[data-url*="action=delete"]'));
    const items = buttons.map(btn => {
        const row = btn.closest('tr');
        const name = row?.querySelector('.table__detailLink')?.textContent?.trim() ?? 'Unknown';
        const url = btn.getAttribute('data-url');
        const id = btn.getAttribute('data-values');
        return { name, url, id };
    });

    const limit = 1000; // ← Změňte dle potřeby
    const toDelete = items.slice(0, limit);

    console.log(`Found ${items.length} items. Deleting up to ${limit}...`);

    for (let i = 0; i < toDelete.length; i++) {
        const { name, url, id } = toDelete[i];
        console.log(`[${i + 1}/${toDelete.length}] Deleting: ${name} (id=${id})...`);

        const body = new URLSearchParams({ id, __csrf__: csrfToken });

        try {
            const res = await fetch(url, {
                method: 'POST',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' },
                body: body.toString(),
                credentials: 'same-origin',
            });
            if (res.ok) {
                console.log(`  ✓ Deleted`);
            } else {
                console.warn(`  ✗ Failed (HTTP ${res.status})`);
            }
        } catch (err) {
            console.error(`  ✗ Error:`, err);
        }

        await new Promise(resolve => setTimeout(resolve, 300));
    }

    console.log("Done! Reload the page to see the result.");
}

deleteFilterParamsSequentially();