Skip to content

Commit

Permalink
feat: 对提示展示信息进行优化,对名单进行拓展,对CI触发进行优化
Browse files Browse the repository at this point in the history
  • Loading branch information
bosens-China committed Nov 3, 2023
1 parent e44bfc7 commit 15099b3
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 117 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- master
paths:
- src/**

jobs:
build:
Expand Down
67 changes: 0 additions & 67 deletions JudgmentConditions.md

This file was deleted.

14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
![tips1](./tips1.png)
![tips2](./tips2.png)

> 如果你对它的判定规则好奇,你可以 [点击查看具体规则](./JudgmentConditions.md)
> 如果你有好的个规则补充,可以修改 [information.json](./src/information.json) 文件进行 PR,后续审核通过就会发版。
> 使用需要结合油猴插件使用
## 使用方式
Expand All @@ -24,6 +22,18 @@ pnpm run build
# 重复方法一
```

## 判定规则

采用黑名单 + 关键词的机制,如果公司名称出现在黑名单上则直接判定为黑名单,否则关键词出现一次,进行提示,出现两次则认定。

参考规则:

- https://www.zhihu.com/question/32123407
- https://zhuanlan.zhihu.com/p/407777028
- https://www.zvsts.com/article/news/1/4e347ffffe83fd932bcbbf4efafb0000.html

> 如果你有好的个规则补充,可以修改 [information.json](./src/information.json) 文件进行 PR,后续审核通过就会发版。
## 协议

MIT License
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "boss-outsourcing-tips",
"version": "1.0.1",
"version": "1.0.2",
"description": "boss招聘对外包公司显式提醒",
"main": "dist/index.js",
"scripts": {
Expand Down
77 changes: 60 additions & 17 deletions src/KeyWords.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,72 @@
import { _ReturnType } from "./chain";
import information from "./information.json";

const traverse = (dom: Element, fn: (el: ChildNode) => void): void => {
const arr = Array.from(dom.childNodes);
arr.forEach((item) => {
if (item.nodeType === Node.ELEMENT_NODE) {
traverse(item as Element, fn);
return;
}
fn(item);
});
};

export const keyWords = (): _ReturnType => {
const selectors = [
".job-banner",
".job-detail-section",
".job-detail-company",
".info-primary h1",
".job-detail-section .job-sec-text",
".job-detail-company .job-sec-text",
];
const content = selectors.reduce((text, selector) => {
const dom = document.body.querySelector(selector);
return text + (dom?.textContent ?? "");
}, "");
// 如果出现一个则提示存在高危风险,两个则直接提示为外包公司谨慎选择
let text = "该岗位描述符合外包定义,具体如下:\n";
const frequency = information.KeyWords.reduce((count, KeyWord) => {
if (content.includes(KeyWord)) {
text += `${count + 1}. ${KeyWord}\n`;
return count + 1;
const store: Set<string> = new Set();

const effect = (el: ChildNode) => {
if (el.nodeType !== Node.TEXT_NODE) {
return;
}
let content = el.textContent || "";

// 可能存在多个关键词都在一串文本出现
information.KeyWords.forEach((KeyWord) => {
if (content.includes(KeyWord)) {
store.add(KeyWord);
content = content.replace(
new RegExp(KeyWord, "g"),
`<span style="color:red">${KeyWord}</span>`
);
}
});
if (content === el.textContent) {
return;
}
const fragment = document.createDocumentFragment();
const span = document.createElement("span");
span.innerHTML = content;
while (span.firstChild) {
fragment.appendChild(span.firstChild);
}
return count;
}, 0);
el.parentNode?.replaceChild(fragment, el);
};

selectors.forEach((text) => {
const dom = document.body.querySelector(text);
if (!dom) {
return;
}
traverse(dom, effect);
});

// 如果没有匹配到,转移到下一个链条进行匹配
if (!frequency) {
if (!store.size) {
return true;
}

return { grade: frequency === 1 ? 0 : 1, text: text.trim() };
return {
grade: store.size === 1 ? 0 : 1,
text: `该岗位描述符合外包定义,出现了:\n${[...store]
.map((item, index) => {
return `${index + 1}. ${item}`;
})
.join("\n")}`,
};
};
13 changes: 10 additions & 3 deletions src/blacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ import { _ReturnType } from "./chain";
import information from "./information.json";

export const blacklist = (): _ReturnType => {
const content =
document.body.querySelector(`a[ka="job-detail-company_custompage"]`)
?.textContent || "";
const dom = document.body.querySelector(
`a[ka="job-detail-company_custompage"]`
) as HTMLAreaElement | null;

if (!dom) {
return true;
}

const content = dom.textContent || "";

let text = "";

const frequency = information.blacklist.some((KeyWord) => {
if (content.includes(KeyWord)) {
text = `公司名称为外包:${KeyWord}`;
dom.style.color = "red";
return true;
}
return false;
Expand Down
8 changes: 5 additions & 3 deletions src/chain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { keyWords } from "./KeyWords";
import { blacklist } from "./blacklist";
import { Props } from "./notify";
import { Props } from "./pages/notify";

export type _ReturnType = (Props & { text: string }) | boolean;

Expand All @@ -11,7 +11,8 @@ class Chain {

next(): _ReturnType {
const result = this.fn();
if (result && this.chain) {

if (result === true && this.chain) {
return this.chain.next.apply(this.chain);
}
return result;
Expand All @@ -26,4 +27,5 @@ class Chain {
const chainKeyWords = new Chain(keyWords);
const chainBlacklist = new Chain(blacklist);

export const result = chainBlacklist.setNext(chainKeyWords).next();
chainBlacklist.setNext(chainKeyWords);
export const result = chainBlacklist.next();
14 changes: 3 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { result } from "./chain";
import { getHtml } from "./notify";
import { addReminder } from "./utils";
import { insertNotify } from "./pages/notify";
import { addReminder } from "./pages/reminder";

(() => {
if (typeof result === "boolean") {
return;
}
const html = getHtml(result);
const dom = document.body.querySelector(".btn-container");
if (!dom) {
return;
}
const div = document.createElement("div");
div.innerHTML = html;
dom.appendChild(div.firstElementChild!);

insertNotify(result);
addReminder(result.text);
})();
6 changes: 5 additions & 1 deletion src/information.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
"浩鲸智能",
"诚迈科技",
"润和软件",
"ST 新海"
"ST 新海",
"慧博云通",
"天源迪科",
"上海思芮",
"塔塔"
],
"KeyWords": [
"解决方案",
Expand Down
12 changes: 10 additions & 2 deletions src/notify.tsx → src/pages/notify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ const Notify: FunctionComponent<Props> = (props) => {
);
};

export const getHtml = (props: Props) => {
return render(<Notify {...props}></Notify>);
export const insertNotify = (props: Props) => {
const html = render(<Notify {...props}></Notify>);

const dom = document.body.querySelector(".btn-container");
if (!dom) {
return;
}
const div = document.createElement("div");
div.innerHTML = html;
dom.appendChild(div.firstElementChild!);
};
26 changes: 26 additions & 0 deletions src/pages/reminder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { FunctionComponent } from "preact";
import { render } from "preact-render-to-string";

interface Props {
text: string;
}

const Reminder: FunctionComponent<Props> = ({ text }) => {
return (
<details>
<summary style={{ cursor: "pointer" }}>查看具体判定规则</summary>
<p style={{ whiteSpace: "pre" }}>{text}</p>
</details>
);
};

export const addReminder = (text: string) => {
const dom = document.body.querySelector(".job-detail");
if (!dom) {
return;
}
const html = render(<Reminder text={text}></Reminder>);
const t = document.createElement("div");
t.innerHTML = html;
dom.insertBefore(t, dom.firstChild);
};
10 changes: 0 additions & 10 deletions src/utils.ts

This file was deleted.

0 comments on commit 15099b3

Please sign in to comment.