代码拉取完成,页面将自动刷新
同步操作将从 Coolman/55a14dab8766eedda13268e931a4d09e 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// ==UserScript==
// @name get-jd-coupon
// @namespace http://tampermonkey.net/
// @version 0.1
// @description get specific coupons
// @author Coolman
// @match https://birth.m.jd.com/babelDiy/Zeus/3DMauchBtuvSfu5XwMW1hgdZeLxr/index.html*
// @grant none
// ==/UserScript==
(() => {
'use strict';
// 超级百亿补贴
// https://birth.m.jd.com/babelDiy/Zeus/3DMauchBtuvSfu5XwMW1hgdZeLxr/index.html
const keywords = ['鸡蛋', '爱媛38号果冻橙柑橘', '京觅 精品琯溪蜜柚', '脱脂纯牛奶',
'电饭煲电饭锅', '金龙鱼 长粒香大米 东北大米 5kg', '云南玉溪高山冰糖橙',
'陕西徐香绿心猕猴桃', '洁柔(C&S)抽纸',
]; // 想要的关键词
const truePrice = 9.9; // 券后九块九的我都要辣!!
const moment = '2019-11-09 14:00'; // 抢购时间
const ms = +new Date(moment); // 抢购时间毫秒值
const pre = +new Date(ms - 1000 * 10); // 提前 10 秒钟准备
const end = +new Date(ms + 1000 * 60 * 3); // 三分钟之后结束
const reloadedKey = 'reloaded' + moment;
const getAllLessThan = (price) => {
const items = document.querySelectorAll('div.BillionSubsidy-content-item-coupon');
for (let item of items) {
const name = item.querySelector('div.BillionSubsidy-content-item-coupon-name');
const truePrice = item.querySelector('div.BillionSubsidy-content-item-coupon-true-price-container > span');
if (truePrice.innerText <= price) {
console.log(`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('开抢')) {
if (down) {
console.info(`--- ${ name.innerText } ---`);
// down.click();
// down.remove();
console.info(`*** u get it ***`);
}
}
}
}
}
const doTask = () => {
const items = document.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 ***`);
}
}
}
}
}
};
// 滚动百亿补贴列表,使其全部加载出来
document.onreadystatechange = () => {
if ('complete' == document.readyState) {
document.querySelector('div.container') && setTimeout(() => {
document.querySelector('div.container').scrollIntoView(false);
}, 600);
}
};
// 获取服务器时间戳
const getServerTime = async () => {
return +new Date((await fetch(`?${ +new Date() }`, {
method: 'head',
}).then((res) => res.headers)).get("Date"));
};
const intervalId = setInterval(() => {
console.log(`it is running...`);
getServerTime().then(now => {
console.log(`server time: ${ now }`);
// 结束了
if (now >= end) {
console.info(`it's time to end.`);
clearInterval(intervalId);
return;
}
// 准备时间
if (now >= pre) {
console.log(`it's time to go...`);
const reloadedValue = sessionStorage.getItem(reloadedKey);
if (now >= ms) {
// 到点页面不会自动刷新,需要手动加载一下
if ('true' != reloadedValue) {
sessionStorage.setItem(reloadedKey, 'true');
location.reload();
}
doTask();
// getAllLessThan(truePrice);
} else {
if ('false' != reloadedValue) {
sessionStorage.setItem(reloadedKey, 'false');
}
}
}
});
}, 800);
})();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。