B站自动签到

B站自动签到工具

  1. // ==UserScript==
  2. // @name B站自动签到
  3. // @namespace B站自动签到,Bilibili自动签到
  4. // @version 0.6
  5. // @description B站自动签到工具
  6. // @author You
  7. // @include https://www.bilibili.com/*
  8. // @include https://t.bilibili.com/*
  9. // @include https://live.bilibili.com/*
  10. // @include https://www.bilibili.com/video/*
  11. // @icon https://s4.ax1x.com/2021/12/31/TfQpnS.png
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. let cookie = document.cookie.split(';')//获取cookie
  17. let time = localStorage.getItem("signInTime")//获取上次签到时间
  18.  
  19. function qd() {//签到方法
  20. fetch("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign", {
  21. method: "GET",//GEt请求
  22. mode: 'cors',//跨域
  23. credentials: 'include',//允许携带cookie
  24. headers: {
  25. 'cookie': cookie,//设置cookie
  26. }
  27. }).then(data => data.json())
  28. .then(response => {
  29. localStorage.setItem("signInTime", new Date().toDateString())//设置签到的时间戳
  30. show("签到完成")//显示提示
  31. })
  32. .catch(err => {
  33. show("发生错误",false)
  34. console.log(err)
  35. })
  36. }
  37. function show(showtext,bool=true) {//签到提示
  38. let showidv = document.createElement("div")//创建标签
  39. let icon = bool ? "🎉 " : "🚫 "
  40. showidv.innerText = icon + showtext
  41. showidv.style = "background-image: linear-gradient(45deg, rgb(255 186 251), rgb(41 201 255));color:#fff;font-size:20px;position: fixed;top:-104px;right:23px;width: 150px;height:100px;z-index:99999;border-radius: 20px;text-align: center;line-height: 100px;transition:all 0.2s linear;"//设置样式
  42. document.body.append(showidv)//添加提示到页面上
  43. setTimeout(() => {
  44. showidv.style.top = "55px"
  45. }, 100)
  46. setTimeout(() => {
  47. showidv.style.top = "-104px"
  48. }, 2000)
  49. setTimeout(() => {
  50. document.body.removeChild(showidv)
  51. }, 3000)
  52. }
  53. function sameday(t) {//是否同一天
  54. return t === new Date().toDateString();
  55. }
  56. console.log(time)
  57. if (time) {//如果有时间则判断时间戳是否是当天的时间
  58. if (!sameday(time)) {//不是同一天就签到
  59. console.log("今天没有签到过,正在签到")
  60. qd()//请求签到
  61. }else{
  62. console.log("已经签到过");
  63. }
  64. } else {//没有时间则没有签到,进行签到,签到完成缓存设置时间戳
  65. console.log("第一次使用此插件签到,正在签到")
  66. qd()//请求签到
  67. }
  68. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址