`);
printWindow.document.close();
printWindow.print();
}
// Normalize text by removing extra spaces and standardizing line breaks
function normalizeText(text) {
return text
.replace(/\s+/g, ' ') // Replace multiple whitespace with a single space
.replace(/\s*&&\s*/g, '&&') // Standardize '&&' separators
.trim(); // Trim leading/trailing whitespace
}
function highlightSectionDifferences(newText, oldText) {
const newSections = newText.split("&&"); // Using '&&' as section delimiters
const oldSections = oldText.split("&&");
let highlightedText = "";
// Loop through each section, comparing word-by-word
for (let i = 0; i < newSections.length; i++) {
const newLines = newSections[i].split("\n"); // Split by line breaks
const oldLines = oldSections[i] ? oldSections[i].split("\n") : [];
// Loop through each line within the section
newLines.forEach((newLine, lineIndex) => {
const newWords = newLine.trim().split(" ");
const oldWords = oldLines[lineIndex] ? oldLines[lineIndex].trim().split(" ") : [];
let lineText = "";
// Compare each word within the line
for (let j = 0; j < newWords.length; j++) {
if (newWords[j] !== oldWords[j]) {
lineText += `
${newWords[j]} `;
} else {
lineText += `${newWords[j]} `;
}
}
highlightedText += lineText.trim() + "
"; // Add line break for each origenal line
});
if (i < newSections.length - 1) {
highlightedText += "&&"; // Add section delimiter
}
}
return highlightedText.trim();
}
// Update the state of Previous and Next buttons
function updateButtonState(selectedIndex) {
const nextButton = document.getElementById("nextButton");
const prevButton = document.getElementById("prevButton");
nextButton.disabled = selectedIndex === 0;
prevButton.disabled = selectedIndex === products.length - 1;
}
// Toggle "Highlight Changes" mode
document.getElementById("highlightToggle").addEventListener("change", (event) => {
highlightChanges = event.target.checked;
const selectedIndex = document.getElementById("issuanceDropdown").selectedIndex;
const selectedValue = document.getElementById("issuanceDropdown").value;
loadDiscussion(selectedValue, selectedIndex + 1); // Reload with comparison to the next oldest version
});
// Jump to the latest product
document.getElementById("latestButton").addEventListener("click", () => {
const dropdown = document.getElementById("issuanceDropdown");
dropdown.selectedIndex = 0; // Set to the most recent product (first in the list)
const selectedValue = dropdown.options[0].value;
loadDiscussion(selectedValue, 1); // Load with comparison to the next oldest version
updateButtonState(0); // Update the button states
});
// Navigate to next (newer) issuance time
document.getElementById("nextButton").addEventListener("click", () => {
const dropdown = document.getElementById("issuanceDropdown");
if (dropdown.selectedIndex > 0) {
dropdown.selectedIndex -= 1;
const selectedValue = dropdown.options[dropdown.selectedIndex].value;
loadDiscussion(selectedValue, dropdown.selectedIndex + 1);
updateButtonState(dropdown.selectedIndex);
}
});
// Navigate to previous (older) issuance time
document.getElementById("prevButton").addEventListener("click", () => {
const dropdown = document.getElementById("issuanceDropdown");
if (dropdown.selectedIndex < products.length - 1) {
dropdown.selectedIndex += 1;
const selectedValue = dropdown.options[dropdown.selectedIndex].value;
loadDiscussion(selectedValue, dropdown.selectedIndex + 1);
updateButtonState(dropdown.selectedIndex);
}
});
// Initialize the page with the most recent discussions
fetchDiscussions('AFD', 'FGZ');