autoGiveLike

始皇别封我号,用来给linux.do帖子自动点赞的

  1. // ==UserScript==
  2. // @name autoGiveLike
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-10-28.1
  5. // @description 始皇别封我号,用来给linux.do帖子自动点赞的
  6. // @author Kubbo
  7. // @match https://linux.do/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. console.log("始皇你好~")
  16.  
  17. //@XODI @Hua 借用你们的防邀设置,做清清白白的人~
  18. const redirectIfNeeded = () => {
  19. if (window.location.href.includes("https://linux.do/invites/")) {
  20. window.location.replace("https://linux.do");
  21. }
  22.  
  23. document.querySelectorAll("div .regular .contents").forEach((el) => {
  24. el.querySelectorAll("a").forEach((a) => {
  25. if (a.href.includes("https://linux.do/invites/")) {
  26. a.href = "https://linux.do";
  27. }
  28. });
  29. });
  30. };
  31.  
  32. document.addEventListener('DOMContentLoaded', redirectIfNeeded);
  33.  
  34. const observer = new MutationObserver(redirectIfNeeded);
  35. observer.observe(document.body, {childList: true, subtree: true});
  36.  
  37. const getTopics = id => fetch(`/t/${id}.json?track_visit=true&forceLoad=true`).then(res => res.json()).then(res => {
  38. const topics = res?.post_stream?.stream || []
  39. console.log("本次查询一共有%s个帖子", topics.length)
  40. return topics
  41. })
  42. const initBtn = () => {
  43. setInterval(() => {
  44. const autoBtn = document.querySelector("#autoGiveLike")
  45. if (/\/t\/topic/.test(location.pathname)) {
  46. if (!autoBtn) {
  47. const btn = document.createElement("button")
  48. let status = 0 // 脚本执行状态: 0:未开始 1:正在执行中
  49. btn.id = "autoGiveLike"
  50. btn.innerText = "开始自动点赞"
  51. btn.style.position = "fixed"
  52. btn.style.top = "10px"
  53. btn.style.right = "20px"
  54. btn.style.padding = "8px 16px"
  55. btn.style.background = "#409EFF"
  56. btn.style.color = "#fff"
  57. btn.style.border = "none"
  58. btn.style.borderRadius = "16px"
  59. btn.style.zIndex = "202403101044"
  60. btn.addEventListener("click", () => {
  61. if (status === 0) {
  62. status = 1
  63. btn.innerText = "停止自动点赞"
  64. btn.style.background = "#F56C6C"
  65. const topicId = location.pathname.match(/\/topic\/([^/]+)/)?.[1]
  66. topicId && getTopics(topicId).then(ids => {
  67. let i = 0
  68. const token = document.querySelector('meta[name="csrf-token"]').content
  69. const loop = () => {
  70. if (status === 1) {
  71. const id = ids[i]
  72. fetch(`/discourse-reactions/posts/${id}/custom-reactions/heart/toggle.json`, {
  73. method: "PUT",
  74. headers: {"X-Csrf-Token": token}
  75. }).finally(() => {
  76. i++
  77. if (i <= 50 && i <= ids.length) { //设置50的阈值,防止始皇封我号
  78. setTimeout(loop, 50);
  79. }
  80. })
  81. }
  82. }
  83. loop()
  84. })
  85. } else if (status === 1) {
  86. status = 0
  87. btn.innerText = "开始自动点赞"
  88. btn.style.background = "#409EFF"
  89. }
  90. })
  91. document.body.appendChild(btn)
  92. }
  93. } else if (autoBtn) {
  94. autoBtn.remove()
  95. }
  96. }, 500)
  97. }
  98. initBtn()
  99.  
  100. function showHotKeys() {
  101. const hotKeys = [
  102. {name: '描述', keys: '快捷键'},
  103. {name: '最新', keys: 'G+L'},
  104. {name: '新', keys: 'G+N'},
  105. {name: '未读', keys: 'G+U'},
  106. {name: '类别', keys: 'G+C'},
  107. {name: '热门', keys: 'G+T'},
  108. {name: '书签', keys: 'G+B'},
  109. {name: '个人资料', keys: 'G+P'},
  110. {name: '消息', keys: 'G+M'},
  111. {name: '草稿', keys: 'G+D'},
  112. ]
  113. const table = document.createElement('table')
  114. table.style.position = 'fixed'
  115. table.style.top = '50%'
  116. table.style.transform = 'translateY(-50%)'
  117. table.style.right = '10px'
  118. table.style.zIndex = '202403101044'
  119. table.style.fontSize = '14px'
  120. table.style.color = '#fff'
  121. table.style.borderRadius = '4px'
  122. hotKeys.forEach(key => {
  123. const tr = document.createElement('tr')
  124. const td1 = document.createElement('td')
  125. const td2 = document.createElement('td')
  126. td1.style.padding = '4px 10px'
  127. td1.innerText = key.name
  128. td2.innerText = key.keys
  129. tr.appendChild(td1)
  130. tr.appendChild(td2)
  131. table.appendChild(tr)
  132. })
  133. document.body.appendChild(table)
  134. }
  135.  
  136. showHotKeys()
  137. })();
  138.  

QingJ © 2025

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