Files
ObsidianHome/小鱼/.cdp/expr-rules-doc.mjs
T

28 lines
1.0 KiB
JavaScript

(async () => {
const sleep = ms => new Promise(r => setTimeout(r, ms));
// 等正文渲染
let txt = '';
for (let i = 0; i < 20; i++) {
txt = (document.body ? document.body.innerText : '') || '';
if (txt.length > 2000) break;
await sleep(800);
}
const out = { href: location.href, title: document.title, len: txt.length, hits: [], all: '' };
const clean = txt.replace(/\r/g, '');
out.all = clean.slice(0, 60000);
const kws = ['重复', '铺货', '同款', '相同商品', '重复发布', '重复铺货'];
const lines = clean.split('\n').map(s => s.trim()).filter(Boolean);
const seen = new Set();
for (let i = 0; i < lines.length; i++) {
const l = lines[i];
if (kws.some(k => l.includes(k))) {
const ctx = lines.slice(Math.max(0, i - 1), Math.min(lines.length, i + 3)).join(' ⏎ ');
const key = l.slice(0, 60);
if (seen.has(key)) continue;
seen.add(key);
out.hits.push({ line: l.slice(0, 600), ctx: ctx.slice(0, 1200) });
}
}
return out;
})()