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

Add build

parent 97b04859
No related branches found
No related tags found
No related merge requests found
export declare const ELEMENT_TYPES_TO_REMOVE: {
br: boolean;
hr: boolean;
use: boolean;
svg: boolean;
BR: boolean;
HR: boolean;
USE: boolean;
SVG: boolean;
};
export declare const ATTRIBUTES_TO_KEEP: {
alt: boolean;
......@@ -13,7 +13,7 @@ export declare const ATTRIBUTES_TO_KEEP: {
href: boolean;
value: boolean;
};
export declare const amendNodes: (document: HTMLDocument) => void;
export declare const normalizeDocumentCommon: (body: HTMLElement) => void;
/**
* Decides whether node should be removed
* @param element
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneAnchorFromPane = exports.pruneElement = exports.amendNodes = exports.ATTRIBUTES_TO_KEEP = exports.ELEMENT_TYPES_TO_REMOVE = void 0;
exports.cloneAnchorFromPane = exports.pruneElement = exports.normalizeDocumentCommon = exports.ATTRIBUTES_TO_KEEP = exports.ELEMENT_TYPES_TO_REMOVE = void 0;
// this is a Node module. require is a must to work across different envs
const URL = require("url-parse");
const DUMMY_QR_CODE_ID = "dummyQrCode";
exports.ELEMENT_TYPES_TO_REMOVE = {
br: true,
hr: true,
use: true,
svg: true,
BR: true,
HR: true,
USE: true,
SVG: true,
};
exports.ATTRIBUTES_TO_KEEP = {
alt: true,
......@@ -19,11 +18,11 @@ exports.ATTRIBUTES_TO_KEEP = {
href: true,
value: true,
};
const amendNodes = (document) => {
const normalizeDocumentCommon = (body) => {
/**
* Unwind Outlook safelink wrappers
*/
const anchors = document.getElementsByTagName("a");
const anchors = body.getElementsByTagName("a");
for (const anchor of anchors) {
const url = new URL(anchor.getAttribute("href"), true);
if (url.host.includes("safelinks.protection.outlook.com")) {
......@@ -33,7 +32,7 @@ const amendNodes = (document) => {
/**
* Unwind Gmail "googleusercontent" wrappers
*/
const images = document.getElementsByTagName("img");
const images = body.getElementsByTagName("img");
for (const image of images) {
let url;
try {
......@@ -50,25 +49,13 @@ const amendNodes = (document) => {
}
}
};
exports.amendNodes = amendNodes;
/**
* Removes dummy QR code from HTML
* @param element
*/
const isDummyQrCode = (element) => {
if (element.id === DUMMY_QR_CODE_ID) {
return true;
}
};
exports.normalizeDocumentCommon = normalizeDocumentCommon;
/**
* Decides whether node should be removed
* @param element
*/
const pruneElement = (element) => {
if (isDummyQrCode(element)) {
return true;
}
return !!exports.ELEMENT_TYPES_TO_REMOVE[element.nodeName.toLowerCase()];
return !!exports.ELEMENT_TYPES_TO_REMOVE[element.nodeName];
};
exports.pruneElement = pruneElement;
const cloneAnchorFromPane = (a, pane) => {
......
export declare const pruneGmailElement: (element: HTMLElement) => boolean;
export declare const amendGmailNodes: (document: HTMLDocument) => void;
export declare const cleanupGMailElementAttributes: (element: HTMLElement) => void;
export declare const normalizeGmailDocument: (document: HTMLDocument) => void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanupGMailElementAttributes = exports.amendGmailNodes = exports.pruneGmailElement = void 0;
exports.normalizeGmailDocument = void 0;
const common_1 = require("./common");
const constants_1 = require("../../constants");
const pruneGmailElement = (element) => {
return common_1.pruneElement(element);
};
exports.pruneGmailElement = pruneGmailElement;
const qrCodeContainerIds = { vereignWrapperLink: 1 };
const removeQrCodeNodes = (document) => {
const remove = (node) => {
......@@ -29,11 +25,10 @@ const removeQrCodeNodes = (document) => {
const elementsToRemove = remove(document.body);
elementsToRemove.forEach((element) => element.parentNode.removeChild(element));
};
const amendGmailNodes = (document) => {
// unwindTags(document, "span");
const normalizeGmailDocument = (document) => {
removeQrCodeNodes(document);
/**
* Look for attachments panes and remove everything but links
* Look for attachments panes and extract <a> tags from them
*/
const attachmentsPanes = Array.from(document.getElementsByClassName("gmail_chip"));
attachmentsPanes.forEach((pane) => {
......@@ -46,21 +41,4 @@ const amendGmailNodes = (document) => {
pane.parentNode.removeChild(pane);
});
};
exports.amendGmailNodes = amendGmailNodes;
const cleanupGMailElementAttributes = (element) => {
if (element.attributes.length > 0) {
for (const attribute of element.attributes) {
if (attribute.name === "data-surl") {
element.setAttribute("src", attribute.value);
}
}
for (let i = 0; i < element.attributes.length; i++) {
const attribute = element.attributes[i];
if (!common_1.ATTRIBUTES_TO_KEEP[attribute.name]) {
element.removeAttribute(attribute.name);
i--;
}
}
}
};
exports.cleanupGMailElementAttributes = cleanupGMailElementAttributes;
exports.normalizeGmailDocument = normalizeGmailDocument;
export declare const printOutlookElement: (node: Node) => string;
/**
* Returns true if element should be completely removed
* @param element
*/
export declare const pruneOutlookElement: (element: HTMLElement) => boolean;
export declare const amendOutlookNodes: (document: HTMLDocument) => void;
export declare const cleanupOutlookElementAttributes: (element: HTMLElement) => void;
export declare const normalizeOutlookDocument: (document: HTMLDocument) => void;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment