-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBossHelper.js
683 lines (607 loc) · 22 KB
/
BossHelper.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
// ==UserScript==
// @name Boss直聘小助手
// @namespace http://tampermonkey.net/
// @version 1.0
// @description first script
// @author lvhao
// @match https://www.zhipin.com/web/boss/recommend
// @grant none
// @icon https://www.zhipin.com/favicon.ico
// @run-at document-idle
// ==/UserScript==
(function () {
'use strict';
/**
* BOSS直聘小助手
*/
class BossHelper {
constructor() {
// ON, OFF
this.workingState = "OFF";
// ON状态下,没有简历可以操作了
this.workDone = false;
// 菜单bar
this.menuBar = new BossHelperBar({
parentDocument: "#header div.top-nav",
plugin: this
});
}
start() {
this.workingState = "ON";
this.workDone = false;
}
stop() {
this.workingState = "OFF";
this.workDone = false;
}
isRunning() {
return this.workingState === "ON";
}
isWorkDone() {
return this.workDone;
}
tryFinishWork(curretnfindingResumeCount) {
let menuState = this.menuBar.countingBar;
// 跟上次一样,说明没有数据了
if (Number(menuState.findingResumeCount) == Number(curretnfindingResumeCount)) {
this.workDone = true;
}
return this.workDone;
}
}
/**
*
*/
class BossHelperBar {
static DEFAULT_PARENT_DOC = "#header div.top-nav";
static DEFAULT_COUNTING_BAR = {
// 打招呼数量
sayHiCount: 0,
// 查看详情数量
screeningResumeCount: 0,
// 获取简历数量
findingResumeCount: 0
};
constructor(settings) {
this.parentDocument = settings.parentDocument || BossHelperBar.DEFAULT_PARENT_DOC;
this.plugin = settings.plugin;
this.countingBar = settings.countingBar || Object.assign({}, BossHelperBar.DEFAULT_COUNTING_BAR);
this.render();
this.registerEvent();
}
registerEvent() {
var plugin = this.plugin;
// 小助手开关
$("#switch-config").click(function () {
if ($(this).hasClass("ui-switch-checked")) {
$(this).removeClass("ui-switch-checked");
$(this).find("input").val(false);
plugin.stop();
} else {
$(this).addClass("ui-switch-checked");
$(this).find("input").val(true);
plugin.start();
}
});
}
render() {
// 小助手界面入口
let helperView = `
<div id="helper-bar" class="nav-item">
<div class="label-name records-center">
<span style="font-size: medium;vertical-align: middle;">🤖 SayHi</span>
<span id="switch-config" class="ui-switch">
<input type="hidden" value="true">
<span class="ui-switch-inner"></span>
</span>
<span id="counting-bar" style="border-radius: 5px;text-align: center;color: #fff;background-color: #fe574a; padding-left: 5px;padding-right: 5px;font-size: medium;vertical-align: middle;">? / ? / ?</span>
</div>
</div>`;
$(this.parentDocument).append(helperView);
}
refreshSayHiCount() {
this.countingBar.sayHiCount += 1;
this.refreshCountingBar();
}
refreshScreeningResumeCount() {
this.countingBar.screeningResumeCount += 1;
this.refreshCountingBar();
}
refreshFindingResumeCount(qty) {
this.countingBar.findingResumeCount = qty;
this.refreshCountingBar();
}
refreshCountingBar() {
let {
sayHiCount,
screeningResumeCount,
findingResumeCount
} = this.countingBar;
let showText = `${sayHiCount} / ${screeningResumeCount} / ${findingResumeCount}`;
$("#counting-bar").text(showText);
}
reset() {
this.countingBar = Object.assign({}, BossHelperBar.DEFAULT_COUNTING_BAR);
this.refreshCountingBar();
}
}
/**
* 任务调度器
*/
class TaskTimer {
constructor(name) {
this.name = name;
this.elapsedTime = 0;
this.eventQueue = [];
}
recordTask(eId) {
this.eventQueue.push(eId);
}
reset() {
this.elapsedTime = 0;
this.eventQueue.forEach((eId) => {
clearTimeout(eId);
});
this.eventQueue = [];
}
timeConsuming(mills) {
this.elapsedTime += Number(mills);
return this.elapsedTime;
}
delayInvoke(funcCaller, delayMills) {
let timeId = setTimeout(() => {
funcCaller();
}, this.timeConsuming(delayMills));
this.recordTask(timeId);
}
//生成从minNum到maxNum的随机数
waitSecondBetween(minSecond, maxSecond) {
return parseInt(Math.random() * (maxSecond - minSecond + 1) + minSecond, 10) * 1000;
}
}
/**
* 简历判定看板
*/
class ResumeJudgementBoard {
constructor(settings) {
this.rootDocument = settings.rootDocument;
this.render();
}
render() {
//信息判定框
let msgStyle = `
width: 400px; height: 450px; color: #ffffff; background-color: #3a475ce8;
border-radius:4px; position: fixed; padding: 25px; top: 10%; margin: 0 auto;
z-index: 999999; left: 35%; display: none;
font-size: 20px; opacity: 0.7;
`;
let msgArea = `<div id="judgement-board" align="center" style="${msgStyle}">
<div id="candicateName" align="center">简历评估</div>
<ul style="margin-top: 30px;text-align: left;font-size:15px;">
</ul>
<div id="scorePanel" style="margin-top: 50px;text-align:center;font-size:20px;"></div>
</div>`;
$(this.rootDocument).contents().find("div[default]").append(msgArea);
}
generateFilterHtmlResult(dataObj) {
let dataStr = Array.isArray(dataObj.data) ? dataObj.data.join(",") : dataObj.data;
let content = `
<li data-score="${dataObj.score}">
<span class="date">${dataObj.title}</span>
<span class="exp-content">${dataStr}</span>
<span class="exp-content">[ ${dataObj.resultHtml} ] - ${dataObj.remark}</span>
</li>
`;
return content;
}
show(filterResultData) {
let $docDefaultDiv = $(this.rootDocument).contents().find("div[default]");
let candicateName = $docDefaultDiv.find("#resume-page div.geek-name").text()
let $evaluateEle = $docDefaultDiv.find("#judgement-board");
// 展示看板
$evaluateEle.find("#candicateName").text(candicateName);
$evaluateEle.show();
// 展示过滤器判定信息
var self = this;
let htmlContent = filterResultData.map(function (frd) {
return self.generateFilterHtmlResult(frd);
}).join("");
$docDefaultDiv.find("#judgement-board ul").append(htmlContent);
// 应用判定算法
let finalScore = filterResultData.map(function (frd) {
return frd.score;
})
.reduce(function (prev, curr) {
return prev + curr;
});
$evaluateEle.data("sayHi", finalScore > 0);
let evaluateText = finalScore > 0 ? `YES(${finalScore}分)` : `NO(${finalScore}分)`
$evaluateEle.find("#scorePanel").text(evaluateText);
}
close() {
let $docDefaultDiv = $(this.rootDocument).contents().find("div[default]");
$docDefaultDiv.find("#judgement-board ul").empty();
$docDefaultDiv.find("#judgement-board").hide();
}
}
/**
* 过滤器
*/
class ResumeFilter {
constructor(id, filterConfig) {
this.id = id;
this.data = filterConfig.data;
this.matchScore = filterConfig.matchScore;
this.nonMatchScore = filterConfig.nonMatchScore;
}
doFilter(inputValue) { }
}
/**
* 企业黑名单过滤器
*/
class CompanyBlacklistFilter extends ResumeFilter {
constructor(filterConfig) {
super("companyBlacklist", filterConfig);
}
doFilter(cv) {
let self = this;
let matchedData = cv.filter(function (cve) {
return self.data.filter(function (de) {
return cve.indexOf(de) > -1;
}).length > 0;
});
return {
"title": "工作:",
"data": matchedData.length ? matchedData : cv,
"result": !matchedData.length,
"resultHtml": matchedData.length ? "❌" : "✅",
"remark": "企业黑名单",
"score": matchedData.length ? this.matchScore : this.nonMatchScore
};
}
}
/**
* 企业白名单过滤器
*/
class CompanyWhitelistFilter extends ResumeFilter {
constructor(filterConfig) {
super("companyWhitelist", filterConfig);
}
doFilter(cv) {
let self = this;
let matchedData = cv.filter(function (cve) {
return self.data.filter(function (de) {
return cve.indexOf(de) > -1;
}).length > 0;
});
return {
"title": "工作:",
"data": matchedData.length ? matchedData : cv,
"result": matchedData.length,
"resultHtml": matchedData.length ? "✅" : "❌",
"remark": "企业白名单",
"score": matchedData.length ? this.matchScore : this.nonMatchScore
};
}
}
/**
* 年龄过滤器
*/
class AgeLessthenFilter extends ResumeFilter {
constructor(filterConfig) {
super("ageLessthen", filterConfig);
}
doFilter(cv) {
let r = cv <= this.data;
return {
"title": "年龄:",
"data": cv,
"result": r,
"resultHtml": r ? "✅" : "❌",
"remark": `年龄小于${this.data}岁`,
"score": r ? this.matchScore : this.nonMatchScore
};
}
}
/**
* 大学白名单过滤器
*/
class UniversityWhitelistFilter extends ResumeFilter {
constructor(filterConfig) {
super("universityWhitelist", filterConfig);
}
doFilter(cv) {
var self = this;
let matchedData = cv.filter(function (cve) {
return $.inArray(cve, self.data) > -1;
});
return {
"title": "学校:",
"data": matchedData.length ? matchedData : cv,
"result": matchedData.length,
"resultHtml": matchedData.length ? "✅" : "❌",
"remark": "名校",
"score": matchedData.length ? self.matchScore : self.nonMatchScore
};
}
}
/**
* 关键字过滤器
*/
class MatchKeywordFilter extends ResumeFilter {
constructor(filterConfig) {
super("matchKeyword", filterConfig);
}
doFilter(cv) {
let matchedData = this.data.filter(function (d) {
return cv.indexOf(d) > -1;
});
return {
"title": "关键字:",
"data": matchedData,
"result": matchedData.length,
"resultHtml": matchedData.length ? "✅" : "❌",
"remark": `关键字匹配`,
"score": matchedData.length ? this.matchScore : this.nonMatchScore
};
}
}
class ResumeFilterChain {
constructor(filters) {
let filterInstances = filters.map(function (f) {
return Reflect.construct(f.filter, [f.filterConfig]);
});
this.filterInstances = filterInstances;
}
doFilter(resumeData) {
let usedFilters = this.filterInstances;
return $.map(usedFilters, function (f) {
let cv = resumeData[f.id];
return f.doFilter(cv);
});
}
}
/**
* 简历搜索插件
*/
class ScreeningResumePlugin extends BossHelper {
constructor(filters) {
super();
this.timer = new TaskTimer("简历筛选助手");
this.rootDocument = "iframe[name=recommendFrame]";
this.resumeFilterChain = new ResumeFilterChain(filters);
this.resumeJudgementBoard = new ResumeJudgementBoard({
rootDocument: this.rootDocument
});
}
/**
* 点击下一页
* @param clickCount
*/
clickNextPage(clickCount) {
this.timer.delayInvoke(() => {
// 找到recommendFrame
if (window.frames[0].name === "recommendFrame") {
window.frames[0].scroll(0, 9999 * clickCount);
}
}, 1000);
}
clickSayHiBtn() {
let $recommendFrame = $(this.rootDocument).contents();
// $recommendFrame.find("#resume-page button.btn-greet")[0].click();
this.menuBar.refreshSayHiCount();
}
/**
* 获取请求页可以打招呼的候选人
* @param pageNo
* @param pageSize
* @returns
*/
findCanSayHiResumes(pageNo, pageSize) {
let menuBar = this.menuBar;
let $recommendFrame = $(this.rootDocument).contents();
// 获取候选人行
let sliceIdx = (pageNo - 1) * pageSize;
let resumes = $recommendFrame.find("#recommend-list").find("ul.recommend-card-list").children();
// 对比上次数据,尝试结束工作
if(this.tryFinishWork(resumes.length)){
return [];
}
// 刷新查到的简历量
menuBar.refreshFindingResumeCount(resumes.length);
// 返回可以打招呼的行,不重复打招呼
return resumes.slice(sliceIdx).filter(function () {
return $("button.btn-greet", this).length === 1;
});
}
needToSayHi() {
let $evaluateEle = $(this.rootDocument).contents().find("#judgement-board");
return $evaluateEle.data("sayHi");
}
getResumeData() {
let $docDefaultDiv = $(this.rootDocument).contents().find("div[default]");
let companyList = (function () {
return $docDefaultDiv.find(".resume-summary ul.jobs")
.not(".project,.education").find("h3 span")
.map(function () {
return $(this).text();
}).get();
}());
return {
companyBlacklist: companyList,
companyWhitelist: companyList,
ageLessthen: (function () {
return $docDefaultDiv.find("#resume-page i.fz-age").next().text().replace('岁', '');
}()),
universityWhitelist: (function () {
let r = [];
let schoolTags = $docDefaultDiv.find("#resume-page p.school-tags span").map(function () {
return $(this).text();
}).get();
let schools = $docDefaultDiv.find(".resume-summary ul.jobs.education").find("h3 span").map(function () {
return $(this).text();
}).get();
return r.concat(schoolTags, schools);
}()),
matchKeyword: (function () {
return $docDefaultDiv.find(".resume-item-content").text();
}())
};
}
/**
* 点击简历卡片
* @param canSayHicandidates
*/
clickResumeCard(canSayHiResumes) {
let $recommendFrame = $(this.rootDocument).contents();
// 延迟等待页面响应,至少10秒
// 第一秒点击详情
// 倒数第5秒展示评估信息
// 浏览X秒后,关闭弹窗
let self = this;
let menuBar = self.menuBar;
let filterChain = this.resumeFilterChain;
let board = this.resumeJudgementBoard;
let timer = this.timer;
let pluginIsRunning = this.isRunning();
$.each(canSayHiResumes, function (idx, ele) {
// 点击候选人详情
timer.delayInvoke(() => {
if (!pluginIsRunning) return;
$(ele).find("div.card-inner")[0].click();
menuBar.refreshScreeningResumeCount();
}, 1000);
// 获取信息等待评估
timer.delayInvoke(() => {
if (!pluginIsRunning) return;
// 获取候选人信息
let resumeData = self.getResumeData();
// 过滤规则结果
let filterResultData = filterChain.doFilter(resumeData);
// 看板展示
board.show(filterResultData);
}, 1600);
// 延迟点击关闭
timer.delayInvoke(() => {
if (!pluginIsRunning) return;
// 点击沟通
if (self.needToSayHi()) {
self.clickSayHiBtn();
}
// 关闭遮罩层
board.close();
// 关闭候选人信息页
let $closeBtn = $recommendFrame.find(".resume-dialog span.resume-custom-close")[0];
if ($closeBtn) $closeBtn.click();
}, timer.waitSecondBetween(8, 20));
});
}
/**
* 筛选简历
* @param pageNo
* @param pageSize
*/
screeningResumes(pageNo, pageSize) {
// 新轮回,时间线回归到0
this.timer.reset();
var pluginIsRunning = this.isRunning();
var pluginIsWorkDone = this.isWorkDone();
// 插件关闭或者全部完成,跳出循环
if (!pluginIsRunning) return;
if (pluginIsWorkDone) {
let {
sayHiCount,
screeningResumeCount,
findingResumeCount
} = this.menuBar.countingBar;
let showText = `
已完成全部简历筛选了 🎉
打招呼数量:${sayHiCount}
查看简历数量:${screeningResumeCount}
检索简历数量:${findingResumeCount}`;
alert(showText);
return;
}
// 获取当前页可以打招呼的候选人列表
let canSayHiCandicates = this.findCanSayHiResumes(pageNo, pageSize);
// 逐个打开候选人详情页
this.clickResumeCard(canSayHiCandicates);
// 点击下一页
pageNo++;
this.clickNextPage(pageNo);
// 等待数据加载完,开启下一轮
this.timer.delayInvoke(() => {
this.screeningResumes(pageNo, pageSize);
}, 3000);
}
reday() {
this.menuBar.reset();
this.resumeJudgementBoard.close();
this.timer.reset();
}
start() {
super.start();
this.screeningResumes(1, 15);
}
stop() {
super.stop();
this.reday();
}
}
// 后端过滤规则配置
const backendFilterCfg = [{
filter: CompanyWhitelistFilter,
filterConfig: {
data: ["阿里", "腾讯", "美团", "京东", "乐信", "OPPO","VIVO", "华为", "字节","头条","货拉拉", "顺丰"],
matchScore: 100,
nonMatchScore: 0
}
},
{
filter: CompanyBlacklistFilter,
filterConfig: {
data: ["文思海辉", "中软", "佰钧成", "软通动力", "博彦", "信必优", "神州数码", "浙大网新", "东软"],
matchScore: -50,
nonMatchScore: 0
}
},
{
filter: AgeLessthenFilter,
filterConfig: {
data: 30,
matchScore: 0,
nonMatchScore: -50
}
},
{
filter: UniversityWhitelistFilter,
filterConfig: {
data: ["985院校", "211院校", "QS世界大学排名TOP500", "双一流院校"],
matchScore: 50,
nonMatchScore: 0
}
},
{
filter: MatchKeywordFilter,
filterConfig: {
data: ["高并发", "博客", "读书", "源码", "开源", "github"],
matchScore: 10,
nonMatchScore: 0
}
}
];
/**
* 启用插件
*/
let bossHelper = {};
bossHelper.plugin = {
run: function () {
setTimeout(() => {
let screeningResumePlugin = new ScreeningResumePlugin(backendFilterCfg);
screeningResumePlugin.reday();
}, 4000)
}
}
// 运行插件
bossHelper.plugin.run();
})();