Last active
June 6, 2023 11:15
-
-
Save ngseke/0e0d52718e078d3eabfd1d88a2148699 to your computer and use it in GitHub Desktop.
CakeResume Company Blocker: CakeResume 黑名單公司封鎖小幫手,避免誤擊你的前東家或者雷公司
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name CakeResume Company Blocker | |
// @namespace https://ngseke.me/ | |
// @version 0.1 | |
// @description 避免誤擊你的前東家或者雷公司 | |
// @author ngseke | |
// @match *.cakeresume.com/jobs* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(() => { | |
/** | |
* ✨ 想匹配的公司關鍵詞列表,接受字串或正則表達式 | |
*/ | |
const keywords = [ | |
'Google', | |
'Amazon', | |
] | |
const patterns = keywords.map(pattern => new RegExp(pattern, 'i')) | |
/** 更新樣式,令匹配的項目淡化並不可選 */ | |
const updateStyles = (node) => { | |
node.style.opacity = .3 | |
node.style.pointerEvents = 'none' | |
node.style.cursor = 'not-allowed' | |
} | |
const handleNewNodes = (nodes) => { | |
const matches = [...nodes] | |
.filter(node => { | |
const jobTitle = node.querySelector('[class^=JobSearchItem_jobTitle]')?.innerText | |
const companyName = node.querySelector('[class^=JobSearchItem_companyName__]')?.innerText | |
const isMatched = patterns.some( | |
pattern => pattern.test(jobTitle) || pattern.test(companyName) | |
) | |
return isMatched | |
}) | |
matches.forEach(updateStyles) | |
} | |
/** 目標列表 */ | |
const container = document.querySelector('[class^=JobSearchHits_list__]') | |
// A. 處理初始列表 | |
handleNewNodes(container.querySelectorAll('[class^=JobSearchItem_wrapper__]')) | |
// B. 處理後續翻頁的新項目 | |
const observer = new MutationObserver((mutations) => { | |
handleNewNodes( | |
mutations.map(mutation => [...mutation.addedNodes]).flat() | |
) | |
}) | |
observer.observe(container, { childList: true }) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment