← back to Hollywood Import

momentum-find-pricelist.mjs

53 lines

// Hunt the authed Momentum trade portal for a downloadable price list / catalog export.
// Read-only: enumerates candidate links/paths + inspects the product 'Download' action.
import { chromium } from 'playwright';
import fs from 'node:fs';
const STATE = new URL('momentum-auth.json', import.meta.url).pathname;
const BASE = 'https://momentumco.com';
const b = await chromium.launch({ channel: 'chrome', headless: true });
const ctx = await b.newContext({ storageState: STATE, viewport: { width: 1500, height: 1200 } });
const p = await ctx.newPage();
const out = { sitewideLinks: [], pathProbes: [], downloadLinkOnPDP: null, accountMenu: [] };

// 1) sitewide: collect links/buttons mentioning price/download/catalog/resource/export/order
await p.goto(BASE + '/', { waitUntil: 'domcontentloaded', timeout: 60000 }).catch(()=>{});
await p.waitForTimeout(4000);
out.sitewideLinks = await p.evaluate(() => {
  const hits = [];
  document.querySelectorAll('a,button').forEach(el => {
    const t = (el.innerText || el.getAttribute('aria-label') || '').trim();
    const href = el.getAttribute('href') || '';
    if (/price\s*list|pricing|download|catalog|export|order\s*(sheet|form)|resources|spec\s*book|tear\s*sheet|product\s*list/i.test(t + ' ' + href) && t.length < 40)
      hits.push(`"${t}" → ${href}`);
  });
  return [...new Set(hits)].slice(0, 40);
});

// 2) probe common price-list paths (note status; don't download yet)
for (const path of ['/account','/account/downloads','/downloads','/resources','/pricing','/price-list','/account/orders','/account/pricing','/catalog','/account/price-list','/my-account','/dashboard']) {
  const r = await p.goto(BASE + path, { waitUntil: 'domcontentloaded', timeout: 30000 }).catch(()=>null);
  out.pathProbes.push(`${path} → ${r ? r.status() : 'ERR'} | ${p.url().replace(BASE,'')}`);
  await p.waitForTimeout(600);
}

// 3) account dropdown / menu links
await p.goto(BASE + '/', { waitUntil: 'domcontentloaded', timeout: 30000 }).catch(()=>{});
await p.waitForTimeout(2500);
out.accountMenu = await p.evaluate(() => [...document.querySelectorAll('a[href]')]
  .map(a => a.getAttribute('href')).filter(h => /account|order|download|price|resource|profile|setting/i.test(h||''))
  .filter((v,i,a)=>a.indexOf(v)===i).slice(0, 30));

// 4) inspect the product 'Download' link on a detail page
await p.goto(BASE + '/products/09153923', { waitUntil: 'domcontentloaded', timeout: 30000 }).catch(()=>{});
await p.waitForTimeout(3000);
out.downloadLinkOnPDP = await p.evaluate(() => {
  const el = [...document.querySelectorAll('a,button')].find(e => /download/i.test(e.innerText||''));
  if (!el) return null;
  return { text: el.innerText.trim(), href: el.getAttribute('href') || null, onclick: !!el.onclick,
    nearbyLinks: [...document.querySelectorAll('a[href$=".pdf"], a[href*="download"], a[href*="export"]')].map(a=>a.getAttribute('href')).slice(0,8) };
});

fs.writeFileSync(new URL('pricelist-probe.json', import.meta.url), JSON.stringify(out, null, 2));
console.log(JSON.stringify(out, null, 2));
await b.close();