globalseo
Advanced tools
Comparing version 2.2.10 to 2.2.11
@@ -6,2 +6,23 @@ const { isBrowser, BRAND } = require("./utils/configs"); | ||
function replaceCustomLinks(window, customLinks = {}) { | ||
// find all tags with href and src | ||
const tagsWithSrc = window.document.querySelectorAll("[src]"); | ||
const tagsWithHref = window.document.querySelectorAll("[href]"); | ||
// replace the links | ||
for (let tag of tagsWithSrc) { | ||
const src = tag.getAttribute("src"); | ||
if (customLinks[src]) { | ||
tag.setAttribute("src", customLinks[src]); | ||
} | ||
} | ||
for (let tag of tagsWithHref) { | ||
const href = tag.getAttribute("href"); | ||
if (customLinks[href]) { | ||
tag.setAttribute("href", customLinks[href]); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -56,2 +77,3 @@ * Extracts options from a script. | ||
const DATA_DOMAIN_SOURCE_PREFIX = "data-domain-source-prefix" | ||
const DATA_CUSTOM_LINKS = "data-custom-links" | ||
@@ -64,2 +86,17 @@ const DATA_TRANSLATION_CACHE = "data-translation-cache"; | ||
const customLinksAttribute = window.translationScriptTag.getAttribute(DATA_CUSTOM_LINKS); | ||
let customLinks = {}; | ||
try { | ||
// format: [oldUrl,newUrl], [oldUrl,newUrl] | ||
const parsed = JSON.parse(`[${customLinksAttribute}]`); | ||
customLinks = parsed.reduce((acc, [oldUrl, newUrl]) => { | ||
acc[oldUrl] = newUrl; | ||
return acc; | ||
}, {}); | ||
replaceCustomLinks(window, customLinks); | ||
} catch (e) { | ||
customLinks = {}; | ||
} | ||
const DATA_ACTIVE_SUBDOMAIN = "data-active-subdomain"; // default: undefined | ||
@@ -370,3 +407,4 @@ const activeSubdomain = window.translationScriptTag.getAttribute(DATA_ACTIVE_SUBDOMAIN); | ||
translationMode, | ||
domainSourcePrefix | ||
domainSourcePrefix, | ||
customLinks, | ||
} | ||
@@ -373,0 +411,0 @@ } |
{ | ||
"name": "globalseo", | ||
"version": "2.2.10", | ||
"version": "2.2.11", | ||
"description": "Translate your React.js or Next.js app with AI", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
568569
3543