Skip to content

Commit

Permalink
dont translate url
Browse files Browse the repository at this point in the history
  • Loading branch information
jemikanegara committed Nov 29, 2023
1 parent db3cb2e commit 4aeaf4c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ const debounce = (mainFunction, delay = 2000) => {
};
};

function isURL(str) {
const pattern = new RegExp("^(https?:\\/\\/)?"+ // protocol
"((([a-zA-Z\\d]([a-zA-Z\\d-]*[a-zA-Z\\d])*)\\.)+[a-zA-Z]{2,})"+ // domain name and extension
"(\\:\\d+)?(\\/[-a-zA-Z\\d%_.~+]*)*"+ // port and path
"(\\?[;&a-zA-Z\\d%_.~+=-]*)?"+ // query string
"(\\#[-a-zA-Z\\d_]*)?$", "i"); // fragment locator
return !!pattern.test(str);
}

function getWeployOptions() {
if (isBrowser) return window.weployOptions;
return weployOptions;
Expand Down Expand Up @@ -152,6 +161,16 @@ function extractTextNodes(node, textNodes) {
if (node.parentNode.tagName && node.parentNode.tagName.toUpperCase() == "INPUT") return;
if (node.parentNode.tagName && node.parentNode.tagName.toUpperCase() == "STYLE") return;
if (node.parentNode.tagName && node.parentNode.tagName.toUpperCase() == "NOSCRIPT") return;

// Check if the text node is a URL
const urlPattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'(((a-z\\d*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
if(urlPattern.test(node.textContent)) return;

textNodes.push(node);
} else {
// filter out weploy-exclude
Expand Down

0 comments on commit 4aeaf4c

Please sign in to comment.