All checks were successful
release-tag / release-image (push) Successful in 1m47s
224 lines
11 KiB
JavaScript
224 lines
11 KiB
JavaScript
(() => {
|
|
const cfg = window.APP_CONFIG;
|
|
if (!cfg) return;
|
|
const base = cfg.baseURL.replace(/\/$/, '');
|
|
const form = document.getElementById('generator-form');
|
|
if (!form) return;
|
|
const $ = id => document.getElementById(id);
|
|
const presets = {
|
|
// Never assume human/editorial review. It can be legally relevant under
|
|
// Article 50(4) AI Act and must reflect the publisher's actual workflow.
|
|
'no-ai': {extent:'none', activities:'', review:'none'},
|
|
research: {extent:'assisted', activities:'research', review:'none'},
|
|
summary: {extent:'assisted', activities:'summarisation', review:'none'},
|
|
full: {extent:'full', activities:'generation', review:'none'}
|
|
};
|
|
|
|
function value(id) {
|
|
const el = $(id);
|
|
return el && !el.disabled ? el.value.trim() : '';
|
|
}
|
|
|
|
function setArticleParams(params) {
|
|
params.set('mode', 'article');
|
|
const fields = {
|
|
text: 'article-text',
|
|
coverImage: 'article-cover-image',
|
|
image: 'article-image',
|
|
research: 'article-research',
|
|
translation: 'article-translation',
|
|
code: 'article-code'
|
|
};
|
|
Object.entries(fields).forEach(([name, id]) => {
|
|
params.set(name + 'Extent', $(id).value);
|
|
params.set(name + 'Review', $(`${id}-review`).value);
|
|
});
|
|
}
|
|
|
|
function legalCategories() {
|
|
const values = [];
|
|
if ($('legal-deepfake')?.checked) values.push('deepfake');
|
|
if ($('legal-public-interest')?.checked) values.push('publicInterestText');
|
|
if ($('legal-creative')?.checked) values.push('artisticCreativeSatiricalFictional');
|
|
if ($('legal-other-voluntary')?.checked) values.push('otherVoluntary');
|
|
return values;
|
|
}
|
|
|
|
function substantiveReview(mode) {
|
|
return mode === 'editorial' || mode === 'expert';
|
|
}
|
|
|
|
function legalAssessment(locale, articleMode) {
|
|
const categories = legalCategories();
|
|
const deepfake = categories.includes('deepfake');
|
|
const publicInterest = categories.includes('publicInterestText');
|
|
const creative = categories.includes('artisticCreativeSatiricalFictional');
|
|
if (categories.length === 0) return {text: locale.text.legal_assessment_none, legal: false, badge: locale.text.badge_article || 'Article transparency'};
|
|
if (categories.includes('otherVoluntary')) return {text: locale.text.legal_assessment_voluntary, legal: false, badge: locale.text.badge_article || 'Article transparency'};
|
|
if (deepfake) return {text: creative ? locale.text.legal_assessment_deepfake_creative : locale.text.legal_assessment_deepfake, legal: true, badge: locale.text.badge_legal_disclosure || 'AI-generated / manipulated content'};
|
|
if (publicInterest) {
|
|
const review = articleMode ? $('article-text-review').value : ($('component').value === 'text' ? $('review').value : 'none');
|
|
const hasResponsibility = Boolean(value('responsible'));
|
|
if (substantiveReview(review) && hasResponsibility) return {text: locale.text.legal_assessment_public_exemption, legal: false, badge: locale.text.badge_article || 'Article transparency'};
|
|
return {text: locale.text.legal_assessment_public_required, legal: true, badge: locale.text.badge_public_interest || 'AI-generated / edited content'};
|
|
}
|
|
return {text: locale.text.legal_assessment_voluntary, legal: false, badge: locale.text.badge_article || 'Article transparency'};
|
|
}
|
|
|
|
function update(applyPreset = false) {
|
|
const mode = $('declaration-mode').value;
|
|
const articleMode = mode === 'article';
|
|
$('single-fields').hidden = articleMode;
|
|
$('article-fields').hidden = !articleMode;
|
|
|
|
const preset = $('preset').value;
|
|
if (!articleMode && applyPreset && presets[preset]) {
|
|
$('extent').value = presets[preset].extent;
|
|
$('activities').value = presets[preset].activities;
|
|
$('review').value = presets[preset].review;
|
|
}
|
|
|
|
const lang = $('lang').value;
|
|
const locale = cfg.locales[lang] || cfg.locales.en;
|
|
const assurance = $('assurance').value;
|
|
const assuranceDescription = locale.text[`assurance_${assurance}_description`];
|
|
if ($('assurance-description') && assuranceDescription) {
|
|
$('assurance-description').textContent = assuranceDescription;
|
|
}
|
|
const params = new URLSearchParams();
|
|
if (articleMode) {
|
|
setArticleParams(params);
|
|
} else {
|
|
if (preset) params.set('preset', preset);
|
|
params.set('component', $('component').value);
|
|
params.set('extent', $('extent').value);
|
|
if ($('activities').value.trim()) params.set('activities', $('activities').value.trim());
|
|
params.set('review', $('review').value);
|
|
}
|
|
params.set('lang', lang);
|
|
params.set('assurance', assurance);
|
|
if ($('subject').value.trim()) params.set('subject', $('subject').value.trim());
|
|
if (value('responsible-role')) params.set('responsibleRole', value('responsible-role'));
|
|
if (value('responsible')) params.set('responsible', value('responsible'));
|
|
if (value('responsible-url')) params.set('responsibleUrl', value('responsible-url'));
|
|
const legal = legalCategories();
|
|
if (legal.length) params.set('legalContext', legal.join(','));
|
|
|
|
if (cfg.capabilities.custom_text) {
|
|
if (value('custom-title')) params.set('customTitle', value('custom-title'));
|
|
if (value('custom-description')) params.set('customDescription', value('custom-description'));
|
|
}
|
|
if (cfg.capabilities.custom_badge) {
|
|
if (value('badge-label')) params.set('badgeLabel', value('badge-label'));
|
|
if (value('badge-message')) params.set('badgeMessage', value('badge-message'));
|
|
if (value('left-color')) params.set('leftColor', value('left-color'));
|
|
if (value('right-color')) params.set('rightColor', value('right-color'));
|
|
}
|
|
|
|
const declarationURL = `${base}/declaration?${params}`;
|
|
const badgeParams = new URLSearchParams(params);
|
|
badgeParams.set('theme', $('theme').value);
|
|
badgeParams.set('link', declarationURL);
|
|
const badgeURL = `${base}/v1/badge.svg?${badgeParams}`;
|
|
const manifestURL = `${base}/v1/declaration.json?${params}`;
|
|
const assessment = legalAssessment(locale, articleMode);
|
|
const alt = assessment.legal
|
|
? assessment.badge
|
|
: (articleMode
|
|
? (locale.text.badge_article || 'Article transparency')
|
|
: ((locale.presets[preset] && locale.presets[preset].title) || locale.extents[$('extent').value] || 'AI usage disclosure'));
|
|
if ($('legal-assessment')) {
|
|
$('legal-assessment').innerHTML = `<strong>${locale.text.legal_assessment_heading || 'Article 50 assessment'}</strong><span>${assessment.text || ''}</span>`;
|
|
$('legal-assessment').dataset.level = assessment.legal ? 'attention' : 'info';
|
|
}
|
|
|
|
$('preview-badge').src = badgeURL;
|
|
$('preview-badge').alt = alt;
|
|
$('preview-link').href = declarationURL;
|
|
const imageMarkup = `<a href="${declarationURL}"><img src="${badgeURL}" alt="${alt}"></a>`;
|
|
$('html-code').value = assessment.legal && $('theme').value === 'emoji'
|
|
? `${imageMarkup} <span>${assessment.badge}</span>`
|
|
: imageMarkup;
|
|
$('markdown-code').value = assessment.legal && $('theme').value === 'emoji'
|
|
? `[](${declarationURL}) **${assessment.badge}**`
|
|
: `[](${declarationURL})`;
|
|
$('json-code').value = manifestURL;
|
|
}
|
|
|
|
|
|
document.querySelectorAll('#article-fields select[data-review]').forEach(extentSelect => {
|
|
extentSelect.addEventListener('change', () => {
|
|
const reviewSelect = $(extentSelect.dataset.review);
|
|
if (!reviewSelect) return;
|
|
if (extentSelect.value === 'none') {
|
|
reviewSelect.value = 'none';
|
|
}
|
|
// For AI-assisted/generated components keep "none" until the publisher
|
|
// explicitly selects the review process that actually took place.
|
|
update(false);
|
|
});
|
|
});
|
|
|
|
function alignLegalContextWithContent(changedId) {
|
|
if (changedId === 'legal-deepfake' && $('legal-deepfake')?.checked) {
|
|
if ($('legal-other-voluntary')) $('legal-other-voluntary').checked = false;
|
|
if ($('declaration-mode').value === 'single') {
|
|
if ($('legal-public-interest')?.checked) {
|
|
$('declaration-mode').value = 'article';
|
|
} else if (!['coverImage', 'image', 'audio', 'video'].includes($('component').value)) {
|
|
$('preset').value = '';
|
|
$('component').value = 'image';
|
|
if ($('extent').value === 'none') $('extent').value = 'partial';
|
|
}
|
|
}
|
|
}
|
|
if (changedId === 'legal-public-interest' && $('legal-public-interest')?.checked) {
|
|
if ($('legal-other-voluntary')) $('legal-other-voluntary').checked = false;
|
|
if ($('declaration-mode').value === 'single') {
|
|
if ($('legal-deepfake')?.checked) {
|
|
$('declaration-mode').value = 'article';
|
|
} else {
|
|
$('preset').value = '';
|
|
$('component').value = 'text';
|
|
if ($('extent').value === 'none') $('extent').value = 'partial';
|
|
}
|
|
}
|
|
if ($('declaration-mode').value === 'article' && $('article-text').value === 'none') {
|
|
$('article-text').value = 'partial';
|
|
}
|
|
}
|
|
if (changedId === 'legal-creative' && $('legal-creative')?.checked && $('legal-other-voluntary')) {
|
|
$('legal-other-voluntary').checked = false;
|
|
}
|
|
if ($('declaration-mode').value === 'article' && $('legal-deepfake')?.checked) {
|
|
const media = ['article-cover-image', 'article-image'];
|
|
const hasMedia = media.some(id => $(id)?.value !== 'none');
|
|
if (!hasMedia && $('article-image')) $('article-image').value = 'partial';
|
|
}
|
|
}
|
|
|
|
['legal-deepfake', 'legal-public-interest', 'legal-creative'].forEach(id => {
|
|
$(id)?.addEventListener('change', () => alignLegalContextWithContent(id));
|
|
});
|
|
$('legal-other-voluntary')?.addEventListener('change', () => {
|
|
if (!$('legal-other-voluntary').checked) return;
|
|
['legal-deepfake', 'legal-public-interest', 'legal-creative'].forEach(id => { if ($(id)) $(id).checked = false; });
|
|
});
|
|
|
|
form.addEventListener('input', event => update(event.target.id === 'preset'));
|
|
form.addEventListener('change', event => update(event.target.id === 'preset'));
|
|
document.querySelector('.pro-panel')?.addEventListener('input', () => update(false));
|
|
$('copy-html')?.addEventListener('click', async () => {
|
|
await navigator.clipboard.writeText($('html-code').value);
|
|
const locale = cfg.locales[$('lang').value] || cfg.locales.en;
|
|
$('copy-html').textContent = locale.text.copied || 'Copied';
|
|
setTimeout(() => { $('copy-html').textContent = locale.text.copy_html || 'Copy HTML'; }, 1600);
|
|
});
|
|
$('page-language')?.addEventListener('change', event => {
|
|
const url = new URL(window.location.href);
|
|
url.searchParams.set('lang', event.target.value);
|
|
window.location.href = url.toString();
|
|
});
|
|
update(true);
|
|
})();
|