Skip to content
Snippets Groups Projects
Commit 474c45bf authored by Igor Markin's avatar Igor Markin
Browse files

Add build

parent 0ecd0f57
No related branches found
No related tags found
No related merge requests found
...@@ -105,7 +105,7 @@ const normalizeVendorHtml = (htmlString, vendor) => { ...@@ -105,7 +105,7 @@ const normalizeVendorHtml = (htmlString, vendor) => {
const { window } = new JSDOM(htmlString); const { window } = new JSDOM(htmlString);
document = window.document; document = window.document;
} }
const mimeBody = document.firstChild.lastChild; const mimeBody = document.body;
const amendNodesFunction = vendorAmendingFunctions[vendor]; const amendNodesFunction = vendorAmendingFunctions[vendor];
if (amendNodesFunction) { if (amendNodesFunction) {
amendNodesFunction(document); amendNodesFunction(document);
......
...@@ -53,46 +53,58 @@ exports.amendOutlookNodes = (document) => { ...@@ -53,46 +53,58 @@ exports.amendOutlookNodes = (document) => {
/** /**
* Get rid of attachments panes * Get rid of attachments panes
*/ */
const attachmentsPanes = document.querySelectorAll("#OwaReferenceAttachments"); const attachmentsPanesConatiner = document.getElementById("OwaReferenceAttachments");
const attachmentsPanesEnds = document.querySelectorAll("#OwaReferenceAttachmentsEnd"); const attachmentsPanesContainerEnd = document.getElementById("OwaReferenceAttachmentsEnd");
attachmentsPanesEnds.forEach((pane) => pane.parentNode.removeChild(pane)); if (attachmentsPanesConatiner) {
attachmentsPanes.forEach((pane) => { const as = attachmentsPanesConatiner.getElementsByTagName("a");
const as = pane.querySelectorAll("a"); Array.from(as).forEach((a) => {
as.forEach((a) => { cloneAnchorFromPane(a, attachmentsPanesConatiner);
cloneAnchorFromPane(a, pane);
}); });
}); attachmentsPanesConatiner.parentNode.removeChild(attachmentsPanesConatiner);
attachmentsPanes.forEach((pane) => { }
pane.parentNode.removeChild(pane); attachmentsPanesContainerEnd &&
}); attachmentsPanesContainerEnd.parentNode.removeChild(attachmentsPanesContainerEnd);
/** /**
* Unwind spans, because sometimes Outlook wraps everything into span after sending * Unwind spans, because sometimes Outlook wraps everything into span after sending
*/ */
const spans = document.querySelectorAll("span"); const spans = document.getElementsByTagName("span");
spans.forEach((span) => { /**
let child = span.firstChild; * Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans
while (child) { */
if (child.nodeName.toLowerCase() === "span") { const spansDepths = {};
Array.from(spans).forEach((span) => {
let descendant = span;
let parent = descendant.parentNode;
let depth = 0;
while (parent && descendant !== parent) {
descendant = parent;
parent = descendant.parentNode;
depth++;
}
if (!spansDepths[depth]) {
spansDepths[depth] = [];
}
spansDepths[depth].push(span);
});
Object.keys(spansDepths)
.sort((a, b) => parseInt(b) - parseInt(a))
.forEach((depth) => {
spansDepths[depth].forEach((span) => {
let child = span.firstChild;
const parent = span.parentNode;
while (child) {
parent.insertBefore(child.cloneNode(true), span);
child = child.nextSibling; child = child.nextSibling;
continue;
}
let parent = span.parentNode;
let lastSpan = span;
while (parent && parent.nodeName.toLowerCase() === "span") {
lastSpan = parent;
parent = parent.parentNode;
} }
parent.insertBefore(child.cloneNode(true), lastSpan); span.parentNode.removeChild(span);
child = child.nextSibling; });
}
}); });
spans.forEach((span) => span.parentNode.removeChild(span));
}; };
exports.amendGmailNodes = (document) => { exports.amendGmailNodes = (document) => {
/** /**
* Look for attachments panes and remove everything but liks * Look for attachments panes and remove everything but liks
*/ */
const attachmentsPanes = document.querySelectorAll(".gmail_chip"); const attachmentsPanes = Array.from(document.getElementsByClassName("gmail_chip"));
attachmentsPanes.forEach((pane) => { attachmentsPanes.forEach((pane) => {
const as = pane.querySelectorAll("a"); const as = pane.querySelectorAll("a");
as.forEach((a) => { as.forEach((a) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment