Show resumeCollectionNum at PipeChina campus recruitment site

Add another column `resumeCollectionNum`, make a POST request for each matching element and fill the new column

目前為 2024-10-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Show resumeCollectionNum at PipeChina campus recruitment site
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Add another column `resumeCollectionNum`, make a POST request for each matching element and fill the new column
// @author       aspen138
// @match        *://wecruit.hotjob.cn/SU617b87702f9d247cb97cc6b7/*
// @grant        none
// @license      MIT
// ==/UserScript==


// test case: https://wecruit.hotjob.cn/SU617b87702f9d247cb97cc6b7/pb/school.html
// 理论上也能适用于使用了用友大易hotjob.cn服务的其他网站
// 建议和中国融通的招聘网站学一下,不要弄什么二级页面显示投递人数 https://job.crtc-hr.com/portal/#/recruitmentc/campus/ebab6691-2fe1-4e72-b0fa-27e63fbcef3e




(function() {
    'use strict';

    // Function to extract postId and make a POST request
    function makePostRequest(element) {
        const postId = element.id;
        if (!postId) {
            console.error('Post ID is missing!');
            return;
        }
        const url = `https://wecruit.hotjob.cn/wecruit/positionInfo/listPositionDetail/SU617b87702f9d247cb97cc6b7?iSaJAx=isAjax&request_locale=zh_CN&t=${Date.now()}`;
        const referer = `https://wecruit.hotjob.cn/SU617b87702f9d247cb97cc6b7/pb/posDetail.html?postId=${postId}&postType=campus`;

        const bodyData = `postId=${postId}`;

        fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Referer': referer,
                'Accept': 'application/json, text/plain, */*',
                'Origin': 'https://wecruit.hotjob.cn',
                'Accept-Encoding': 'gzip, deflate, br, zstd',
                'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0'
            },
            body: bodyData
        })
        .then(response => response.json())
        .then(data => {
            console.log(`Response for postId ${postId}:`, data);
            if (data && data.data && data.data.resumeCollectionNum !== undefined) {
                const resumeCollectionNum = data.data.resumeCollectionNum;
                let newColumn = element.querySelector('.resume-collection');
                if (!newColumn) {
                    newColumn = document.createElement('div');
                    newColumn.className = 'list-cell resume-collection';
                    newColumn.style.width = '10%';
                    newColumn.style.flex = 'initial';
                    element.querySelector('.list-row-item').appendChild(newColumn);
                }
                newColumn.textContent = `${resumeCollectionNum}`;
            }
        })
        .catch(error => {
            console.error(`Error for postId ${postId}:`, error);
        });
    }

    // Add a new header column for Resume Collection Number
    function addResumeCollectionHeader() {
        const headerRow = document.querySelector('.list-hd.list-row-item');
        if (headerRow && !headerRow.querySelector('.resume-collection-header')) {
            const newHeader = document.createElement('div');
            newHeader.className = 'list-cell resume-collection-header';
            newHeader.style.width = '10%';
            newHeader.style.flex = 'initial';
            newHeader.textContent = '投递';
            headerRow.appendChild(newHeader);
        }
    }

    // Function to process all current and future elements
    function processElements() {
        addResumeCollectionHeader();
        document.querySelectorAll('div.list-item-main').forEach(element => {
            const postId = element.getAttribute('id');
            if (postId) {
                makePostRequest(element);
            }
        });
    }

    // Start by processing existing elements
    setTimeout(() => {
        processElements();
    }, 1000);

    // Use MutationObserver to detect when new list items are added and process them
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === 1 && node.classList.contains('list-item-main')) {
                    const postId = node.getAttribute('id');
                    if (postId) {
                        makePostRequest(node);
                    }
                }
            });
        });
    });

    // Observe changes in the document's body or a specific container
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址