Greasy Fork

boss直聘职位描述远程兼职关键词高亮显示

有问题联系:qq183180915

当前为 2024-04-01 提交的版本,查看 最新版本

// ==UserScript==
// @name         boss直聘职位描述远程兼职关键词高亮显示
// @namespace    http://tampermonkey.net/
// @version      2024-04-01
// @description  有问题联系:qq183180915
// @author       余默
// @match        https://www.zhipin.com/*
// @icon         https://img.bosszhipin.com/beijin/mcs/banner/3e9d37e9effaa2b6daf43f3f03f7cb15cfcd208495d565ef66e7dff9f98764da.jpg
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    window.onload = function() {
        // 在这里编写需要在页面加载完毕后执行的 JavaScript 代码

        setInterval(() => {
            const desc = document.querySelector('p.desc');
            let txt = desc.innerHTML;
            // console.log(txt);
            // 获取文本内容
            // const textContent = document.getElementById('content').innerHTML;

            // 匹配包含“远程”的关键词
            // const keywords = txt.match(/远程/g);
            // const keywords2 = txt.match(/兼职/g);

            // const regex = /兼([\s\S]*?)职/g;
            // const matches = txt.match(regex);
            // 输出匹配到的内容
            // console.log(matches);
            txt = txt.replace(/兼([\s\S]*?)职/g, '兼职');
            txt = txt.replace(/远([\s\S]*?)程/g, '远程');
            txt = txt.replace(/线([\s\S]*?)上/g, '线上');

            // 高亮显示关键词
            const highlightedContent = txt.replace(/远程/g, '<span style="background-color:yellow;">远程</span>');
            const highlightedContent1 = highlightedContent.replace(/家/g, '<span style="background-color:yellow;">家</span>');
            const highlightedContent2 = highlightedContent1.replace(/兼职/g, '<span style="background-color:yellow;">兼职</span>');
            const highlightedContent3 = highlightedContent2.replace(/线上/g, '<span style="background-color:yellow;">线上</span>');

            // 更新文本内容
            desc.innerHTML = highlightedContent3;
        }, 1200);
    };
})();