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

Add build

parent 0ecd0f57
Branches
Tags
No related merge requests found
......@@ -105,7 +105,7 @@ const normalizeVendorHtml = (htmlString, vendor) => {
const { window } = new JSDOM(htmlString);
document = window.document;
}
const mimeBody = document.firstChild.lastChild;
const mimeBody = document.body;
const amendNodesFunction = vendorAmendingFunctions[vendor];
if (amendNodesFunction) {
amendNodesFunction(document);
......
......@@ -53,46 +53,58 @@ exports.amendOutlookNodes = (document) => {
/**
* Get rid of attachments panes
*/
const attachmentsPanes = document.querySelectorAll("#OwaReferenceAttachments");
const attachmentsPanesEnds = document.querySelectorAll("#OwaReferenceAttachmentsEnd");
attachmentsPanesEnds.forEach((pane) => pane.parentNode.removeChild(pane));
attachmentsPanes.forEach((pane) => {
const as = pane.querySelectorAll("a");
as.forEach((a) => {
cloneAnchorFromPane(a, pane);
const attachmentsPanesConatiner = document.getElementById("OwaReferenceAttachments");
const attachmentsPanesContainerEnd = document.getElementById("OwaReferenceAttachmentsEnd");
if (attachmentsPanesConatiner) {
const as = attachmentsPanesConatiner.getElementsByTagName("a");
Array.from(as).forEach((a) => {
cloneAnchorFromPane(a, attachmentsPanesConatiner);
});
});
attachmentsPanes.forEach((pane) => {
pane.parentNode.removeChild(pane);
});
attachmentsPanesConatiner.parentNode.removeChild(attachmentsPanesConatiner);
}
attachmentsPanesContainerEnd &&
attachmentsPanesContainerEnd.parentNode.removeChild(attachmentsPanesContainerEnd);
/**
* Unwind spans, because sometimes Outlook wraps everything into span after sending
*/
const spans = document.querySelectorAll("span");
spans.forEach((span) => {
let child = span.firstChild;
while (child) {
if (child.nodeName.toLowerCase() === "span") {
const spans = document.getElementsByTagName("span");
/**
* Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans
*/
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;
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);
child = child.nextSibling;
}
span.parentNode.removeChild(span);
});
});
spans.forEach((span) => span.parentNode.removeChild(span));
};
exports.amendGmailNodes = (document) => {
/**
* 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) => {
const as = pane.querySelectorAll("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