-
Notifications
You must be signed in to change notification settings - Fork 7
/
refined-boss.user.js
177 lines (154 loc) · 5.77 KB
/
refined-boss.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// ==UserScript==
// @name 重新定义Boss直聘
// @namespace http://tampermonkey.net/
// @version 0.0.3
// @description 显示岗位最后修改时间,屏蔽,已沟通过,不活跃岗位
// @author YuTengjing
// @supportURL https://github.com/tjx666/user-scripts/issues
// @homepage https://github.com/tjx666/user-scripts
// @match https://www.zhipin.com/web/geek/job*
// @icon https://www.google.com/s2/favicons?sz=64&domain=zhipin.com
// @grant none
// ==/UserScript==
(function () {
'use strict';
async function sleep(ms) {
return new Promise((resolve) => {
setTimeout(() => resolve(), ms);
});
}
async function waitElements(selector, delay = 50) {
let elements;
while (true) {
elements = document.querySelectorAll(selector);
if (elements.length !== 0) {
return elements;
}
await sleep(delay);
}
}
const day = 1000 * 60 * 60 * 24;
const week = day * 7;
const month = week * 4;
function humanizeDuration(ms) {
if (ms <= day) {
return '一天内';
} else if (ms <= day * 3) {
return '三天内';
} else if (ms <= week) {
return '本周内';
} else if (ms <= week * 2) {
return '两周内';
} else if (ms <= month) {
return '本月内';
} else if (ms <= month * 3) {
return '最近三个月';
} else {
return '超过三个月';
}
}
function getDurationColor(ms) {
if (ms <= week) return '#fe574a';
else if (ms <= month) return '#40b14f';
else return '#666';
}
function getFetchJobListBaseUrl() {
return window.performance
.getEntries()
.filter((item) => item.name.includes('/joblist.json?'))[0]?.name;
}
/**
* 翻页,搜索别的岗位都会请求 jobList
*/
const listenUpdateJobList = (function () {
const callbacks = [];
let fetchJobListBaseUrl;
async function publishUpdate() {
if (callbacks.length === 0) return;
// location url params -> fetchJobListParams
const keyMap = {
areaBusiness: 'multiBusinessDistrict',
};
const baseUrlObj = new URL(fetchJobListBaseUrl);
const fetchJobListParams = baseUrlObj.searchParams;
const locationParams = new URLSearchParams(location.search);
for (const [key, value] of locationParams.entries()) {
fetchJobListParams.set(keyMap[key] ?? key, value);
}
const fetchJobListUrl = baseUrlObj.toString();
const resp = await fetch(fetchJobListUrl);
const jobLists = (await resp.json()).zpData.jobList;
callbacks.forEach((cb) => cb(jobLists));
}
(async function pollBaseFetchJobListUrl() {
while (true) {
fetchJobListBaseUrl = getFetchJobListBaseUrl();
if (fetchJobListBaseUrl) {
publishUpdate();
// monitor location url change
let lastUrl = location.href;
(async function () {
while (true) {
const currentUrl = location.href;
if (currentUrl !== lastUrl) {
publishUpdate();
lastUrl = currentUrl;
}
await sleep(100);
}
})();
return;
}
await sleep(32);
}
})();
/**
* @param {(jobList: any[]) => void} callback
*/
return function (callback) {
callbacks.push(callback);
};
})();
async function main() {
listenUpdateJobList(async (jobList) => {
const now = Date.now();
const jobMap = jobList.reduce((map, cur) => {
map.set(cur.encryptJobId, cur);
return map;
}, new Map());
const jobCardLinks = await waitElements('a.job-card-left');
for (const link of jobCardLinks) {
const jobId = link.href.match(/job_detail\/(.*?)\.html/)?.[1];
const job = jobMap.get(jobId);
if (!job) continue;
// 屏蔽已沟通过的岗位
if (link.textContent.includes('继续沟通')) {
link.parentNode.parentNode.remove();
continue;
}
// 屏蔽不活跃岗位
const duration = now - job.lastModifyTime;
if (duration > month * 3) {
link.parentElement.parentElement.remove();
continue;
}
// 屏蔽外包岗位
const outsourcingKeywords = ['外包', '外派'];
if (outsourcingKeywords.some((keyword) => job.jobName.includes(keyword))) {
link.parentElement.parentElement.remove();
continue;
}
// 显示岗位最后修改时间
const jobTitle = link.querySelector('.job-title');
const modDateSpan = document.createElement('span');
modDateSpan.className = 'mod-date';
modDateSpan.innerHTML = ' ' + humanizeDuration(duration);
modDateSpan.style = `font-size: 13px; font-weight: normal; color: ${getDurationColor(
duration,
)};`;
jobTitle.append(modDateSpan);
}
});
}
main();
})();