1 Star 0 Fork 8

landcruser99/55a14dab8766eedda13268e931a4d09e

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
get-free-coupons.js 2.52 KB
一键复制 编辑 原始数据 按行查看 历史
zhanglianxin 提交于 2019-11-09 13:56 . fix
// ==UserScript==
// @name get-free-coupons
// @namespace http://tampermonkey.net/
// @version 0.1
// @description get free coupons
// @author Coolman
// @match https://prodev.m.jd.com/mall/active/2F3KrzC3cVRqVZNxoDoVgz5StZZ8/index.html*
// @grant none
// ==/UserScript==
(() => {
'use strict';
// 生鲜好物低价购
// https://prodev.m.jd.com/mall/active/2F3KrzC3cVRqVZNxoDoVgz5StZZ8/index.html
const moument = '2019-11-08 20:00'; // 抢购时间
const ms = +new Date(moument); // 抢购时间毫秒值
const pre = +new Date(ms - 1000 * 5); // 提前 5 秒钟准备
const end = +new Date(ms + 1000 * 60 * 1); // 一分钟之后结束
// 获取服务器时间戳
const getServerTime = async () => {
return +new Date((await fetch(`?${ +new Date() }`, {
method: 'head',
}).then((res) => res.headers)).get("Date"));
};
const doTask = () => {
const coupons = document.querySelectorAll('div.free_coupon a.coupon');
for (let coupon of coupons) {
console.log(coupon.innerText.replace('\n', ' '));
if (coupon.classList.contains('coupon_today_receive')) {
// 今日已领取
console.log('今日已领取');
} else if (coupon.classList.contains('coupon_today_empty')) {
// 今日已抢完
console.log('今日已抢完');
} else if (coupon.classList.contains('coupon_receive')) {
// 已领取
console.log('已领取');
} else if (coupon.classList.contains('coupon_empty')) {
// 已抢完
console.log('已抢完');
} else {
console.info('--- 抢它 ---')
// coupon.click();
// coupon.remove();
}
}
};
const intervalId = setInterval(() => {
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...`);
if (now >= ms) {
doTask();
}
} else {
console.info(`it's too early.`);
clearInterval(intervalId);
return;
}
});
}, 800);
})();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/landcruser99/55a14dab8766eedda13268e931a4d09e.git
git@gitee.com:landcruser99/55a14dab8766eedda13268e931a4d09e.git
landcruser99
55a14dab8766eedda13268e931a4d09e
55a14dab8766eedda13268e931a4d09e
master

搜索帮助