前提:BOSS直聘VIP用户
通过网页抓包分析可得:VIP功能的聊天消息设置优先提醒boss的API接口为:
https://www.zhipin.com/wapi/zpitem/web/online/setRemind
请求方式:post
传输的数据(securityId可从API https://www.zhipin.com/wapi/zprelation/friend/getGeekFriendList.json?page=1 获取):
securityId=xxx&source=12&
成功:
{
"code": 0,
"message": "Success",
"zpData": {
"hasVip": true,
"vipUrl": null,
"hasNoDisturb": false,
"remindResult": true
}
}
一段时间内重复设置,设置失败:
{
"code": 0,
"message": "Success",
"zpData": {
"hasVip": true,
"vipUrl": null,
"hasNoDisturb": false,
"remindResult": false
}
}
逻辑:查询前100个BOSS聊天最近一条由我发出的信息状态为送达的BOSS(已读的或不是我发出的信息则不需要使用功能),使用设置优先提醒BOSS功能。
结合前文https://www.cnblogs.com/harglo/p/16798799.html的BOSS聊天消息状态显示,编写JavaScript油猴脚本如下:
// ==UserScript==
// @name BOSS聊天消息状态显示及一键优先提醒
// @namespace http://tampermonkey.net/
// @version 0.2
// @description try to take over the world!
// @author You
// @match https://www.zhipin.com/web/geek/chat*
// @require https://unpkg.com/[email protected]/dist/ajaxhook.min.js
// @require https://unpkg.com/[email protected]/dist/axios.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
function axiosArr(data){
return axios({
method:"post",
url:'https://www.zhipin.com/wapi/zpitem/web/online/setRemind',
headers: {'zp_token': document.cookie.match(/(?<=geek_zp_token=)(.*?)(?=($|;))/)[0]},
withCredentials:true,
data:"securityId="+data+"&source=12&"
})
}
let remindSuccess=0; //设置成功
let remindRepeat=0; //短时间内重复使用该功能,设置失败
let securityIdArr=[];
let requestArray=[];
ah.proxy({
onRequest: (config, handler) => {
handler.next(config);
},
one rror: (err, handler) => {
handler.next(err)
},
onResponse: (response, handler) => {
if(response.config.url=="/wapi/zprelation/friend/getGeekFriendList.json?page=1"){
let responseJson=JSON.parse(response.response);
let resultData=responseJson.zpData.result;
setTimeout(function () {
var text = document.getElementsByClassName('text');
console.log(text.length);
for (let i = 0; i < resultData.length; i++) {
let span = document.createElement('span');
span.setAttribute('class','time');
if(resultData[i].lastMessageInfo.status==1){ //送达
span.textContent="-送达";
if(resultData[i].lastMessageInfo.fromId==123456789){//判断是否为由我发送的消息(123456789为具体的用户ID)
securityIdArr.push(resultData[i].securityId);
}
}else if(resultData[i].lastMessageInfo.status==2||resultData[i].lastMessageInfo.status==0){
span.textContent="-已读";
}else{
span.textContent="-status:"+resultData[i].lastMessageInfo.status;
}
text[i].children[0].insertBefore(span,text[i].children[0].children[0]);
}
//生成页面按钮
let d1 = document.createElement("div");
d1.style.cssText = "width:80px;height:30px;border-radius:3px;background-color:#00bebd;position:absolute;left:5px;top:120px;z-index:999;cursor:pointer;color:white;text-align:center;font-size:10px;line-height:30px";
d1.textContent="一键优先提醒";
//按钮点击方法
d1.onclick=function(){
console.log("设置优先提醒");
for (let i = 0; i < securityIdArr.length; i++) {
requestArray.push(axiosArr(securityIdArr[i]));
}
axios.all(requestArray).then(
axios.spread((...resp) => {
[...resp].forEach((item, index) => {
if(item.data.zpData.remindResult){
remindSuccess++;
}else{
remindRepeat++;
}
});
console.log("共送达:"+(remindSuccess+remindRepeat)+"个,其中设置优先提醒成功"+remindSuccess+"个");
})
).catch(error => {
console.log(error)
});
};
document.body.appendChild(d1);
},3000);
}
handler.next(response);
}
});
})();
效果:在消息页面https://www.zhipin.com/web/geek/chat点击页面上生成的按钮一键设置消息状态为送达的BOSS使用VIP功能-优先提醒BOSS。
标签:span,直聘,resultData,BOSS,VIP,https,text,com From: https://www.cnblogs.com/harglo/p/16800337.html