Greasy Fork

Greasy Fork is available in English.

Nowpick replace 999+ with actual data from the response

Capture a specific URL, replace 999+ with actual data from the response, and show job info in a toast with delay

当前为 2024-10-08 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Nowpick replace 999+ with actual data from the response
// @namespace    http://tampermonkey.net/
// @version      1.0.3
// @description  Capture a specific URL, replace 999+ with actual data from the response, and show job info in a toast with delay
// @author       aspen138
// @match        *://nowpick.nowcoder.com/w/hrconsole/job-manage*
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @require      https://update.greasyfork.icu/scripts/462234/1322684/Message.js
// @license      MIT
// ==/UserScript==



// key: "getDeliverNum",
// value: function(t) {
//     if (1 === t.showStatus)
//         return "- -";
//     var e = t.inviteSuccessCnt + t.initiativeDeliverCnt;
//     return e > 999 ? "999+" : e
// }





(function () {
    'use strict';

    // Function to execute the main functionality
    async function executeMainFunctionality() {
        if (window.location.href === "https://nowpick.nowcoder.com/w/hrconsole/job-manage") {
            window.QMSG_GLOBALS = {
                DEFAULTS: {
                    showClose: true,
                    autoClose: false,
                    timeout: 3600 * 1000 // ms
                }
            };

            const name = "JobUpdater";

            function toast(s, error = false) {
                if (error) {
                    Qmsg.error(`[${name}] ${s}`);
                    console.error(`[${name}] ${s}`);
                } else {
                    Qmsg.success(`[${name}] ${s}`);
                    console.log(`[${name}] ${s}`);
                }
            }

            // Function to show a toast message
            function showToast(message) {
                toast(" " + message, false); // Display
            }

            // Function to escape special characters in CSS selectors
            function escapeCSSSelector(selector) {
                return selector.replace(/([!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g, '\\$1');
            }

            // Function to replace the '999+' value with actual data
            async function replaceValues(jobName, unProcessCount) {
                const jobTitleElements = document.querySelectorAll('.job-title-name');
                const updateTasks = Array.from(jobTitleElements).map(async (el) => {
                    if (el.textContent.trim() === jobName) {
                        const jobInfoParent = el.closest('.job-info').parentElement.parentElement;
                        const unProcessElement = jobInfoParent.querySelector('.tw-font-semibold');
                        if (unProcessElement && unProcessElement.textContent.trim() === '999+') {
                            unProcessElement.textContent = unProcessCount;
                            showToast(`Updated job "${jobName}" with deliverNum: ${unProcessCount}`);
                        }
                    }
                });
                await Promise.all(updateTasks);
            }

            // Function to delay the update (parallelized for faster updates)
            async function delayUpdate(summaryDetailList) {
                await new Promise(resolve => setTimeout(resolve, 0.0001*1000)); // 1 second delay //why we need the delay here???

                const updateTasks = summaryDetailList.map(async (job) => {
                    const deliverNum = job.unProcessCount + job.successCount + job.failCount + job.unDetermined + job.writtenInterviewCount;
                    await replaceValues(job.jobName, deliverNum);
                });

                await Promise.all(updateTasks);
            }

            // Function to fetch data and initiate update (parallelized)
            async function fetchDataAndInitiateUpdate() {
                try {
                    const response = await fetch("https://nowpick.nowcoder.com/h/resume-deliver/summary");
                    if (response.ok) {
                        const jsonResponse = await response.json();
                        if (jsonResponse.data && jsonResponse.data.summaryDetailList) {
                            const summaryDetailList = jsonResponse.data.summaryDetailList;
                            await delayUpdate(summaryDetailList);
                        } else {
                            showToast("Unexpected response format");
                        }
                    } else {
                        showToast("Error: " + response.statusText);
                    }
                } catch (e) {
                    showToast("Request failed: " + e.message);
                }
            }

            // Execute only if we are on the specific URL
            await fetchDataAndInitiateUpdate();
        }
    }

    // Execute the main functionality on page load
    executeMainFunctionality();

    // Listen for hash change or pop state to detect URL changes
    window.addEventListener('hashchange', executeMainFunctionality);
    window.addEventListener('popstate', executeMainFunctionality);

    // Use a MutationObserver to detect URL changes if the page uses JavaScript-based navigation
    const observer = new MutationObserver(() => {
        executeMainFunctionality();
    });

    observer.observe(document, { childList: true, subtree: true });
})();