Initialer Upload
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
// popup.js
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
document.getElementById("project-name").innerText = PROJECT_NAME;
|
||||
|
||||
const options = await loadOptions();
|
||||
const bannerElement = document.getElementById("project-banner");
|
||||
if (bannerElement && (options.showBanner ?? SHOW_BANNER_DEFAULT)) {
|
||||
bannerElement.innerText = `Erstellt mit ${PROJECT_NAME} – deinem datenschutzfreundlichen Helfer gegen unerlaubte Cookie-Banner.`;
|
||||
}
|
||||
|
||||
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
document.getElementById("current-url").value = tab.url;
|
||||
|
||||
const violationsDiv = document.getElementById("violations");
|
||||
VIOLATION_TYPES.forEach(type => {
|
||||
const label = document.createElement("label");
|
||||
label.innerHTML = `<input type="checkbox" value="${type}"> ${type}`;
|
||||
violationsDiv.appendChild(label);
|
||||
});
|
||||
|
||||
document.getElementById("screenshot-btn").addEventListener("click", createScreenshot);
|
||||
// PDF-Funktion aktuell deaktiviert:
|
||||
// document.getElementById("create-pdf-btn").addEventListener("click", preparePDF);
|
||||
document.getElementById("create-email-btn").addEventListener("click", prepareEmail);
|
||||
document.getElementById("open-options-btn").addEventListener("click", openOptions);
|
||||
});
|
||||
|
||||
// Optionen laden
|
||||
async function loadOptions() {
|
||||
const result = await chrome.storage.local.get('options');
|
||||
return result.options || {};
|
||||
}
|
||||
|
||||
// Screenshot erstellen und speichern
|
||||
async function createScreenshot() {
|
||||
try {
|
||||
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
const imageUri = await chrome.tabs.captureVisibleTab(tab.windowId, { format: "png" });
|
||||
|
||||
const url = new URL(tab.url);
|
||||
const domain = url.hostname.replace('www.', '');
|
||||
|
||||
const now = new Date();
|
||||
const timestamp = now.getFullYear().toString()
|
||||
+ String(now.getMonth() + 1).padStart(2, '0')
|
||||
+ String(now.getDate()).padStart(2, '0')
|
||||
+ String(now.getHours()).padStart(2, '0')
|
||||
+ String(now.getMinutes()).padStart(2, '0');
|
||||
|
||||
const filename = `${timestamp}_${domain}.png`;
|
||||
|
||||
const response = await fetch(imageUri);
|
||||
const blob = await response.blob();
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
|
||||
await chrome.downloads.download({
|
||||
url: blobUrl,
|
||||
filename: `cookiekop/screenshots/${filename}`, // Vorschlagpfad
|
||||
saveAs: true
|
||||
});
|
||||
|
||||
// Kein alert mehr notwendig!
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Screenshot:", error);
|
||||
alert("Screenshot konnte nicht gespeichert werden.");
|
||||
}
|
||||
}
|
||||
|
||||
// (PDF erstellen Funktion bleibt auskommentiert – später aktivieren)
|
||||
|
||||
// E-Mail vorbereiten
|
||||
async function prepareEmail() {
|
||||
const url = document.getElementById("current-url").value;
|
||||
const violations = Array.from(document.querySelectorAll('#violations input:checked')).map(input => input.value);
|
||||
const note = document.getElementById("custom-note").value;
|
||||
const options = await loadOptions();
|
||||
|
||||
let body = `Sehr geehrte Damen und Herren,\n\n`;
|
||||
body += `ich möchte folgende Verstöße gegen die DSGVO im Zusammenhang mit dem Cookie-Banner melden:\n\n`;
|
||||
violations.forEach(v => {
|
||||
body += `- ${v}\n`;
|
||||
});
|
||||
body += `\nURL: ${url}\n`;
|
||||
if (note) {
|
||||
body += `\nZusätzliche Hinweise: ${note}\n`;
|
||||
}
|
||||
|
||||
if (options.showBanner ?? true) {
|
||||
body += `\n\nErstellt mit CookieKop – https://gitlab.com/1337gut/cookiekop`;
|
||||
}
|
||||
|
||||
body += `\n\nMit freundlichen Grüßen\n\n`;
|
||||
|
||||
const subject = encodeURIComponent("Meldung eines Cookie-Banner-Verstoßes");
|
||||
const bodyEncoded = encodeURIComponent(body);
|
||||
|
||||
let recipient = "poststelle@lda.bayern.de"; // Fallback
|
||||
if (options?.state) {
|
||||
try {
|
||||
const response = await fetch('data/datenschutzbehoerden.json');
|
||||
const authorities = await response.json();
|
||||
const found = authorities.find(entry => entry.bundesland === options.state);
|
||||
if (found && found.email) {
|
||||
recipient = found.email;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Behördenliste:", error);
|
||||
}
|
||||
}
|
||||
|
||||
const mailtoLink = `mailto:${recipient}?subject=${subject}&body=${bodyEncoded}`;
|
||||
|
||||
try {
|
||||
await chrome.tabs.create({ url: mailtoLink });
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Öffnen von mailto:", error);
|
||||
fallbackCopyEmailText(body);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: E-Mail-Text in Zwischenablage kopieren
|
||||
function fallbackCopyEmailText(text) {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
alert("E-Mail-Text wurde kopiert. Bitte öffne dein E-Mail-Programm und füge ihn ein (Strg+V).");
|
||||
}).catch(err => {
|
||||
console.error("Kopieren fehlgeschlagen:", err);
|
||||
alert("Fehler beim Kopieren des E-Mail-Texts.");
|
||||
});
|
||||
}
|
||||
|
||||
// Optionen-Seite öffnen
|
||||
function openOptions() {
|
||||
chrome.runtime.openOptionsPage();
|
||||
}
|
||||
Reference in New Issue
Block a user