Skip to content
Snippets Groups Projects

Use url-parse

Merged Igor Markin requested to merge use-url-parse into master
7 files
+ 26
16
Compare changes
  • Side-by-side
  • Inline
Files
7
"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;
const url_parse_1 = require("url-parse");
const DUMMY_QR_CODE_ID = "dummyQrCode";
exports.ELEMENT_TYPES_TO_REMOVE = {
br: true,
@@ -23,10 +24,9 @@ const amendNodes = (document) => {
*/
const anchors = document.getElementsByTagName("a");
for (const anchor of anchors) {
const url = new URL(anchor.getAttribute("href"));
const url = new url_parse_1.default(anchor.getAttribute("href"), true);
if (url.host.includes("safelinks.protection.outlook.com")) {
const originalUrl = new URL(url.searchParams.get("url"));
anchor.setAttribute("href", originalUrl.href);
anchor.setAttribute("href", url.query["url"]);
}
}
};
@@ -53,7 +53,7 @@ const pruneElement = (element) => {
exports.pruneElement = pruneElement;
const cloneAnchorFromPane = (a, pane) => {
try {
const url = new URL(a.getAttribute("href"));
const url = new url_parse_1.default(a.getAttribute("href"));
// If this is external url
if (url.host && url.protocol) {
pane.parentNode.insertBefore(a.cloneNode(false), pane);
Loading