// ==UserScript== // @name IgnoreSomeCompanies // @namespace https://github.com/hfc1994 // @version 1.0.1 // @description 根据需要添加关键字,然后可以把页面上相对应公司的招聘条目给忽略 // @author 枯木 // @license GPL // @icon https://avatars2.githubusercontent.com/u/32028349?s=40&v=4 // @match https://search.51job.com/list/* // @match https://sou.zhaopin.com/* // @grant none // @downloadURL none // ==/UserScript== /** * 根据指定的关键字,忽略求职网站上指定公司的招聘条目 * 如果发现bug,非常欢迎向我提出来https://github.com/hfc1994/IgnoreSomeCompanies */ let companies = [] let website = '' // 初始化,用来读取localStorage // 存储格式key:companies,value:['',''] function init() { judgeWebsite() appendGlobalStyle() appendFloatDiv() try { companies = JSON.parse(window.localStorage.getItem('companies')) if (companies === null || companies === undefined || companies.length === 0) { companies = [] console.warn('页面暂无需要过滤的数据') return } else { for (let i=0; i { // console.log('DOM changed') doIgnore() }) let number = setInterval(() => { let target = document.getElementById('listContent') if (null !== target) { doIgnore() // DOM布局第一次形成,先过滤一遍 observer.observe(target, {'childList': true}) clearInterval(number) // console.log('observer设置完毕,定时任务结束') } else { // console.log('dom还没有初始化完成,500毫秒后重试') } }, 500) } function doIgnore() { let compDivs = getDivListToIgnore() compDivs.forEach((item) => { if (alreadyBeIgnored(item)) { return } let cName = getRealCompanyName(item) if (isIgnoreCompany(cName)) { // console.log('匹配到:' + cName) addIgnoreClassTag(item) appendNewChildNode(item, cName) } }) } function getDivListToIgnore() { if (website === '51job') { return document.querySelectorAll('.dw_table .el') } else { return document.querySelectorAll('.contentpile__content__wrapper .clearfix') } } function getRealCompanyName(node) { if (website === '51job') { return node.getElementsByClassName('t2')[0].textContent.trim() } else { return node.getElementsByClassName('company_title')[0].textContent.trim() } } // 添加一些全局样式 function appendGlobalStyle() { // 需要被忽略的节点 buildStyle('.ISC_ignoreNode{height:30px !important;background-color:#dbecfe !important;}') // 需要被忽略的子节点 buildStyle('.ISC_ignoreChildNode{display:none !important;}') // toolbox节点里面的 if (website === '51job') { // 新添加的节点 buildStyle('.ISC_appendNode{font-size: 10px;text-align: center;margin-top: -5px;color: #bababa;}') buildStyle('#ISC_info {position: fixed;bottom: 126px;margin-left: 1042px;text-align: center;padding-top: 5px;height: 48px;width: 48px;}') buildStyle('#ISC_input {bottom: 182px;height: 30px;}') buildStyle('#ISC_content {bottom: 215px;min-height: 150px;}') buildStyle('#ISC_content,#ISC_input {position: fixed;margin-left: 890px;box-shadow: 1px 1px 3px 0px #a3a3a3;width: 200px;opacity: 0.75;z-index: 10;}') } else { // 新添加的节点 buildStyle('.ISC_appendNode{font-size: 10px;text-align: center;padding-top: 5px;color: #bababa;}') buildStyle('#ISC_info {position: fixed;bottom: 22px;margin-left: 800px;text-align: center;padding-top: 5px;height: 48px;width: 48px;}') buildStyle('#ISC_input {bottom: 73px;height: 30px;}') buildStyle('#ISC_content {bottom: 106px;min-height: 150px;}') buildStyle('#ISC_content,#ISC_input {position: fixed;margin-left: 800px;box-shadow: 1px 1px 3px 0px #a3a3a3;width: 200px;opacity: 0.75;z-index: 10;}') // 额外调整UI的 buildStyle('#filterInput {line-height: initial;background: #fff;width: 155px;height: 21px;border: 1px solid #aaa;}') buildStyle('#filterButton {border: 1px solid #aaa;background-color: #eee;width: 31px;height: 22px;font-size: 14px;margin-bottom: 6px;}') } buildStyle('#ISC_info:hover {border-radius: 10px;box-shadow: 2px 2px 5px 0px #a3a3a3;}') buildStyle('#ISC_info:active {transform: scale(0.8);-webkit-transform: scale(0.8);-moz-transform: scale(0.8);-ms-transform: scale(0.8);}') buildStyle('#ISC_content,#ISC_input,#ISC_info,.ISC_keyword {background-color: #ecf5ff;border: 1px solid #409eff;color: #409eff;}') buildStyle('.ISC_keyword {margin: 5px;padding: 1px 2px;display: inline-block;color: #000;cursor: pointer;box-shadow: 2px 2px 4px 0px #a3a3a3;}') buildStyle('.ISC_keyword:hover {transform: scale(1.1);-webkit-transform: scale(1.1);-moz-transform: scale(1.1);-ms-transform: scale(1.1);}') buildStyle('#ISC_info,.ISC_keyword {transition: all 0.3s;-webkit-transition: all 0.3s;-moz-transition: all 0.3s;-ms-transition: all 0.3s;}') buildStyle('#filterInput, #filterButton {margin: 3px 2px;}') buildStyle('#ISC_node_copy {opacity: 0.4;}') } // 根据给定内容构造样式 function buildStyle(content) { let newStyle = document.createElement('style') newStyle.type = 'text/css' newStyle.innerHTML = content document.head.appendChild(newStyle) } // 是否是需要被忽略的 function isIgnoreCompany(cName) { for (let i = 0; i < companies.length; i++) { let ignoreName = companies[i] if (cName === ignoreName || cName.indexOf(ignoreName) !== -1) { return true } } return false } // 是否已经被过滤过了,true为已经被过滤了 function alreadyBeIgnored(node) { for (let i=0; i { if (alreadyBeIgnored(node)) { let cName = getRealCompanyName(node) if (cName.indexOf(keyword) !== -1) { node.classList.remove('ISC_ignoreNode') for (let j=0; j