# Brand Color Extraction Snippet

Ready-to-use JavaScript for `browser_console`. Paste as the `expression` parameter.

## Full Extraction Snippet

```javascript
(function() {
  const styles = getComputedStyle(document.body);
  const links = document.querySelectorAll('a');
  const headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');

  // Collect link colors
  const linkColors = new Set();
  links.forEach(l => {
    const c = getComputedStyle(l).color;
    if (c && c !== 'rgb(0, 0, 0)') linkColors.add(c);
  });

  // Collect heading colors
  const headingColors = new Set();
  headings.forEach(h => {
    headingColors.add(getComputedStyle(h).color);
  });

  // Scan all stylesheets for color and backgroundColor declarations
  const cssColors = [];
  for (const sheet of document.styleSheets) {
    try {
      for (const rule of sheet.cssRules) {
        if (rule.style && rule.style.color)
          cssColors.push(rule.selectorText + ': ' + rule.style.color);
        if (rule.style && rule.style.backgroundColor)
          cssColors.push(rule.selectorText + ' bg: ' + rule.style.backgroundColor);
      }
    } catch(e) {} // CORS-protected sheets
  }

  return JSON.stringify({
    bodyBg: styles.backgroundColor,
    bodyText: styles.color,
    linkColors: [...linkColors],
    headingColors: [...headingColors],
    cssColorsSample: cssColors.slice(0, 40)
  }, null, 2);
})()
```

## RGB to Hex Conversion

If you need hex in the same expression, add this helper:

```javascript
function rgbToHex(rgb) {
  const m = rgb.match(/\d+/g);
  if (!m) return rgb;
  return '#' + m.map(n => parseInt(n).toString(16).padStart(2, '0')).join('').toUpperCase();
}
```

Then wrap collected colors: `linkColors: [...linkColors].map(rgbToHex)`

## Example Output (noris.cloud, July 2026)

```json
{
  "bodyBg": "rgb(255, 255, 255)",
  "bodyText": "rgb(17, 17, 17)",
  "linkColors": [
    "rgb(17, 130, 145)",   // #118291 — primary teal/petrol
    "rgb(158, 25, 70)",    // #9E1946 — burgundy accent
    "rgb(102, 102, 102)"   // #666666 — muted gray
  ],
  "headingColors": [
    "rgb(255, 255, 255)",  // white (on dark hero)
    "rgb(36, 78, 92)"      // #244E5C — dark slate teal
  ]
}
```

Resulting palette:
- Primary: `#118291` (petrol/teal — links, headings)
- Accent: `#9E1946` (burgundy — buttons)
- Dark BG: `#244E5C` (slate teal — deep backgrounds)
- Base: `#313131` (near-black — dark surfaces)
