Greasy Fork

Greasy Fork is available in English.

resume_check

Boss|more...

目前为 2021-02-19 提交的版本。查看 最新版本

// ==UserScript==
// @name         resume_check
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Boss|more...
// @author       Lonely
// @match        https://www.zhipin.com/web/boss/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js
// @require      https://cdn.jsdelivr.net/npm/vue
// @require      https://unpkg.com/element-ui/lib/index.js
// @grant        GM_xmlhttpRequest
// ==/UserScript==


(function () {
    'use strict';
    //jq方式导入 element-ui.css
    $("head").append($(`<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">`));

    (function () {
        // 做一个div套着,后续直接innerHTML一把嗦
        var div = document.createElement('div')
        div.id = 'script_ele_box'
        div.style.height = '150px'
        div.style.width = '350px'
        // div.style.background = '#5df3a5'
        div.style.background = '#9eea6a'
        div.style.opacity = '0.8'
        div.style.borderRadius = '10px'
        div.style.position = 'absolute'
        div.style.zIndex = '999'
        div.innerHTML = `
                        <div id="resume_app" v-show='is_show()'>
                            <i class="el-icon-refresh-right" @click="match" style="font-size: 30px"></i>
                            <h3 style="text-align: right;float: right; pointer-events: none">{{ update_area }}s</h3>
                            <h2 style="position: absolute;top: 40px; pointer-events: none"> {{ message }}</h2>
                            <a class="preview" href='#' target='_blank' style="font-size: 30px"></a>
                            <el-table
                                    border
                                    ref="singleTable"
                                    :data="tableData"
                                    tooltip-effect="dark"
                                    :header-cell-style="{background:'#BCE784',color:'#606266'}"
                                    :row-style="{background:'#BCE784',color:'red'}"
                                    style="width: 100%;position: absolute;top: 150px; pointer-events: auto;border-radius: 10px">
                                <el-table-column
                                        type="index"
                                        width="40"
                                        align="center">
                                </el-table-column>
                                <el-table-column
                                        property="type"
                                        label="类别"
                                        width="50"
                                        align="center">
                                </el-table-column>
                        
                                <el-table-column
                                        :show-overflow-tooltip="true"
                                        property="exp"
                                        label="经验"
                                        width="210"
                                        align="center">
                                </el-table-column>
                                
                                <el-table-column
                                        property="checked"
                                        label="存在"
                                        width="50"
                                        align="center">
                                </el-table-column>
                            </el-table>
                        </div>
                        `
        document.body.appendChild(div);
        window.script_ele_box = div; // 把这个div赋值给window对象, 方便后续程序改变其可见性

    })()

    // 拖动
    class Drag {
        constructor() {
            this.ele = document.querySelector("#script_ele_box");
            this.m = this.move.bind(this);
            this.u = this.up.bind(this);

            this.init();
            this.addEvent();
        }

        init() {
            this.pos = localStorage.getItem("pos") ? JSON.parse(localStorage.getItem("pos")) : {
                l: 200,
                t: 100
            };
            this.ele.style.left = this.pos.l + "px";
            this.ele.style.top = this.pos.t + "px"
        }

        addEvent() {
            this.ele.addEventListener('mousedown', this.down.bind(this));
        }

        down(eve) {
            var e = eve || window.event;
            this.x = e.offsetX;
            this.y = e.offsetY;

            document.addEventListener('mousemove', this.m);
            document.addEventListener('mouseup', this.u);

        }

        move(eve) {
            // console.log(this)
            var e = eve;
            //移动时的鼠标坐标
            this.ele.style.left = e.clientX - this.x + "px";
            this.ele.style.top = e.clientY - this.y + "px";
        }

        up() {
            var pos = {
                l: this.ele.offsetLeft,
                t: this.ele.offsetTop
            }
            localStorage.setItem("pos", JSON.stringify(pos))
            //删除移动和抬起事件
            document.removeEventListener('mousemove', this.m)
            document.removeEventListener('mouseup', this.u)
        }
    }

    new Drag();

    var app = new Vue({
        el: '#resume_app',
        data: {
            message: '点击刷新',
            more_text: 'more',
            update_area: 0,
            intervalId: null,
            resume_detail: {
                // url和css选择器的一个键值对, 下面的extract_experience 根据此键值对获取其简历区域的html代码发给后端匹配
                'https://www.zhipin.com/web/boss/index': '.resume-detail'
            },
            tableData: []
        },
        methods: {
            show_more: function () {
                if (this.more_text === 'hide') {
                    window.script_ele_box.style.height = "150px"
                    this.more_text = 'more'
                } else {
                    window.script_ele_box.style.height = "300px"

                    this.more_text = 'hide'
                }

            },
            is_show: function () {
                // 如果当前链接在可显示的数组中, 则返回true, 即显示插件内容
                var flag = document.location.href in this.resume_detail
                if (flag) {
                    window.script_ele_box.style.visibility = "visible"
                } else {
                    window.script_ele_box.style.visibility = "hidden"
                }
                return flag
            },
            extract_experience: function () {
                // 提取经历部分的HTML代码
                if (document.querySelector(this.resume_detail[document.location.href])) {
                    return document.querySelector('.resume-detail').outerHTML
                }
                return null
            },
            match: function () {
                var experience_html = this.extract_experience()
                if (!experience_html) {
                    alert('请在简历页面点击匹配')
                    return
                }
                var self = this
                GM_xmlhttpRequest({
                    method: "POST",
                    url: "http://192.168.1.224:8888/api/v1/resume/parse_html_exp",
                    data: 'data=' + encodeURIComponent(experience_html),
                    headers: {
                        'accept': 'application/json',
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    onload: function (e) {
                        var python_response = JSON.parse(e.response)
                        var _a = document.querySelector('a.preview')
                        self.update_area = 0
                        self.tableData = python_response.data.detail
                        self.message = `${python_response.data.name}:${python_response.data.score}分`
                        if (python_response.data.score > 0) {
                            _a.href = python_response.data.file_path
                            _a.text = '预览'
                        }


                    }
                })
            },

            // 定时器
            dateRefresh: function () {
                if (this.intervalId != null) return

                this.intervalId = setInterval(() => {
                    this.update_area += 1
                }, 1000);
            },
            // 停止定时器
            clear: function () {
                clearInterval(this.intervalId); //清除计时器
                this.intervalId = null; //设置为null
            }
        },
        created: function () {
            this.dateRefresh();
        },
        destroyed() {
            // 在页面销毁后,清除计时器
            this.clear();
        }
    })

})();