← back to Carmelwallpapers

verification/TK-11380/console-review.cjs

41 lines

const { chromium } = require('/Users/macstudio3/Projects/Designer-Wallcoverings/node_modules/playwright');
const fs = require('node:fs');
const site = process.argv[2];
const phase = process.argv[3] || 'inspect';
if (!['carmelwallpapers.com', 'iwascute.com', 'hospitalitydesignreps.com'].includes(site)) throw Error('Out of scope');
if (phase !== 'inspect' && Date.now() >= Date.parse('2026-09-11T09:19:10Z')) throw Error('Approval expired');
(async () => {
  const browser = await chromium.connectOverCDP('http://127.0.0.1:18800');
  const url = 'https://adsense.google.com/adsense/u/0/pub-5278231299883833/sites/detail/url=' + site;
  const pages = browser.contexts().flatMap(c => c.pages()).filter(p => p.url() === url);
  if (pages.length !== 1) throw Error('Expected one dedicated tab: ' + pages.length);
  const page = pages[0];
  await page.bringToFront();
  const before = (await page.locator('body').innerText()).split('Manage your sites')[0];
  if (phase === 'verify') {
    if (site === 'iwascute.com') await page.getByRole('radio', { name: 'Meta tag', exact: true }).check();
    const checkbox = page.getByRole('checkbox', { name: /placed the/ });
    await checkbox.check();
    await page.getByRole('button', { name: 'Verify', exact: true }).click();
    await page.waitForTimeout(5000);
  } else if (phase === 'next') {
    const dialog = page.getByRole('dialog').filter({ hasText: 'Your site is verified' });
    if (await dialog.count() !== 1) throw Error('Expected ownership verified dialog');
    await dialog.getByRole('button', { name: 'Next', exact: true }).click();
    await page.waitForTimeout(1000);
  } else if (phase === 'request') {
    if (site !== 'carmelwallpapers.com') throw Error('Only reviewed Carmel is authorized in this request step');
    const button = page.locator('button').filter({ hasText: /^Request review$/ });
    if (await button.count() !== 1) throw Error('Ambiguous review request');
    await button.click();
    await page.waitForTimeout(5000);
  } else if (phase !== 'inspect') throw Error('Unknown phase');
  const result = { timestamp: new Date().toISOString(), site, phase, url: page.url(), before, after: (await page.locator('body').innerText()).split('Manage your sites')[0], buttons: await page.getByRole('button').allTextContents() };
  result.buttons = result.buttons.filter(t => /verify|review|next|done/i.test(t));
  result.dialogs = await page.getByRole('dialog').allTextContents();
  fs.writeFileSync(__dirname + '/console-' + site + '-' + phase + '.json', JSON.stringify(result, null, 2) + '\n');
  console.log(JSON.stringify(result));
  // CDP-attached browser belongs to Steve; disconnect by exiting, never close it.
  process.exit(0);
})().catch(err => { console.error(err); process.exit(1); });