function _beforeNotify(id, data) {
const pos1 = data.curData.text.indexOf('悄悄关注');
let tureweibo = data.curData.text;
if (pos1 !== -1) {
// 截取从"悄悄关注"开始往后全部内容
tureweibo = data.curData.text.slice(pos1 + 4).trim();
}
const pos2 = data.curData.text.indexOf('管理');
let turekey = data.curData.text;
if (pos2 !== -1) {
// 截取从"悄悄关注"开始往后全部内容
turekey = data.curData.text.slice(pos2+2, pos1);
}
keywords = turekey.split(/\r?\n/).filter(item => item.trim());
data.curData.text = tureweibo;
const originLines = data.curData.text.split(/\r?\n/);
for (const kw of keywords) {
if (data.curData.text.includes(kw)) {
data.config.webhook = "https://api.day.app/qmLUgvJK8AS3jSZZd4Sshj/?call=1&group=羊毛&sound=electronic";
}
}
const filterLines = originLines;
const htmlStr = data.curData.html;
// 匹配目标商品a标签正则
const aReg = /<a[^>]*href="[^"]*shop\.sc\.weibo\.com\/h5\/goods\/index[^"]*"[^>]*>([\s\S]*?)<\/a>/g;
const result = [];
let match;
while ((match = aReg.exec(htmlStr)) !== null) {
const fullMatchStr = match[0];
const matchStartIndex = match.index;
// 截取a标签前面最多7个字符
const pre7Text = htmlStr.slice(Math.max(0, matchStartIndex - 7), matchStartIndex);
// 前7字符内包含“凑单”则排除
if (pre7Text.includes('凑单')) {
continue;
}
// 提取a内纯文本
const innerText = match[1].replace(/<[^>]+>/g, '').trim();
if (innerText) {
result.push(innerText);
}
}
let finalLines;
if (result.length === 0) {
finalLines = originLines;
} else {
finalLines = result;
}
if (finalLines.length > 0) {
// 第一行作为标题
let title = finalLines[0].trim();
// 剩下所有行拼接成正文
const restLines = finalLines.slice(1);
let content = restLines.join('\n');
// 正文为空时,拆分标题,前9字符为新标题,剩余为正文
if (!content.trim()) {
if (title.length > 9) {
content = title.slice(9);
title = title.slice(0, 9);
} else {
content = '';
}
}
data.config.title = title;
data.text = content;
} else {
data.config.title = '';
data.text = '';
}
// data.config.title = turekey;
_callback(id, data);
}
console