V2EX = way to explore
V2EX æ¯ä¸ä¸ªå
³äºåäº«åæ¢ç´¢çå°æ¹
`;
switch(displayFormat) {
case 'text-only':
html += `
`;
break;
case 'small-with-description':
html += `
${campaign.img_small_cid ? `
` : ''}
${description}
`;
break;
case 'banner-only':
html += `
`;
break;
case 'big-only':
html += `
`;
break;
case 'big-with-description':
html += `
`;
html += `
`;
break;
case 'big-with-title-description-button':
html += `
`;
html += `
`;
html += `
`;
break;
default:
html += `
`;
}
html += `
`
return html;
}
// Load campaign from emitter
var xhr = new XMLHttpRequest();
xhr.open('GET', '/pro/emitter', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
try {
var campaign = JSON.parse(xhr.responseText);
if (campaign && campaign.id) {
var html = renderCampaign(campaign);
document.getElementById('pro-campaign-container').innerHTML = html;
} else {
// No campaign to display, hide the container
document.getElementById('pro-campaign-container').style.display = 'none';
}
} catch (e) {
// Parse error, hide the container
document.getElementById('pro-campaign-container').style.display = 'none';
console.log('Error parsing campaign data: ' + e.message);
}
} else {
// HTTP error, hide the container
document.getElementById('pro-campaign-container').style.display = 'none';
console.log('Error loading campaign: HTTP ' + xhr.status);
}
}
};
xhr.send();
});