boss一键沟通

try to take over the world!

  1. // ==UserScript==
  2. // @name boss一键沟通
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-02-26
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://www.zhipin.com/*
  8. // @icon https://static.zhipin.com/v2/web/geek/images/logo.png
  9. // @grant none
  10. // @require https://cdn.jsdelivr.net/npm/dayjs@1.11.10/dayjs.min.js
  11. // @license GPL-3.0
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. const dayjs = window.dayjs;
  17.  
  18. class Store {
  19. constructor() {
  20. this.store = {
  21. name: "BossOk",
  22. jobListReqs: [],
  23. jobMap: {},
  24. };
  25. }
  26. set(key, value) {
  27. this.store[key] = value;
  28. }
  29. get(key) {
  30. return this.store[key];
  31. }
  32. bgColor(diffday) {
  33. if (diffday > 90) return "transparent";
  34. if (diffday > 30) return "#e8f7d8";
  35. if (diffday > 7) return "#f7e4d8";
  36. return "#f7d8d8";
  37. }
  38. }
  39.  
  40. const store = new Store();
  41.  
  42. function log(message) {
  43. console.log(`[${store.get("name")}]`, message);
  44. }
  45.  
  46. function onFetchJoblist(data) {
  47. log(data);
  48. const jobList = data?.zpData?.jobList;
  49. const jobMap = jobList.reduce((acc, cur) => {
  50. acc[cur.encryptJobId] = cur;
  51. return acc;
  52. }, store.get("jobMap") || {});
  53. store.set("jobMap", jobMap);
  54.  
  55. const $a = document.querySelectorAll("a[href]");
  56. $a.forEach((dom) => {
  57. const href = dom.getAttribute("href");
  58. const jobId = href.match(/job_detail\/(.*?)\.html/)?.[1];
  59. if (!jobId) return;
  60. // 已经添加过的不再添加
  61. const attrKey = store.get("name").toLowerCase();
  62. if (dom.parentNode.querySelector(`[${attrKey}]`)){return;}
  63. const job = jobMap[jobId];
  64. if (!job) return;
  65. const { lastModifyTime } = job;
  66. const infodom = document.createElement("div");
  67. const diffday = -dayjs(lastModifyTime).diff(dayjs(), "day");
  68. infodom.innerHTML = `📅 最后更新日期:${dayjs(lastModifyTime).format(
  69. "YYYY-MM-DD"
  70. )} (${diffday}天前)`;
  71. infodom.style = `padding: 10px;background: ${store.bgColor(diffday)};`;
  72. infodom.setAttribute(attrKey, jobId);
  73. dom.parentNode.appendChild(infodom);
  74. });
  75. }
  76.  
  77. function updateJoblistReqs() {
  78. const urls = window.performance
  79. .getEntries()
  80. .filter((item) => item.name.includes("joblist.json?"))
  81. ?.map((item) => item.name);
  82. store.set("jobListReqs", urls);
  83. return urls;
  84. }
  85.  
  86.  
  87. function update () {
  88. const now_urls = updateJoblistReqs();
  89. // 当客户端发起新请求时
  90. if (now_urls[now_urls.length - 1] != now_urls[now_urls.length - 2]) {
  91. const url = now_urls[now_urls.length - 1];
  92. window.fetch(url).then((res) => {
  93. res.json().then((data) => {
  94. onFetchJoblist(data);
  95. setTimeout(() => {
  96. update();
  97. }, 5000);
  98. });
  99. });
  100. } else {
  101. setTimeout(() => {
  102. update();
  103. }, 3000);
  104. }
  105. }
  106.  
  107. update()
  108.  
  109. // Your code here...
  110. // 定义一个等待函数
  111. function wait(ms) {
  112. return new Promise(resolve => setTimeout(resolve, ms));
  113. }
  114. function getRandomInteger(min, max) {
  115. return Math.floor(Math.random() * (max - min + 1)) + min;
  116. }
  117. // 创建一个容器
  118. let container = document.createElement('div');
  119. container.style.position = 'fixed';
  120. container.style.top = '50px';
  121. container.style.right = '10px';
  122. container.style.zIndex = '10000';
  123. document.body.appendChild(container);
  124.  
  125.  
  126. // 创建一键沟通按钮
  127. let communicateBtn = document.createElement('button');
  128. communicateBtn.textContent = '一键沟通';
  129. container.appendChild(communicateBtn);
  130.  
  131.  
  132.  
  133. communicateBtn.addEventListener('click', function() {
  134. // 获取所有具有 "start-chat-btn" 类的元素
  135. var buttons = document.getElementsByClassName("start-chat-btn");
  136.  
  137. // 定义一个函数,用于执行延迟点击
  138. async function delayedClick(index) {
  139. if (index >= buttons.length) {
  140. console.log("所有按钮点击完成");
  141. alert('执行完毕');
  142. return; // 如果所有按钮都已经被点击,就退出函数
  143. }
  144. if( buttons[index].innerText==="继续沟通"){
  145. console.log("已沟通")
  146. }else{
  147. // 触发点击
  148. let match_day = document.getElementsByClassName("job-card-body clearfix")[index].children[2].innerText.match(/(\d+)天前/)
  149. let daysAgo = match_day ? parseInt(match_day[1], 10) : null;
  150. if(daysAgo <= 7){
  151. buttons[index].click();
  152. //console.log(document.getElementsByClassName("job-card-body clearfix")[index].children[2].innerText)
  153. console.log("按钮 " + index + " 被点击");
  154. await wait(2000)
  155. document.querySelector("body > div.greet-boss-dialog > div.greet-boss-container > div.greet-boss-footer > a.default-btn.cancel-btn").click()
  156. }else{
  157. console.log("发布日期过长")
  158. }
  159.  
  160. }
  161.  
  162. await wait(getRandomInteger(300, 2000))
  163. // 设置下一个点击的延迟
  164. setTimeout(function() {
  165. delayedClick(index + 1);
  166. }, 1000); // 这里设置的延迟是1000毫秒(1秒)
  167. }
  168.  
  169. // 开始遍历并延迟点击每个按钮
  170. delayedClick(0);
  171.  
  172.  
  173. });
  174.  
  175.  
  176.  
  177. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址