Created
May 23, 2020 12:28
-
-
Save Feroz-Istar/029975d392a7031a37c7e4c09768d156 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var replaceTextInNode = function (parentNode) { | |
for (var i = parentNode.childNodes.length - 1; i >= 0; i--) { | |
var node = parentNode.childNodes[i]; | |
// Make sure this is a text node | |
if (node.nodeType == Element.TEXT_NODE && (node.parentNode.tagName == undefined || !/SCRIPT|STYLE/.test(node.parentNode.tagName))) { | |
if (node.textContent && node.textContent.trim()) { | |
console.log(node.textContent); | |
if (ValidatePhoneNumber(node.textContent)) { | |
console.log('phone number is >>>> ' + node.textContent); | |
try { | |
node.parentNode.style.backgroundColor = "red"; | |
} catch (error) { | |
console.log(error) | |
} | |
} | |
} | |
} else if (node.nodeType == Element.ELEMENT_NODE) { | |
// Check this node's child nodes for text nodes to act on | |
replaceTextInNode(node); | |
} | |
} | |
}; | |
function ValidatePhoneNumber(phone) { | |
var phoneExp = /(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?/img; | |
return phoneExp.test(phone); | |
} | |
window.addEventListener('load', function () { | |
replaceTextInNode(document.body); | |
}); | |
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { | |
if (changeInfo.url) { | |
chrome.tabs.query({}, function (tabs) { | |
console.log('senidng messgae') | |
var message = { action: "urlload", senddata: changeInfo.url }; | |
setTimeout(function () { | |
for (var i = 0; i < tabs.length; i++) { | |
chrome.tabs.sendMessage(tabs[i].id, message); | |
} | |
}, 4500); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment