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