第25行报错,改了一下就可以运行了
[JavaScript] 纯文本查看 复制代码 (() => {
// https://birth.m.jd.com/babelDiy/Zeus/3DMauchBtuvSfu5XwMW1hgdZeLxr/index.html
const keywords = ['鸡蛋', '爱媛38号果冻橙柑橘', '京觅 精品琯溪蜜柚',]; // 想要的关键词
const moument = '2019-11-06 00:00'; // 抢购时间
const ms = +new Date(moument); // 抢购时间毫秒值
const pre = +new Date(ms - 1000 * 5); // 提前 5 秒钟准备
const end = +new Date(ms + 1000 * 60 * 3); // 三分钟之后结束
let reloaded = false;
const part1 = document.querySelector('#NavPart1'); // 列表容器
// 滚动百亿补贴列表,使其全部加载出来
const scroll = () => {
for (let i = 0; i < 18; i++) {
setTimeout(() => {
part1.scrollIntoView(false);
}, 100 * i);
}
};
// 获取服务器时间戳
const getServerTime = () => async function test(){
const header = await fetch('.', {
method: 'head',
}).then((response) => {
return response.headers;
});
return +new Date(header.get('Date'));
};
const intervalId = setInterval(() => {
console.log(`it is running...`);
const now = getServerTime();
// 结束了
if (now >= end) {
console.info(`it's time to end.`);
clearInterval(intervalId);
return;
}
// 准备时间
if (now >= pre) {
console.log(`it's time to go...`);
if (now >= ms) {
// 到点页面不会自动刷新,需要手动加载一下
if (!reloaded) {
location.reload();
reloaded = true;
setTimeout(scroll, 600);
}
const items = part1.querySelectorAll('div.BillionSubsidy-content-item-coupon');
for (let item of items) {
const name = item.querySelector('div.BillionSubsidy-content-item-coupon-name');
for (let key of keywords) {
if (name.innerText.includes(key)) {
console.log(`key: [${ key }], matched: [${ name.innerText }]`);
const right = item.querySelector('div.BillionSubsidy-content-item-coupon-right-container');
const down = item.querySelector('div.BillionSubsidy-content-item-coupon-right-down');
if (right.innerText.includes('限量') && !right.innerText.includes('开抢')) {
console.log(`wanna [${ key }], matched ${ name.innerText }`);
if (down) {
console.info(`--- ${ name.innerText } ---`);
// down.click();
// down.remove();
console.info(`*** u get it ***`);
}
}
}
}
}
}
}
}, 800);
})(); |