Skip to content

Instantly share code, notes, and snippets.

@ahmetozer
Created March 21, 2021 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmetozer/9188f0b9caf323e3210a06ad8fd5a55c to your computer and use it in GitHub Desktop.
Save ahmetozer/9188f0b9caf323e3210a06ad8fd5a55c to your computer and use it in GitHub Desktop.
Detect TLD links
var links = document.getElementsByTagName("a");
document.head.insertAdjacentHTML("beforeend", `<style>@keyframes intraT { 50% { opacity: 0; }}</style>`)
for (var i = 0; i < links.length; i++) {
let temp_url = ""
try {
temp_url = new URL(links[i].href);
} catch(err) {
temp_url = "err"
}
if (temp_url != "err") {
let a1 = temp_url.hostname.match(/\./g)
if (a1 == null && temp_url.hostname.length != 0 ){
links[i].style.color = "tomato"
links[i].style.animation= "intraT 1s linear infinite"
console.log(temp_url.hostname)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment