";
} else {
const tempLoadingDiv = document.querySelector("div.widget.HTML[id='" + (currentScriptElement && currentScriptElement.closest('.widget') ? currentScriptElement.closest('.widget').id : '') + "'] .afcm-loading");
if(tempLoadingDiv) tempLoadingDiv.textContent = "Error de inicialización del módulo AFCM.";
console.error("AFCM: Placeholder div no encontrado o mal ubicado.");
return;
}
let blogHomepageUrl = '';
if (typeof BLOG_CMT_domain == 'string' && BLOG_CMT_domain !== '') {
blogHomepageUrl = window.location.protocol + '//' + BLOG_CMT_domain;
} else if (typeof _WidgetManager != 'undefined' && _WidgetManager._bfo && _WidgetManager._bfo.baseUrl) {
blogHomepageUrl = _WidgetManager._bfo.baseUrl.replace(/\/$/, '');
} else {
blogHomepageUrl = window.location.origin;
}
let featuredTag = 'DESTACADO'; // Etiqueta por defecto
if (widgetRootElement && widgetRootElement.previousElementSibling &&
widgetRootElement.previousElementSibling.classList.contains('afcm-widget-config-tag')) {
const configTagDiv = widgetRootElement.previousElementSibling;
if (configTagDiv && configTagDiv.textContent && configTagDiv.textContent.trim() !== "") {
featuredTag = configTagDiv.textContent.trim();
}
} else {
const bloggerWidgetContainer = currentScriptElement.closest('.widget.HTML');
if (bloggerWidgetContainer) {
const configTagDivInBloggerWidget = bloggerWidgetContainer.querySelector(".afcm-widget-config-tag");
if (configTagDivInBloggerWidget && configTagDivInBloggerWidget.textContent && configTagDivInBloggerWidget.textContent.trim() !== "") {
featuredTag = configTagDivInBloggerWidget.textContent.trim();
}
}
}
const NUM_POSTS_TOTAL = 5; // 1 principal + 4 secundarios
const DEFAULT_THUMBNAIL_URL = "https://via.placeholder.com/1200x675.png?text=Sin+Imagen"; // Placeholder más grande
window[callbackFunctionName] = function(json) {
const postsDisplayArea = document.getElementById(postsDisplayAreaId);
if (!postsDisplayArea) return;
postsDisplayArea.innerHTML = ''; // Limpiar el mensaje de "Cargando"
function escapeHtml(unsafe) {
if (typeof unsafe !== 'string') return '';
const div = document.createElement('div');
div.appendChild(document.createTextNode(unsafe));
return div.innerHTML;
}
function getPostImage(entry) {
if (entry.media$thumbnail && entry.media$thumbnail.url) {
let thumbnailUrl = entry.media$thumbnail.url;
if (thumbnailUrl.includes("img.youtube.com/vi/")) {
const videoIdMatch = thumbnailUrl.match(/\/vi\/([a-zA-Z0-9_-]{11})\//);
if (videoIdMatch && videoIdMatch[1]) {
return `https://img.youtube.com/vi/${videoIdMatch[1]}/sddefault.jpg`; // o hqdefault.jpg
}
return thumbnailUrl;
} else {
return thumbnailUrl.replace(/\/s[0-9]+(-c)?\//, '/s1200/'); // Solicitar imagen grande
}
}
if (entry.content && entry.content.$t) {
const content = entry.content.$t;
const proxyRegex = /(https:\/\/lh3\.googlecontent\.com\/blogger_img_proxy\/[^"']+(?:=w\d+-h\d+[^"']*)?)/g;
let matches = content.match(proxyRegex);
if (matches && matches.length > 0) {
let bestMatch = matches[0];
bestMatch = bestMatch.replace(/=w\d+[^"']*/, '=s1200').replace(/=s\d+[^"']*/, '=s1200');
return bestMatch;
}
const imgRegex = /
![]()
]+src="([^">]+)"/i;
const imgMatch = content.match(imgRegex);
if (imgMatch && imgMatch[1]) {
let imgSrc = imgMatch[1];
if (imgSrc.includes("googlecontent.com/") && !imgSrc.includes("blogger_img_proxy")) {
imgSrc = imgSrc.replace(/\/s[0-9]+(-c)?\//, '/s1200/');
}
return imgSrc;
}
}
return DEFAULT_THUMBNAIL_URL;
}
function createSnippet(content, length = 100) {
if (!content) return '';
const tempDiv = document.createElement('div');
tempDiv.innerHTML = content;
let text = tempDiv.textContent || tempDiv.innerText || "";
text = text.replace(/\s+/g, ' ').trim();
return text.length > length ? escapeHtml(text.substring(0, length)) + '...' : escapeHtml(text);
}
function createPostItemHtml(postEntry, itemType) { // itemType: 'main' o 'secondary'
const postTitle = postEntry.title.$t;
const postUrlEntry = postEntry.link.find(link => link.rel === 'alternate');
const postUrl = postUrlEntry ? postUrlEntry.href : '#';
const imageUrl = getPostImage(postEntry);
let snippetText = '';
let snippetLength = itemType === 'main' ? 150 : 80; // Más largo para el principal
const summary = postEntry.summary && postEntry.summary.$t ? postEntry.summary.$t : (postEntry.content ? postEntry.content.$t : '');
snippetText = createSnippet(summary, snippetLength);
let itemHtml = `
${escapeHtml(postTitle)} 492h
`;
if (snippetText && itemType === 'main') { // Solo snippet para el principal
itemHtml += `
${snippetText} 3t261c
`;
}
itemHtml += `
`;
return itemHtml;
}
if (!json.feed || !json.feed.entry || json.feed.entry.length === 0) {
postsDisplayArea.innerHTML = "
No se encontraron posts con la etiqueta '" + escapeHtml(featuredTag) + "'.
";
return;
}
const posts = json.feed.entry;
let mainPostHtml = "";
let secondaryPostsHtml = "";
// Post Principal
if (posts[0]) {
mainPostHtml = createPostItemHtml(posts[0], 'main');
}
// Posts Secundarios
if (posts.length > 1) {
for (let i = 1; i < Math.min(posts.length, NUM_POSTS_TOTAL); i++) {
secondaryPostsHtml += createPostItemHtml(posts[i], 'secondary');
}
}
let finalHtml = "";
if (mainPostHtml) {
finalHtml += `
${mainPostHtml}
`;
}
if (secondaryPostsHtml) {
finalHtml += `
${secondaryPostsHtml}
`;
}
if (finalHtml === "") {
postsDisplayArea.innerHTML = "
No hay suficientes posts para mostrar con la etiqueta '" + escapeHtml(featuredTag) + "'.
";
} else {
postsDisplayArea.innerHTML = finalHtml;
}
};
if (!blogHomepageUrl) {
if (widgetRootElement) widgetRootElement.innerHTML = "
Error: No se pudo determinar la URL del blog.
";
return;
}
const feedUrl = blogHomepageUrl +
"/feeds/posts/default/-/" + encodeURIComponent(featuredTag) +
"?alt=json-in-script" +
"&max-results=" + NUM_POSTS_TOTAL +
"&callback=" + callbackFunctionName;
const feedScript = document.createElement('script');
feedScript.type = 'text/javascript';
feedScript.src = feedUrl;
feedScript.onerror = function() {
const postsDisplayArea = document.getElementById(postsDisplayAreaId);
if (postsDisplayArea) postsDisplayArea.innerHTML = "
Error al cargar los posts.
";
};
document.body.appendChild(feedScript);
})();
//]]>
Follow us on social networks! 735o49