Marketplace 自動刪除商品貼文腳本
 

Facebook Marketplace 自動刪除商品貼文腳本
 

這裡也有 Facebook 社團貼文自動刪除腳本 ~

裡也有 Facebook 社團待審貼文自動刪除腳本 ~
 

用途:自動刪除Facebook Marketplace上所有已發布的商品貼文
使用方法:

1. 前往 Facebook Marketplace 的「我的商品」頁面 (https://www.facebook.com/marketplace/you/selling)







  2. 打開瀏覽器開發者工具 (F12 或右鍵 -> 檢查),切換到 Console 標籤​​​​​​








3. 先打 'allow pasting'按 Enter,再複製貼上此腳本並按 Enter 執行


'allow pasting'這個要多試幾次或刷新再打一次才會成功貼上腳本




 

以下為腳本 :




const delay = ms => new Promise(res => setTimeout(res, ms));
const randomDelay = (min = 500, max = 2000) => delay(Math.floor(Math.random() * (max - min + 1)) + min);
const logStyles = {
  info: 'color: #3498db; font-weight: bold;',
  success: 'color: #2ecc71; font-weight: bold;',
  warning: 'color: #f39c12; font-weight: bold;',
  error: 'color: #e74c3c; font-weight: bold;',
  debug: 'color: #9b59b6; font-weight: bold;'
};
function log(message, type = 'info') {
  console.log(`%c${message}`, logStyles[type]);
}
async function clickConfirmDelete() {
  await delay(1000);
 
  const allDialogButtons = Array.from(document.querySelectorAll('div[role="dialog"] button'));
 
  const confirmSelectors = [
    button => button.textContent.includes('刪除') && !button.textContent.includes('取消'),
    button => button.textContent.includes('Delete') && !button.textContent.includes('Cancel'),
    button => button.textContent.trim() === '確認' || button.textContent.trim() === 'Confirm',
    button => button.classList.contains('primary') || button.getAttribute('data-testid')?.includes('confirm'),
    button => /刪除|移除|delete|remove/i.test(button.textContent)
  ];
 
  let confirmBtn = null;
  for (const selector of confirmSelectors) {
    const buttons = allDialogButtons.filter(selector);
    if (buttons.length > 0) {
      confirmBtn = buttons[0];
      break;
    }
  }
 
  if (!confirmBtn) {
    const clickableElements = Array.from(document.querySelectorAll('div[role="dialog"] [role="button"], div[role="dialog"] [tabindex="0"]'));
   
    confirmBtn = clickableElements.find(el => {
      const text = el.textContent.trim().toLowerCase();
      return text.includes('刪除') || text.includes('delete') || text.includes('確認') || text.includes('confirm');
    });
  }
  if (confirmBtn) {
    confirmBtn.click();
    return true;
  } else {
    const event = new KeyboardEvent('keydown', {
      key: 'Enter',
      code: 'Enter',
      keyCode: 13,
      which: 13,
      bubbles: true
    });
    document.activeElement.dispatchEvent(event);
   
    if (allDialogButtons.length > 0) {
      const lastButton = allDialogButtons[allDialogButtons.length - 1];
      lastButton.click();
    }
   
    await delay(1500);
   
    const dialogStillExists = document.querySelector('div[role="dialog"]');
    if (!dialogStillExists) {
      return true;
    }
   
    const cancelBtn = allDialogButtons.find(btn =>
      btn.textContent.includes('取消') || btn.textContent.includes('Cancel')
    );
    if (cancelBtn) {
      cancelBtn.click();
    }
   
    return false;
  }
}
async function deleteMarketplaceListings() {
  let deleted = 0;
  const skippedItems = new Set();
  let loopsWithoutNewItems = 0;
  let totalAttempts = 0;
 
  log("🚀 開始執行 Facebook Marketplace 商品刪除腳本", 'info');
  if (!window.location.href.includes('facebook.com/marketplace/you/selling')) {
    log("❌ 請先前往 Facebook Marketplace 的「我的商品」頁面", 'error');
    log("📌 正確網址: https://www.facebook.com/marketplace/you/selling", 'info');
    return;
  }
  while (true) {
    let menuButtons = [];
   
    const standardMenuBtns = Array.from(document.querySelectorAll('div[aria-label="商品選項"], div[aria-label="Item options"], div[aria-label="更多"]')).filter(el => !el.dataset.processed);
    menuButtons = [...menuButtons, ...standardMenuBtns];
   
    if (menuButtons.length === 0) {
      const roleBtns = Array.from(document.querySelectorAll('div[role="button"][aria-label*="選項"], div[role="button"][aria-label*="options"]')).filter(el => !el.dataset.processed);
      menuButtons = [...menuButtons, ...roleBtns];
    }
   
    if (menuButtons.length === 0) {
      const ellipsisBtns = Array.from(document.querySelectorAll('div[role="button"]')).filter(el =>
        (el.textContent.includes('⋯') || el.innerHTML.includes('ellipsis')) &&
        !el.dataset.processed
      );
      menuButtons = [...menuButtons, ...ellipsisBtns];
    }
   
    if (menuButtons.length === 0) {
      const possibleBtns = Array.from(document.querySelectorAll('div[role="button"], [aria-haspopup="menu"]')).filter(el =>
        !el.dataset.processed &&
        (el.getAttribute('aria-haspopup') === 'menu' || el.getAttribute('aria-controls'))
      );
      menuButtons = [...menuButtons, ...possibleBtns];
    }
    if (menuButtons.length === 0) {
      loopsWithoutNewItems++;
     
      if (loopsWithoutNewItems >= 3) {
        log(`✅ 完成! 已成功刪除 ${deleted} 個商品`, 'success');
        if (skippedItems.size > 0) {
          log(`⚠️ 有 ${skippedItems.size} 個商品無法刪除`, 'warning');
        }
        break;
      }
     
      log("🔄 找不到更多商品,滾動頁面以載入更多...", 'info');
     
      for (let j = 0; j < 3; j++) {
        window.scrollBy(0, -300);
        await delay(800);
        window.scrollBy(0, 800);
        await delay(1200);
      }
     
      await randomDelay(1500, 3000);
      continue;
    }
    loopsWithoutNewItems = 0;
   
    for (let i = 0; i < menuButtons.length; i++) {
      const button = menuButtons[i];
      totalAttempts++;
     
      try {
        button.scrollIntoView({ behavior: 'smooth', block: 'center' });
        await randomDelay(800, 1500);
       
        button.click();
        button.dataset.processed = "true";
        log(`📝 點擊第 ${totalAttempts} 個商品的選單`, 'info');
       
        await randomDelay(1000, 2000);
       
        const deleteSelectors = [
          'div[role="menuitem"]',
          'span',
          'a[role="menuitem"]',
          'div[role="button"]'
        ];
       
        let deleteOption = null;
       
        for (const selector of deleteSelectors) {
          const options = Array.from(document.querySelectorAll(selector)).filter(el =>
            el.textContent.trim() === '刪除商品' ||
            el.textContent.trim() === 'Delete Listing' ||
            el.textContent.trim() === '刪除' ||
            el.textContent.trim() === 'Delete'
          );
         
          if (options.length > 0) {
            deleteOption = options[0];
            break;
          }
        }
       
        if (!deleteOption) {
          const allMenuItems = Array.from(document.querySelectorAll('div[role="menu"] *'));
          deleteOption = allMenuItems.find(el =>
            /刪除|delete|移除|remove/i.test(el.textContent.trim())
          );
        }
       
        if (!deleteOption) {
          log(`⏭️ 找不到刪除選項(第 ${totalAttempts} 個商品)`, 'warning');
          skippedItems.add(`第 ${totalAttempts} 個商品`);
         
          document.body.click();
          await randomDelay(500, 1000);
          continue;
        }
       
        deleteOption.click();
        log(`🗑️ 點擊「${deleteOption.textContent.trim()}」選項`, 'info');
       
        const confirmed = await clickConfirmDelete();
        if (confirmed) {
          deleted++;
          log(`✅ 已刪除第 ${deleted} 個商品 (總嘗試: ${totalAttempts})`, 'success');
        } else {
          skippedItems.add(`第 ${totalAttempts} 個商品 - 確認失敗`);
        }
       
        await randomDelay(1500, 3000);
       
      } catch (err) {
        log(`❌ 錯誤(第 ${totalAttempts} 個商品):${err.message}`, 'error');
        skippedItems.add(`錯誤第 ${totalAttempts} 個商品`);
        await randomDelay(1000, 2000);
      }
    }
   
    window.scrollTo(0, document.body.scrollHeight / 2);
    await randomDelay(1500, 3000);
  }
}
deleteMarketplaceListings();





複製以上腳本即可,有問題可在詢問~
如果腳本沒反應,在刷新重打指令就可以了,最好是每運行一段時間去檢查~