// ==UserScript== // @name B站自动签到 // @namespace B站自动签到,Bilibili自动签到 // @version 0.2 // @description B站自动签到工具 // @author You // @include https://www.bilibili.com/* // @include https://t.bilibili.com/ // @icon https://s4.ax1x.com/2021/12/31/TfQpnS.png // @grant none // @downloadURL none // ==/UserScript== (function() { let cookie = document.cookie.split(';')//获取cookie let time = localStorage.getItem("signInTime")//获取上次签到时间 function qd() {//签到方法 fetch("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign", { method: "GET",//GEt请求 mode: 'cors',//跨域 credentials: 'include',//允许携带cookie headers: { 'cookie': cookie,//设置cookie } }).then(data => data.json()) .then(response => { // console.log("签到结果") // if (response.code === 200) {//签到成功 // console.log("签到成功") localStorage.setItem("signInTime", new Date().toDateString())//设置签到的时间戳 show("签到完成")//显示提示 // }else{ // console.log(response.message) // } }) .catch(err => { show("发生错误") console.log(err) }) } function show(showtext) {//签到提示 let showidv = document.createElement("div")//创建标签 showidv.innerText = showtext showidv.style = "position: fixed;right:25px;top:-104px;width: 150px;height:100px;z-index:99999;background-color: #fff;border-radius: 20px;text-align: center;line-height: 100px;transition:all 0.2s linear;box-shadow: 0px 0px 3px 2px #fafafa;"//设置样式 document.body.append(showidv)//添加提示到页面上 setTimeout(() => { showidv.style.top = "35px" }, 100) setTimeout(() => { showidv.style.top = "-104px" }, 2000) setTimeout(() => { document.body.removeChild(showidv) }, 3000) } function sameday(t){//是否同一天 return new Date(t).toDateString() === new Date().toDateString(); } if (time) {//如果有时间则判断时间戳是否是当天的时间 if (sameday(time)) {//是同一天则不签到 show("已经签到过") console.log("已经签到过") }else{ console.log("不是同一天,没有签到过") qd()//请求签到 } } else {//没有时间则没有签到,进行签到,签到完成缓存设置时间戳 console.log("第一次使用此插件签到") qd()//请求签到 } })();