Custom yz_tj

研招网调剂增强

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Custom yz_tj
// @namespace    https://github.com/invobzvr
// @version      0.3
// @description  研招网调剂增强
// @author       invobzvr
// @match        *://yz.chsi.com.cn/sytj/tj/qecx.html*
// @grant        unsafeWindow
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @require      https://greasyfork.org/scripts/443030-hook-js/code/Hookjs.js?version=1037826
// @homepageURL  https://github.com/invobzvr/invotoys.js/tree/main/yz_tj
// @supportURL   https://github.com/invobzvr/invotoys.js/issues
// @license      GPL-3.0
// ==/UserScript==

(function () {
    function inithook() {
        XMLHttpRequest.prototype.open.hook({
            scope: XMLHttpRequest.prototype,
            before: function () {
                if (arguments[1].endsWith('/sytj/stu/sytjqexxcx.action')) {
                    this.addEventListener('readystatechange', () => {
                        if (this.readyState !== 4) {
                            return;
                        }
                        let ret = JSON.parse(this.responseText);
                        ret.data.vo_list.vos = ret.data.vo_list.vos.filter(ii => !ii.sfmzjybyq && !ii.sfmzyq).sort((a, b) => a.gxsj - b.gxsj);
                        Object.defineProperty(this, 'responseText', { value: JSON.stringify(ret) });
                    });
                }
            }
        });

        unsafeWindow.template_zytb_add && unsafeWindow.template_zytb_add.hook({
            scope: unsafeWindow,
            before: function (id) {
                if (zy_status.cur_num < zy_status.max_num) {
                    open(`tbtjzy.html?zy_type=1&id=${id}`);
                    return null;
                }
            }
        });

        unsafeWindow.change_seach && unsafeWindow.change_seach.hook({
            scope: unsafeWindow,
            after: function () {
                let stype = arguments[1][1];
                GM_setValue('stype', stype);
                if (stype === 'accurate') {
                    return;
                }
                let dwxx = document.querySelector('[name=dwmc2]'),
                    tjBtn = document.querySelector('.tj-seach-btn'),
                    ddb = dwxx.insertAdjacentElement('afterend', document.createElement('div'));
                ddb.className = 'dropdown-box';
                dwxx.parentElement.style.position = 'relative';
                dwxx.addEventListener('keydown', evt => evt.keyCode === 13 && tjBtn.click());
                dwxx.addEventListener('click', evt => {
                    evt.stopPropagation();
                    if (keywords.length) {
                        ddb.classList.add('show');
                        ddb.innerHTML = keywords.map(ii => `<div class="dropdown-item">${ii}<div class="dropdown-delete"></div></div>`).join('');
                    }
                });
                addEventListener('click', evt => {
                    if (!ddb.classList.contains('show')) {
                        return;
                    }
                    switch (evt.target.className) {
                        case 'dropdown-item':
                            dwxx.value = evt.target.innerText;
                            ddb.classList.remove('show');
                            break;
                        case 'dropdown-delete':
                            let el = evt.target.parentElement;
                            GM_setValue('keywords', keywords = keywords.filter(ii => ii !== el.innerText));
                            el.remove();
                            !keywords.length && ddb.classList.remove('show');
                            break;
                        default:
                            ddb.classList.remove('show');
                            break;
                    }
                });
            }
        });

        unsafeWindow.qecx_post && unsafeWindow.qecx_post.hook({
            scope: unsafeWindow,
            before: function () {
                let kw = arguments[1].find(ii => ii.name === 'dwmc2').value;
                if (!keywords.includes(kw)) {
                    keywords.push(kw);
                    GM_setValue('keywords', keywords);
                }
            }
        });

        unsafeWindow.layer && layer.alert.hook({
            scope: layer,
            before: function () {
                let args = arguments[1];
                if (typeof args === 'object') {
                    args.shadeClose = true;
                }
            }
        });
    }

    inithook();
    let stype = GM_getValue('stype'),
        keywords = GM_getValue('keywords', ['aa', 'bb']);
    stype === 'fuzzy' && change_seach('', 'fuzzy', new MouseEvent('click'));
    unsafeWindow.page_size = 100;
    GM_addStyle(`.dropdown-box {
    background: #fff;
    border-radius: 2px;
    border: 1px solid!important;
    display: none;
    position: absolute;
    top: 51px;
    user-select: none;
    width: 252px;
}
.dropdown-box.show {
    display: block;
}
.dropdown-item {
    padding: 5px;
    position: relative;
}
.dropdown-item:hover {
    background: #0002;
}
.dropdown-delete:before,
.dropdown-delete:after {
    background: grey;
    border-radius: 25px;
    content: '';
    height: 2px;
    position: absolute;
    top: 11px;
    transform: rotate(45deg);
    transition: .2s;
    width: 15px;
}
.dropdown-delete {
    height: 15px;
    margin: 5px;
    position: absolute;
    right: 0;
    top: 0;
    width: 15px;
}
.dropdown-delete:after {
    transform: rotate(-45deg);
}
.dropdown-delete:hover:before,
.dropdown-delete:hover:after {
    background: #09f;
}`);
})();