Greasy Fork is available in English.

Sonkwo-AutoCheckin

Auto Checkin Script for Sonkwo

  1. // ==UserScript==
  2. // @name Sonkwo-AutoCheckin
  3. // @namespace https://www.sonkwo.cn/
  4. // @license WTFPL
  5. // @description Auto Checkin Script for Sonkwo
  6. // @version 0.0.2
  7. // @author Hiiro
  8. // @match https://www.sonkwo.cn/
  9. // @match https://limestart.cn/
  10. // @icon https://www.sonkwo.cn/favicon.ico
  11. // @run-at document-end
  12. // @grant GM_registerMenuCommand
  13. // ==/UserScript==
  14.  
  15.  
  16. (function () {
  17. 'use strict';
  18. GM_registerMenuCommand('清除本地存储', removeDateStore)
  19. const isSonkwoPage = (window.location.href.toString().indexOf('https://www.sonkwo.cn/') != -1)
  20. const date = new Date().getDate()
  21. function SetDateStore() {
  22. localStorage.setItem('SONKWO-SCRIPT-LAST-RUN', date)
  23. }
  24. function CompareDateStore() {
  25. return localStorage.getItem('SONKWO-SCRIPT-LAST-RUN') == date
  26. }
  27. function removeDateStore() {
  28. localStorage.removeItem('SONKWO-SCRIPT-LAST-RUN')
  29. document.location.reload()
  30. DetectAndRun()
  31. }
  32. function DoCheckin() {
  33. document.getElementsByClassName('orange')[0].click()
  34. }
  35. function isCookieExists(name) {
  36. // 获取当前页面的所有cookies组成的字符串
  37. var cookies = document.cookie.split('; ');
  38.  
  39. for (var i = 0; i < cookies.length; i++) {
  40. // 分割每个cookie为键和值
  41. var cookiePair = cookies[i].split('=');
  42.  
  43. // 清除键名前后的空白字符并转换为小写(因为cookie名称是大小写敏感的)
  44. var cookieName = cookiePair[0].trim().toLowerCase();
  45.  
  46. // 如果找到匹配的cookie名称,则返回true
  47. if (cookieName === name.toLowerCase()) {
  48. return true;
  49. }
  50. }
  51.  
  52. // 如果遍历完所有cookie都未找到匹配项,则返回false
  53. return false;
  54. }
  55. function DetectAndRun() {
  56. if (CompareDateStore()) {
  57. return
  58. }
  59. if (!isSonkwoPage) {
  60. SetDateStore()
  61. window.location.href = 'https://www.sonkwo.cn/'
  62. }
  63. var timer = setInterval(() => {
  64. if (!isCookieExists('access_token')) {
  65. window.location.href = 'https://www.sonkwo.cn/sign_in?return_addr=%2F'
  66. clearInterval(timer)
  67. } else if (document.getElementsByClassName('orange').length != 0) {
  68. if (document.getElementsByClassName('orange')[0].innerHTML == '签到赚积分') {
  69. DoCheckin()
  70. SetDateStore()
  71. clearInterval(timer)
  72. } else if (document.getElementsByClassName('light-gray')[0]?.innerHTML == '已签到') {
  73. SetDateStore()
  74. clearInterval(timer)
  75. }
  76. }
  77. }, 3000)
  78. }
  79. window.onload = function () {
  80. DetectAndRun()
  81. }
  82. })();