Extract Social media

by Ryan Perez

JavaScript

// Find all anchor tags on the page
var anchors = document.getElementsByTagName("a");

// Loop through all anchor tags
for (var i = 0; i < anchors.length; i++) {
    var anchor = anchors[i];
    var href = anchor.getAttribute("href");

    // Check if the href value contains the string "facebook"
    if (href != null && href.indexOf("facebook") > -1) {
        console.log("Facebook link found: " + href);
    }
    // Check if the href value contains the string "twitter"
    else if (href != null && href.indexOf("twitter") > -1) {
        console.log("Twitter link found: " + href);
    }
    // Check if the href value contains the string "instagram"
    else if (href != null && href.indexOf("instagram") > -1) {
        console.log("Instagram link found: " + href);
    }
    // Check if the href value contains the string "linkedin"
    else if (href != null && href.indexOf("linkedin") > -1) {
        console.log("LinkedIn link found: " + href);
    }
    // Check if the href value contains the string "youtube"
    else if (href != null && href.indexOf("youtube") > -1) {
        console.log("Youtube link found: " + href);
    }
}