油猴脚本规则
// ==UserScript== // @name 这里是你的编写的油猴脚本的名字 // @namespace 这个是命名空间;用来区分名称相同但是作者不同的用户脚本,一般都是写作者的个人网址,没有也可以写你的博客地址 // @version 这个是你编写的脚本版本号 // @description 这个是功能描述,描述你的这个脚本是用来干嘛的 // @author 这个是作者的名字,比如我:无仙 // @match 这个是该脚本匹配的网址,支持通配符匹配 // @icon 脚本图标 // @grant 请看下边表格 // ==/UserScript== (function() { 'use strict'; // 你的脚本代码 })();
签到业务场景
那我们要写的这个脚本的场景就是帮助我们在浏览器打开掘金的时候实现自动签到
并且签到之后,会获得一次免费抽奖的机会,顺便可以实现自动免费抽奖
// ==UserScript== // @name 掘金自动签到免费抽奖 // @namespace http://tampermonkey.net/ // @version 1.0.0 // @description 掘金自动签到 自动触发免费抽奖 // @author 无仙 // @match https://juejin.cn/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // ==/UserScript== (function () { 'use strict'; // 抽奖 const drawFn = async () => { // 查询今日是否有免费抽奖机会 const today = await fetch('https://api.juejin.cn/growth_api/v1/lottery_config/get', { headers: { cookie: document.cookie }, method: 'GET', credentials: 'include' }).then((res) => res.json()); if (today.err_no !== 0) return console.warn('免费抽奖失败!'); if (today.data.free_count === 0) return console.log('今日已经免费抽奖!'); // 免费抽奖 const draw = await fetch('https://api.juejin.cn/growth_api/v1/lottery/draw', { headers: { cookie: document.cookie }, method: 'POST', credentials: 'include' }).then((res) => res.json()); if (draw.err_no !== 0) return console.warn('免费抽奖失败!'); [3, 4].includes(draw.data.lottery_type) ? alert(`恭喜抽到:${draw.data.lottery_name}`) : console.log(`恭喜抽到:${draw.data.lottery_name}`); }; // 签到 (async () => { // 查询今日是否已经签到 const today_status = await fetch('https://api.juejin.cn/growth_api/v1/get_today_status', { headers: { cookie: document.cookie }, method: 'GET', credentials: 'include' }).then((res) => res.json()); if (today_status.err_no !== 0) return console.warn('签到失败!'); if (today_status.data) { console.log('今日已经签到!'); drawFn(); return; } // 签到 const check_in = await fetch('https://api.juejin.cn/growth_api/v1/check_in', { headers: { cookie: document.cookie }, method: 'POST', credentials: 'include' }).then((res) => res.json()); if (check_in.err_no !== 0) return console.warn('签到失败!'); console.log(`签到成功!当前积分;${check_in.data.sum_point}`); drawFn(); })(); })();
版权声明:本文为原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
关注微信公众号:"cq_xifan";