1import { createC2pa } from '/TemplatePackage/contrib/libs/c2pa/latest/c2pa.esm.min.js'; 2 3(async () => { 4 const ROOT = String(window.CDC?.tpPath || '').trim(); 5 const c2pa = await createC2pa({ 6 wasmSrc: `${ROOT}/TemplatePackage/contrib/libs/c2pa/latest/toolkit_bg.wasm`, 7 workerSrc: `${ROOT}/TemplatePackage/contrib/libs/c2pa/latest/c2pa.worker.min.js`, 8 }); 9 10 const DEBUG = !!window.location?.search?.includes('cdcdebug'); 11 const manifests = {}; 12 13 // expose as recallable method 14 window.cdcc2paCheck = () => { 15 Array.from(document.getElementsByTagName('img')).forEach(async (image) => { 16 // skip images in page headers, footers, or non-indexed content, or images already checked 17 if (image?.closest('header, footer, .noindex, #hero-carousel')) { 18 return; 19 } 20 // skip some extensions 21 if (!image.src || image.src.match(/\.(svg|axd|gif|bmp)([#\?]|$)/i)) { 22 return; 23 } 24 25 let manifestStore = null; 26 if (manifests.hasOwnProperty(image.src)) { 27 manifestStore = manifests[image.src]; 28 } else { 29 // Get a manifest store for the image 30 try { 31 let manifest = await c2pa.read(image); 32 manifestStore = manifest.manifestStore; 33 } catch (e) { 34 DEBUG && console.error(`C2R: failed checking image:`, image, e); 35 return; 36 } 37 manifests[image.src] = manifestStore 38 } 39 const manifestFlat = JSON.stringify(manifestStore?.activeManifest?.assertions?.data || {}); 40 const manifestCheck = manifestFlat.includes('cv.iptc.org/newscodes/digitalsourcetype/compositeWithTrainedAlgorithmicMedia') || 41 manifestFlat.includes('cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia'); 42 43 DEBUG && console.info(`C2R: ${manifestCheck?'Y':'n'}`, image, manifestStore); 44 if (manifestStore && manifestCheck) { 45 const details = { 46 generator: String(manifestStore.activeManifest?.claimGenerator || ''), 47 tools: [], 48 issuer: '', 49 date: '', 50 }; 51 if (Array.isArray(manifestStore.activeManifest?.assertions?.data)) { 52 manifestStore.activeManifest.assertions.data.forEach((assertion) => { 53 let assertionData = assertion?.data; 54 if (assertionData) { 55 assertionData.actions.forEach((action) => { 56 if (action.digitalSourceType.includes('cv.iptc.org/newscodes/digitalsourcetype/compositeWithTrainedAlgorithmicMedia') || 57 action.digitalSourceType.includes('cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia')) { 58 details.tools.push(action?.softwareAgent); 59 } 60 }); 61 } 62 }); 63 } 64 details.issuer = String(manifestStore.activeManifest?.signatureInfo?.issuer || ''); 65 details.date = String(manifestStore.activeManifest?.signatureInfo?.time || ''); 66 // dispatch event and flag to avoid retriggering 67 image.dispatchEvent(new CustomEvent('cdc-image-c2r', { detail: details, bubbles: true })); 68 } 69 }); 70 } 71 if (document.readyState === 'loading') { 72 document.addEventListener('DOMContentLoaded', window.cdcc2paCheck); 73 } else { 74 window.cdcc2paCheck(); 75 } 76})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.