-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e44bfc7
commit 15099b3
Showing
12 changed files
with
134 additions
and
117 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ on: | |
push: | ||
branches: | ||
- master | ||
paths: | ||
- src/** | ||
|
||
jobs: | ||
build: | ||
|
This file was deleted.
Oops, something went wrong.
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
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
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
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")}`, | ||
}; | ||
}; |
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
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
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
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); | ||
})(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,11 @@ | |
"浩鲸智能", | ||
"诚迈科技", | ||
"润和软件", | ||
"ST 新海" | ||
"ST 新海", | ||
"慧博云通", | ||
"天源迪科", | ||
"上海思芮", | ||
"塔塔" | ||
], | ||
"KeyWords": [ | ||
"解决方案", | ||
|
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
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
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); | ||
}; |
This file was deleted.
Oops, something went wrong.