Company Name Extractor with Block List (Enhanced)

Extract and manage company names from job listings on LinkedIn job search, with immediate blocking and interactive UI for managing blocked companies.

2024/04/08のページです。最新版はこちら

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Company Name Extractor with Block List (Enhanced)
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Extract and manage company names from job listings on LinkedIn job search, with immediate blocking and interactive UI for managing blocked companies.
// @author       Daniel Gleason
// @match        https://www.linkedin.com/jobs/*
// @grant        GM_setValue
// @grant        GM_getValue
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract and handle job postings based on company block list
    function handleJobPostings() {
        const jobPostings = document.querySelectorAll('div[data-job-id]');

        jobPostings.forEach(jobPosting => {
            const companyNameElement = jobPosting.querySelector('span.job-card-container__primary-description');
            if (companyNameElement) {
                const companyName = companyNameElement.innerText.trim();
                if (isCompanyBlocked(companyName)) {
                    // Company is blocked, remove the job posting div
                    jobPosting.remove();
                }
            }
        });
    }

    // Function to check if a company is blocked
    function isCompanyBlocked(companyName) {
        const blockedCompanies = getBlockedCompanies();
        return blockedCompanies.includes(companyName);
    }

    // Function to retrieve blocked companies from storage
    function getBlockedCompanies() {
        const blockedCompaniesJSON = GM_getValue('blockedCompanies', '[]');
        return JSON.parse(blockedCompaniesJSON);
    }

    // Function to save blocked companies to storage
    function saveBlockedCompanies(blockedCompanies) {
        const blockedCompaniesJSON = JSON.stringify(blockedCompanies);
        GM_setValue('blockedCompanies', blockedCompaniesJSON);
    }

    // Function to add a company to block list
    function addCompanyToBlockList(companyName) {
        let blockedCompanies = getBlockedCompanies();
        blockedCompanies.push(companyName.trim());
        saveBlockedCompanies(blockedCompanies);
    }

    // Function to remove a company from block list
    function removeCompanyFromBlockList(companyName) {
        let blockedCompanies = getBlockedCompanies();
        const index = blockedCompanies.indexOf(companyName.trim());
        if (index !== -1) {
            blockedCompanies.splice(index, 1);
            saveBlockedCompanies(blockedCompanies);
        }
    }

    // Function to display the blocked companies UI
    function displayBlockedCompaniesUI() {
        const blockedCompanies = getBlockedCompanies();

        // Create a table to display blocked companies
        const table = document.createElement('table');
        table.style.borderCollapse = 'collapse';
        table.style.marginTop = '20px';

        // Add header row
        const headerRow = table.insertRow();
        const nameHeader = headerRow.insertCell();
        nameHeader.textContent = 'Company Name';
        const actionHeader = headerRow.insertCell();
        actionHeader.textContent = 'Action';

        // Add rows for each blocked company
        blockedCompanies.forEach(companyName => {
            const row = table.insertRow();
            const nameCell = row.insertCell();
            nameCell.textContent = companyName;

            const actionCell = row.insertCell();
            const removeButton = document.createElement('button');
            removeButton.textContent = 'X';
            removeButton.style.color = 'red';
            removeButton.style.cursor = 'pointer';
            removeButton.addEventListener('click', () => {
                removeCompanyFromBlockList(companyName);
                row.remove(); // Remove row from table
            });
            actionCell.appendChild(removeButton);
        });

        // Create input field and button for adding new company to block list
        const inputContainer = document.createElement('div');
        inputContainer.style.marginTop = '10px';
        inputContainer.style.display = 'flex';
        inputContainer.style.alignItems = 'center';

        const addCompanyInput = document.createElement('input');
        addCompanyInput.placeholder = 'Enter company name';
        addCompanyInput.style.marginRight = '10px';

        const addButton = document.createElement('button');
        addButton.textContent = 'Add to Block List';
        addButton.style.cursor = 'pointer';
        addButton.style.backgroundColor = '#007bff'; // Blue background color
        addButton.style.color = 'white'; // White text color
        addButton.style.border = 'none'; // No border
        addButton.style.borderRadius = '4px'; // Rounded corners
        addButton.style.padding = '8px 16px'; // Padding
        addButton.addEventListener('click', () => {
            const newCompanyName = addCompanyInput.value.trim();
            if (newCompanyName !== '') {
                addCompanyToBlockList(newCompanyName);
                addCompanyInput.value = ''; // Clear input field
                // Refresh the displayed list of blocked companies
                displayBlockedCompaniesUI();
            }
        });

        inputContainer.appendChild(addCompanyInput);
        inputContainer.appendChild(addButton);

        // Display the table and input field/button in a modal
        const modalContent = document.createElement('div');
        modalContent.style.position = 'fixed';
        modalContent.style.top = '50px';
        modalContent.style.left = '50px';
        modalContent.style.padding = '20px';
        modalContent.style.backgroundColor = 'white';
        modalContent.style.border = '1px solid black';
        modalContent.style.zIndex = '9999';
        modalContent.appendChild(table);
        modalContent.appendChild(inputContainer);

        // Add close button
        const closeButton = document.createElement('button');
        closeButton.textContent = 'Close';
        closeButton.style.marginTop = '10px';
        closeButton.style.cursor = 'pointer';
        closeButton.style.backgroundColor = '#dc3545';
        closeButton.style.color = 'white';
        closeButton.style.border = 'none';
        closeButton.style.borderRadius = '4px';
        closeButton.style.padding = '8px 16px';
        closeButton.addEventListener('click', () => {
            modalContent.remove();
        });
        modalContent.appendChild(closeButton);

        document.body.appendChild(modalContent);
    }

    function isPageFullyLoaded() {
        return document.readyState === 'complete';
    }

    function initInterval() {
        if (isPageFullyLoaded()) {
            handleJobPostings();
        } else {
            setTimeout(initInterval, 1000);
            return;
        }

        setInterval(handleJobPostings, 5000);
    }

    initInterval();

    const showBlockedCompaniesButton = document.createElement('button');
    showBlockedCompaniesButton.textContent = 'View Blocked Companies';
    showBlockedCompaniesButton.style.position = 'fixed';
    showBlockedCompaniesButton.style.top = '20px';
    showBlockedCompaniesButton.style.right = '20px';
    showBlockedCompaniesButton.style.zIndex = '9999';
    showBlockedCompaniesButton.addEventListener('click', displayBlockedCompaniesUI);
    document.body.appendChild(showBlockedCompaniesButton);

})();