Mammada ya Alia? a LinkedIn analysis

Extract and display top 5 first names, last names, and occupations from LinkedIn connections

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Mammada ya Alia? a LinkedIn analysis 
// @namespace    http://github.com/armanjr
// @version      1.1
// @description  Extract and display top 5 first names, last names, and occupations from LinkedIn connections
// @match        https://www.linkedin.com/mynetwork/invite-connect/connections/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let connections = [];

    // Create a status indicator element
    const statusIndicator = document.createElement('div');
    statusIndicator.style.position = 'fixed';
    statusIndicator.style.left = '50%';
    statusIndicator.style.top = '50%';
    statusIndicator.style.transform = 'translate(-50%, -50%)';
    statusIndicator.style.padding = '10px';
    statusIndicator.style.backgroundColor = 'white';
    statusIndicator.style.color = 'red';
    statusIndicator.style.border = '2px solid black';
    statusIndicator.style.zIndex = '1000';
    statusIndicator.innerText = 'Please wait...';
    document.body.appendChild(statusIndicator);

    function showStatusIndicator() {
        statusIndicator.style.display = 'block';
    }

    function hideStatusIndicator() {
        statusIndicator.style.display = 'none';
    }

    function handleLoadMoreButton() {
        const loadMoreButton = document.querySelector('.scaffold-finite-scroll__load-button');
        if (loadMoreButton) {
            loadMoreButton.click();
            setTimeout(scrollToEnd, 3000);
        } else {
            scrollToEnd();
        }
    }

    function scrollToEnd() {
        showStatusIndicator();
        window.scrollTo(0, document.body.scrollHeight);
        setTimeout(checkIfEndReached, 3000);
    }

    function checkIfEndReached() {
        let currentConnections = document.querySelectorAll('.mn-connection-card__details').length;
        if (connections.length !== currentConnections) {
            connections = document.querySelectorAll('.mn-connection-card__details');
            handleLoadMoreButton();
        } else {
            hideStatusIndicator();
            extractData();
        }
    }

    function getTop5(countMap) {
        return Object.entries(countMap)
                     .sort((a, b) => b[1] - a[1])
                     .slice(0, 5)
                     .map(entry => `${entry[0]} (${entry[1]})`)
                     .join(', ');
    }

    function extractData() {
        let firstNameCounts = {};
        let lastNameCounts = {};
        let occupationCounts = {};

        connections.forEach(connection => {
            let fullName = connection.querySelector('.mn-connection-card__name')?.innerText.trim();
            let occupation = connection.querySelector('.mn-connection-card__occupation')?.innerText.trim();

            if (fullName && occupation) {
                let names = fullName.split(' ');
                let firstName = names[0];
                let lastName = names[names.length - 1];

                firstNameCounts[firstName] = (firstNameCounts[firstName] || 0) + 1;
                lastNameCounts[lastName] = (lastNameCounts[lastName] || 0) + 1;
                occupationCounts[occupation] = (occupationCounts[occupation] || 0) + 1;
            }
        });

        let topFirstNames = getTop5(firstNameCounts);
        let topLastNames = getTop5(lastNameCounts);
        let topOccupations = getTop5(occupationCounts);

        alert('Top 5 First Names: ' + topFirstNames +
              '\nTop 5 Last Names: ' + topLastNames +
              '\nTop 5 Occupations: ' + topOccupations);
    }

    scrollToEnd();
})();