4khd.com Helper

auto click, remove ads, record failure links

目前为 2025-04-19 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 4khd.com Helper
  3. // @namespace http://tampermonkey.net/
  4. // @description auto click, remove ads, record failure links
  5. // @author rainbowflesh
  6. // @include https://m.4khd.com/*
  7. // @include https://m.4khd.com/vip/*
  8. // @include https://www.terabox.com/s/*
  9. // @connect m.4khd.com
  10. // @version 1.0.0
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=4khd.com
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_cookie
  14. // @grant GM.cookie
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. "use strict";
  20.  
  21. function autoClicker() {
  22. const interval = setInterval(() => {
  23. const button = document.getElementById("custom_button");
  24. if (button) {
  25. button.click();
  26. clearInterval(interval);
  27. }
  28. }, 100);
  29. }
  30.  
  31. function adsRemover() {
  32. window.addEventListener("load", () => {
  33. new MutationObserver(() => {
  34. document.querySelector("div.popup")?.remove();
  35. }).observe(document.body, {
  36. childList: true,
  37. subtree: true,
  38. });
  39. });
  40. }
  41.  
  42. function createLinkGroupUIContainer() {
  43. let linkGroupUIContainer = document.getElementById("linkGroupUIContainer");
  44. if (linkGroupUIContainer) return linkGroupUIContainer;
  45.  
  46. linkGroupUIContainer = document.createElement("div");
  47. linkGroupUIContainer.id = "linkGroupUIContainer";
  48. linkGroupUIContainer.style = `
  49. position: fixed;
  50. top: 10px;
  51. left: 10px;
  52. z-index: 9999;
  53. background: rgba(0, 0, 0, 0.6);
  54. padding: 10px;
  55. border-radius: 8px;
  56. max-height: 90vh;
  57. min-width: 8em;
  58. overflow-y: auto;
  59. `;
  60.  
  61. const title = document.createElement("div");
  62. title.textContent = "Failure links";
  63. title.style = `
  64. text-align: center;
  65. font-size: 16px;
  66. font-weight: bold;
  67. margin-bottom: 8px;
  68. color: white;
  69. `;
  70.  
  71. const linksWrapper = document.createElement("div");
  72. linksWrapper.id = "linkList";
  73.  
  74. linkGroupUIContainer.appendChild(title);
  75. linkGroupUIContainer.appendChild(linksWrapper);
  76. document.body.appendChild(linkGroupUIContainer);
  77. return linkGroupUIContainer;
  78. }
  79.  
  80. function createCookedLink() {
  81. const stored = JSON.parse(localStorage.getItem("failureStatus") || "{}");
  82. const sortedKeys = Object.keys(stored).sort();
  83.  
  84. const container = createLinkGroupUIContainer();
  85. const linkList = container.querySelector("#linkList");
  86. linkList.innerHTML = ""; // reset link list
  87.  
  88. sortedKeys.forEach((key) => {
  89. if (stored[key] === true) return; // hide "true"
  90.  
  91. const linkWrapper = document.createElement("div");
  92. linkWrapper.className = "failure-link";
  93. linkWrapper.style = `
  94. display: flex;
  95. align-items: center;
  96. justify-content: space-between;
  97. gap: 8px;
  98. margin-bottom: 6px;
  99. `;
  100.  
  101. const link = document.createElement("a");
  102. link.href = `https://m.4khd.com/${key}`;
  103. link.target = "_blank";
  104. link.innerText = key;
  105. link.style.color = "red";
  106. link.style.marginRight = "8px";
  107.  
  108. const deleteBtn = document.createElement("button");
  109. deleteBtn.style = `
  110. color: #fff;
  111. background: #900;
  112. border: none;
  113. border-radius: 4px;
  114. cursor: pointer;
  115. padding: 2px;
  116. vertical-align: middle;
  117. display: flex;
  118. align-items: center;
  119. justify-content: center;
  120. width: 20px;
  121. height: 20px;
  122. `;
  123. deleteBtn.innerHTML = `
  124. <svg width="9" height="9" xmlns="http://www.w3.org/2000/svg" fill="white" fill-opacity="context-fill-opacity"><path d="M1 .412a.588.588 0 0 0-.416.172.588.588 0 0 0 0 .832L3.668 4.5.584 7.584a.588.588 0 0 0 0 .832.588.588 0 0 0 .832 0L4.5 5.332l3.084 3.084a.588.588 0 0 0 .832 0 .588.588 0 0 0 0-.832L5.332 4.5l3.084-3.084a.588.588 0 0 0 0-.832.588.588 0 0 0-.832 0L4.5 3.668 1.416.584A.588.588 0 0 0 1 .412z"/></svg>
  125. `;
  126. deleteBtn.onclick = () => {
  127. const data = JSON.parse(localStorage.getItem("failureStatus") || "{}");
  128. data[key] = true;
  129. localStorage.setItem("failureStatus", JSON.stringify(data));
  130. linkWrapper.remove();
  131. };
  132.  
  133. linkWrapper.appendChild(link);
  134. linkWrapper.appendChild(deleteBtn);
  135. linkList.appendChild(linkWrapper);
  136. });
  137. }
  138.  
  139. // save cookie to localStorage
  140. function saveCookies() {
  141. GM_cookie.list({}, function (cookies, error) {
  142. if (!error) {
  143. const cook = cookies.filter((c) => c.name.startsWith("short_"));
  144. if (cook.length === 0) return;
  145. const stored = JSON.parse(localStorage.getItem("failureStatus") || "{}");
  146. cook.forEach((c) => {
  147. const key = c.name.replace("short_", "");
  148. if (!(key in stored)) {
  149. stored[key] = false;
  150. console.log("4khd helper: add new key ", key);
  151. } else {
  152. console.log("4khd helper: ", key, "already exists in localStorage");
  153. }
  154. });
  155.  
  156. localStorage.setItem("failureStatus", JSON.stringify(stored));
  157. createCookedLink();
  158. } else {
  159. console.error(error);
  160. }
  161. });
  162. }
  163.  
  164. if (location.href.startsWith("https://m.4khd.com/vip/index.php")) {
  165. window.addEventListener("load", () => {
  166. saveCookies();
  167. });
  168. }
  169.  
  170. window.addEventListener("load", () => {
  171. autoClicker();
  172. adsRemover();
  173. createCookedLink();
  174. });
  175. })();