celi_main
📎 1 file 2,315 chars
📄
pasted-code-1788116043695.txt
txt 92 lines
▶
**PROMPT B (Browser‑Extension)**

Erstelle eine vollständige Chrome/Edge‑Extension (Manifest V3), die mit dem Trident‑Dashboard arbeitet:

**Dashboard‑URL:**  
`https://trident.bot/dashboard/*/panel*`

---

## FUNKTIONEN

### 1. Datei‑Sync  
Die Extension liest alle 500ms die Datei:

```
C:/trident/data.json
```

Diese Datei enthält:

```json
{
  "pendingModerations": [],
  "pendingShifts": {}
}
```

### 2. UI‑Injection  
Wenn das Trident Moderation Panel geöffnet ist, füge oben rechts zwei Buttons ein:

- **Import Moderations**  
- **Pending Imports**

Buttons sollen optisch zum Trident‑Panel passen (gleiche Farben, gleiche Höhe, gleiche Font).

### 3. Import Moderations  
Wenn der Button gedrückt wird:

- Lade `pendingModerations` aus der Datei  
- Für jeden Eintrag:  
  - Fülle das Username‑Feld im Trident‑Panel  
  - Wähle die passende Aktion im Dropdown (warn, kick, ban, banid, note)  
  - Fülle das Reason‑Feld  
  - Klicke automatisch den „Create Moderation“‑Button  
- Entferne den Eintrag aus `pendingModerations`  
- Schreibe die Datei danach neu

Import passiert **nur**, wenn der Button gedrückt wird.

### 4. Pending Imports  
Wenn der Button gedrückt wird:

- Zeige ein kleines Popup  
- Liste alle Einträge aus `pendingModerations` auf  
- Zeige Roblox‑Avatar + Username (über Roblox API)  
- Zeige Reason + Action  
- Popup soll rechts oben erscheinen und zum Trident‑Design passen

### 5. Auto‑Copy UserID  
Wenn im Dashboard ein Spieler angeklickt wird:

- Extension erkennt den Klick  
- Extrahiert die Roblox‑UserID aus dem DOM  
- Kopiert sie automatisch in die Zwischenablage

### 6. Sicherheit  
- Keine automatischen Moderationen  
- Keine Hotkeys außer F2/F3 (werden von der App gesteuert)  
- Extension darf nur auf Trident‑Seiten aktiv sein  
- Extension muss DOM‑Elemente sauber erkennen  
- Extension muss Buttons stabil einfügen  

---

## ERSTELLE

- `manifest.json`  
- Content‑Script  
- Datei‑Leser (File‑Watcher)  
- DOM‑Injection für Buttons  
- Import‑Logik  
- Pending‑Popup  
- Auto‑Copy‑System  
- Roblox API‑Integration  

Die Extension muss ausschließlich auf:

```
https://trident.bot/dashboard/*/panel*
```

