This commit is contained in:
Josh at WLTechBlog
2025-12-16 14:01:21 -07:00
parent 148b948a4b
commit 6f9839ee86

View File

@@ -13059,20 +13059,20 @@ func (d *Daemon) extractDiviStructure(tabID string, timeout int) (*DiviStructure
} }
// JavaScript to extract Divi structure // JavaScript to extract Divi structure
jsCode := ` // Note: page.Eval expects a function expression, not an IIFE
(function() { jsCode := `() => {
const result = { const result = {
url: window.location.href, url: window.location.href,
sections: [], sections: [],
metadata: { metadata: {
extraction_date: new Date().toISOString(), extraction_date: new Date().toISOString(),
accuracy: "60-70% (approximation from CSS classes)", accuracy: "60-70% (approximation from CSS classes)",
limitations: "Cannot access original Divi shortcode/JSON or builder settings" limitations: "Cannot access original Divi shortcode/JSON or builder settings"
} }
}; };
// Find all Divi sections // Find all Divi sections
const sections = document.querySelectorAll('.et_pb_section, .et_section_specialty, .et_pb_fullwidth_section'); const sections = document.querySelectorAll('.et_pb_section, .et_section_specialty, .et_pb_fullwidth_section');
sections.forEach((section, sectionIndex) => { sections.forEach((section, sectionIndex) => {
const sectionData = { const sectionData = {
@@ -13198,8 +13198,7 @@ func (d *Daemon) extractDiviStructure(tabID string, timeout int) (*DiviStructure
}); });
return result; return result;
})(); }`
`
// Execute JavaScript with timeout // Execute JavaScript with timeout
var resultData interface{} var resultData interface{}
@@ -13265,53 +13264,52 @@ func (d *Daemon) extractDiviImages(tabID string, timeout int) ([]DiviImage, erro
} }
// JavaScript to extract images // JavaScript to extract images
jsCode := ` // Note: page.Eval expects a function expression, not an IIFE
(function() { jsCode := `() => {
const images = []; const images = [];
let imageIndex = 0; let imageIndex = 0;
// Extract regular images // Extract regular images
document.querySelectorAll('img').forEach((img) => { document.querySelectorAll('img').forEach((img) => {
if (img.src && img.src !== '') { if (img.src && img.src !== '') {
images.push({
url: img.src,
alt: img.alt || '',
title: img.title || '',
width: img.naturalWidth || img.width || 0,
height: img.naturalHeight || img.height || 0,
context: 'image ' + imageIndex,
is_background: false
});
imageIndex++;
}
});
// Extract background images
document.querySelectorAll('*').forEach((element) => {
const styles = window.getComputedStyle(element);
const bgImage = styles.backgroundImage;
if (bgImage && bgImage !== 'none' && !bgImage.includes('gradient')) {
// Extract URL from background-image
const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/);
if (urlMatch && urlMatch[1]) {
images.push({ images.push({
url: img.src, url: urlMatch[1],
alt: img.alt || '', alt: '',
title: img.title || '', title: '',
width: img.naturalWidth || img.width || 0, width: 0,
height: img.naturalHeight || img.height || 0, height: 0,
context: 'image ' + imageIndex, context: 'background ' + imageIndex,
is_background: false is_background: true
}); });
imageIndex++; imageIndex++;
} }
}); }
});
// Extract background images return images;
document.querySelectorAll('*').forEach((element) => { }`
const styles = window.getComputedStyle(element);
const bgImage = styles.backgroundImage;
if (bgImage && bgImage !== 'none' && !bgImage.includes('gradient')) {
// Extract URL from background-image
const urlMatch = bgImage.match(/url\(['"]?([^'"]+)['"]?\)/);
if (urlMatch && urlMatch[1]) {
images.push({
url: urlMatch[1],
alt: '',
title: '',
width: 0,
height: 0,
context: 'background ' + imageIndex,
is_background: true
});
imageIndex++;
}
}
});
return images;
})();
`
// Execute JavaScript with timeout // Execute JavaScript with timeout
var resultData interface{} var resultData interface{}
@@ -13377,21 +13375,21 @@ func (d *Daemon) extractDiviContent(tabID string, timeout int) (*DiviContent, er
} }
// JavaScript to extract content // JavaScript to extract content
jsCode := ` // Note: page.Eval expects a function expression, not an IIFE
(function() { jsCode := `() => {
const result = { const result = {
url: window.location.href, url: window.location.href,
modules: [], modules: [],
images: [], images: [],
metadata: { metadata: {
extraction_date: new Date().toISOString(), extraction_date: new Date().toISOString(),
total_modules: 0, total_modules: 0,
total_images: 0 total_images: 0
} }
}; };
// Extract all Divi modules // Extract all Divi modules
const modules = document.querySelectorAll('[class*="et_pb_module"]'); const modules = document.querySelectorAll('[class*="et_pb_module"]');
modules.forEach((module, index) => { modules.forEach((module, index) => {
const moduleData = { const moduleData = {
@@ -13458,8 +13456,7 @@ func (d *Daemon) extractDiviContent(tabID string, timeout int) (*DiviContent, er
result.metadata.total_images = result.images.length; result.metadata.total_images = result.images.length;
return result; return result;
})(); }`
`
// Execute JavaScript with timeout // Execute JavaScript with timeout
var resultData interface{} var resultData interface{}