// ==UserScript== // @name Boss直聘职位排序 // @namespace http://tampermonkey.net/ // @version 0.1 // @description A Tampermonkey script using jQuery // @author You // @match https://www.zhipin.com/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function () { 'use strict'; try { const realXHR = window.XMLHttpRequest; window.XMLHttpRequest = function () { const xhr = new realXHR(); const oldOpen = xhr.open; xhr.open = function (method, url, async, user, password) { this.addEventListener('readystatechange', function () { // if (this.readyState === 1) { // console.log('XHR in progress with readyState ', this.readyState); // } }, false); oldOpen.apply(this, arguments); }; xhr.addEventListener('load', function () { if (this.status === 200 && (this.responseURL.includes('/list.json?') || this.responseURL.includes('/joblist.json?'))) { console.log('XHR finished with status ', xhr.responseText); createScript('https://code.jquery.com/ui/1.12.1/jquery-ui.min.js').then(res => { createStyleLink() createRootDom() createTable(JSON.parse(xhr.responseText).zpData.jobList) }) } }, false); return xhr; }; function createScript(href) { return new Promise((resolve, reject) => { const script = document.createElement('script') script.src = href document.head.appendChild(script) script.onload = () => { resolve(true) } script.onerror = () => { reject(false) } }) } function createTable(data) { // 创建新的 DOM 元素 var newElement = $('
', { class: 'my-custom-element', }); // 创建一个表格 const list = data.sort((a, b) => { // 判断是否有最后修改时间 if (!a.lastModifyTime) { return 1 } return new Date(b.lastModifyTime) - new Date(a.lastModifyTime) }).map((_, index) => { return $('', { html: `${index}${_.brandName}${_.jobName}${_.salaryDesc}${_.jobExperience}${_.bossName}${_.bossTitle}${_.lastModifyTime ? new Date(_.lastModifyTime).toLocaleString('zh-CN', { hour12: false }) : _.lastModifyTime}` }) }) // 添加表头 const tablehead = ['序号', '公司', '职位', '薪资', '经验', '招聘人', '招聘人职位', '最后修改时间'] list.unshift(`${tablehead.map((_) => `${_}`).join('')}`) const table = $('', { html: list, class: 'ui-widget ui-widget-content' }) // 将表格添加到新元素中 newElement.append(table) // 将新元素添加到 body 中 $('.my-root-element').append(newElement); } function createRootDom() { const rootDom = $('
', { class: 'my-root-element', }) // 将新元素添加到 body 中 $('body').append(rootDom); // 设置可以拖动 $('.my-root-element').draggable() } function createStyleLink() { const link = document.createElement('link') link.rel = 'stylesheet' link.href = 'https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css' document.head.appendChild(link) } } catch (error) { console.error(error) } // 插入样式 const style = document.createElement('style') style.type = 'text/css' style.id = 'my-custom-style' const str = ` .my-root-element { position: fixed; top: 10px; left: 10px; z-index: 9999; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; height: 300px; overflow: hidden; } .my-custom-element { background-color: #f9f9f9; border: 1px solid #ccc; padding: 10px; margin: 10px 0; font-size: 16px; color: #333; height: 300px; overflow: auto; } .my-custom-element table { width: 100%; border-collapse: collapse; height: 100%; } .my-custom-element th, .my-custom-element td { border: 1px solid #ccc; padding: 5px; text-align: center; } ` style.innerHTML = str document.head.appendChild(style) })();