aktiv sein und dort die beschriebenen Funktionen ausführen.
Kodari AI
KodariAug 30 at 6:59 pm 1
TridentModerationSync
A Chrome/Edge extension (Manifest V3) that syncs moderation data between a local JSON file and the Trident dashboard. It injects Import Moderations and Pending Imports buttons into the panel, reads pendingModerations from C:/trident/data.json every 500ms, and automates form filling for moderation creation. Features include a popup displaying pending entries with Roblox avatars via API, automatic UserID copying on player click, and strict security with no auto-moderation or unauthorized hotkeys. Active only on trident.bot/dashboard/*/panel* URLs.

Chrome kann aus Sicherheitsgründen nicht selbstständig auf C:/trident/data.json zugreifen. Öffne nach dem Laden der Extension das Popup, wähle diese Datei einmal aus und erteile die Lese-/Schreibberechtigung.

Kodari can make mistakes. Review important code before using.
Files
background.js
content.css
content.js
manifest.json
popup.css
popup.html
popup.js
Code
7 1,251
content.js
const DATA_POLL_INTERVAL = 500;

let latestData = {
  pendingModerations: [],
  pendingShifts: {}
};
let pollingInProgress = false;
let importInProgress = false;
let injectionTimer = null;
let pendingOverlay = null;
let toastTimer = null;

function sendMessage(message) {
  return new Promise((resolve, reject) => {
    chrome.runtime.sendMessage(message, (response) => {
      if (chrome.runtime.lastError) {
        reject(new Error(chrome.runtime.lastError.message));
        return;
      }

      resolve(response);
    });
  });
}

function wait(milliseconds) {
  return new Promise((resolve) => {
    window.setTimeout(resolve, milliseconds);
  });
}

function normalizedText(value) {
  return String(value || '').trim().toLowerCase().replace(/[^a-z0-9]/g, '');
}

function showToast(message) {
  const existingToast = document.querySelector('.trident-sync-toast');
  if (existingToast) {
    existingToast.remove();
  }

  const toast = document.createElement('div');
  toast.className = 'trident-sync-toast';
  toast.setAttribute('role', 'status');
  toast.textContent = message;
  document.body.appendChild(toast);

  if (toastTimer) {
    window.clearTimeout(toastTimer);
  }

  toastTimer = window.setTimeout(() => {
    toast.remove();
    toastTimer = null;
  }, 3500);
}

async function pollData() {
  if (pollingInProgress) {
    return;
  }

  pollingInProgress = true;

  try {
    const response = await sendMessage({ type: 'READ_DATA' });

    if (response?.ok) {
      latestData = response.data;
    } else if (response?.code !== 'FILE_NOT_CONNECTED') {
      console.error('Trident data polling failed:', response?.error || 'Unknown error');
    }
  } catch (error) {
    console.error('Trident data polling request failed:', error);
  } finally {
    pollingInProgress = false;
  }
}

function getElementDescriptor(element) {
  const label = element.labels?.[0]?.textContent || '';
  return [
    element.getAttribute('name'),
    element.getAttribute('id'),
    element.getAttribute('aria-label'),
    element.getAttribute('placeholder'),
    label
  ].join(' ').toLowerCase();
}

function findField(container, keywords, selector = 'input, textarea, select, [role="combobox"]') {
  const fields = [...container.querySelectorAll(selector)];

  return fields.find((field) => {
    const descriptor = getElementDescriptor(field);
    return keywords.some((keyword) => descriptor.includes(keyword));
  }) || null;
}

function setInputValue(field, value) {
  const stringValue = value == null ? '' : String(value);
  const prototype = field instanceof HTMLTextAreaElement
    ? HTMLTextAreaElement.prototype
    : HTMLInputElement.prototype;
  const valueSetter = Object.getOwnPropertyDescriptor(prototype, 'value')?.set;

  if (valueSetter) {
    valueSetter.call(field, stringValue);
  } else {
    field.value = stringValue;
  }

  field.dispatchEvent(new Event('input', { bubbles: true }));
  field.dispatchEvent(new Event('change', { bubbles: true }));
}

function findActionControl(container) {
  const select = findField(container, ['action', 'moderation action', 'type'], 'select');
  if (select) {
    return select;
  }

  return findField(container, ['action', 'moderation action', 'type'], '[role="combobox"], button');
}

async function setAction(container, action) {
  const actionControl = findActionControl(container);

  if (!actionControl) {
    throw new Error('Could not find the moderation action control.');
  }

  const wantedAction = normalizedText(action);

  if (actionControl instanceof HTMLSelectElement) {
    const matchingOption = [...actionControl.options].find((option) => {
      return normalizedText(option.value) === wantedAction ||
        normalizedText(option.textContent) === wantedAction;
    });

    if (!matchingOption) {
      throw new Error(`The moderation action "${action}" is not available.`);
    }

    actionControl.value = matchingOption.value;
    actionControl.dispatchEvent(new Event('input', { bubbles: true }));
    actionControl.dispatchEvent(new Event('change', { bubbles: true }));
    return;
  }

  actionControl.click();
  await wait(80);

  const options = [...document.querySelectorAll('[role="option"], option, li, [data-value]')];
  const matchingOption = options.find((option) => {
    return normalizedText(option.textContent) === wantedAction ||
      normalizedText(option.getAttribute('data-value')) === wantedAction;
  });

  if (!matchingOption) {
    throw new Error(`The moderation action "${action}" is not available.`);
  }

  matchingOption.click();
}

function findCreateModerationButton(container) {
  const buttons = [...container.querySelectorAll('button, [role="button"]')];

  return buttons.find((button) => {
    const text = normalizedText(button.textContent);
    return text.includes('createmoderation') ||
      text === 'create' ||
      text.includes('submitmoderation');
  }) || null;
}

function findModerationContainer() {
  const createButton = [...document.querySelectorAll('button, [role="button"]')].find((button) => {
    return normalizedText(button.textContent).includes('createmoderation');
  });

  if (!createButton) {
    return null;
  }

  return createButton.closest('form, [role="dialog"], section, main') ||
    createButton.parentElement;
}

function applyButtonStyle(button, referenceButton) {
  if (!referenceButton) {
    return;
  }

  const styles = window.getComputedStyle(referenceButton);
  button.style.setProperty('--trident-sync-border', styles.border);
  button.style.setProperty('--trident-sync-radius', styles.borderRadius);
  button.style.setProperty('--trident-sync-background', styles.backgroundColor);
  button.style.setProperty('--trident-sync-color', styles.color);