旺旺UpUp

牛刀小试

目前为 2024-11-02 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/515340/1476348/%E6%97%BA%E6%97%BAUpUp.js

  1. // ==UserScript==
  2. // @name 旺旺UpUp
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.3
  5. // @description 牛刀小试
  6. // @author theCrazy-handsomeboy
  7. // @match https://ads.tiktok.com/i18n/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function getRandomTime() {
  12. const min = 8000; // 最小值
  13. const max = 12000; // 最大值
  14. return Math.random() * (max - min) + min; // 返回随机时间
  15. }
  16.  
  17. (function () {
  18. "use strict";
  19.  
  20. // check element
  21. const targetSelector = ".biz-right-bar";
  22. let successfulCount = 0;
  23. let intervalId;
  24. let codeTextArea = "";
  25. let runFlag = false;
  26. //---------- The Box ----------
  27. const popupContainer = document.createElement("div");
  28. popupContainer.id = "popupContainer";
  29. Object.assign(popupContainer.style, {
  30. position: "fixed", // Changed from "none" to "fixed"
  31. display: "none",
  32. justifyContent: "space-between",
  33. alignItems: "center",
  34. top: "90%",
  35. left: "230px",
  36. transform: "translate(-50%, -50%)",
  37. padding: "10px",
  38. backgroundColor: "white",
  39. boxShadow: "0 4px 8px rgba(0, 0, 0, 0.2)",
  40. zIndex: "1000",
  41. width: "380px",
  42. borderRadius: "8px",
  43. });
  44.  
  45. popupContainer.innerHTML = `
  46. <div style="display:flex;justify-content: center;">
  47. <h4>Execution Count:${successfulCount}</h4>
  48. </div>
  49. <div style="display: flex;">
  50. <textarea id="CodeTextarea" rows="3" style="width: 200px; margin-bottom: 10px;margin-top:2px"></textarea>
  51. <div>
  52. <div>
  53.  
  54. <button id="executeBtn" style="font-size: 15px; margin-left: 10px; cursor: pointer; width: 50px; height: 30px; margin-right: 10px; border: none; background-color: #5475e7; color: #fff;">run</button>
  55. </div>
  56. <div>
  57. <button id="stopBtn" style="margin-top:5px;font-size: 15px; width: 50px; margin-left: 10px;xcursor: pointer; height: 30px; margin-right: 10px; border: none; background-color: #e75454; color: #fff;">stop</button>
  58. </div>
  59. </div>
  60. <div style="margin-right:10px;margin-left:10px">
  61. <div style="display: flex; justify-content: center; align-items: center;">
  62. <p>Count:</p>
  63. <input type="number" id="loopCount" min="10" value="10" style="cursor: pointer; width: 50px; font-size: 20px; border-radius: 5px; ">
  64. <button id="clearAll" style="margin-left: 10px;font-size: 15px; width: 60px; cursor: pointer; height: 30px; margin-right: 10px; border: none; background-color: #54e780; color: #fff;">clearAll</button>
  65. </div>
  66. <div style="display: flex; justify-content: center; align-items: center;margin-top:5px">
  67. <p>Timer:</p>
  68. <input type="number" id="timers" min="1" value="1" style="cursor: pointer; width: 50px; font-size: 20px; border-radius: 5px; ">
  69. <button id="closeBtn" style="margin-left: 10px;font-size: 15px; width: 60px; cursor: pointer; height: 30px; margin-right: 10px; border: none; background-color: #e7a754; color: #fff;">close</button>
  70. </div>
  71. </div>
  72. </div>
  73. `;
  74.  
  75. // Box functions
  76. function addBox() {
  77. document.body.appendChild(popupContainer);
  78. }
  79.  
  80. function hiddenBox() {
  81. popupContainer.style.display = "none"; // 隐藏 box 而不是删除
  82. }
  83.  
  84. function showBox() {
  85. popupContainer.style.display = "block"; // 显示box
  86. }
  87.  
  88. // Watching target Element
  89. const checkForElement = () => {
  90. const targetElement = document.querySelector(targetSelector);
  91. if (targetElement) {
  92. console.log("已出现");
  93. // addBox();
  94. observer.disconnect();
  95. addBox();
  96. targetElement.insertAdjacentHTML(
  97. "beforebegin",
  98. `<div id="customButton" style="margin-top: 30px; width:200px; cursor: pointer; color: gray; text-align: center;">_____</div>`
  99. );
  100.  
  101. const button = document.getElementById("customButton");
  102. button.addEventListener("click", () => {
  103. if (
  104. document.getElementById("popupContainer") &&
  105. popupContainer.style.display === "block"
  106. ) {
  107. hiddenBox();
  108. } else if (
  109. document.getElementById("popupContainer") &&
  110. popupContainer.style.display === "none"
  111. ) {
  112. showBox();
  113. }
  114. });
  115.  
  116. const executeBtn = document.getElementById("executeBtn");
  117. const stopBtn = document.getElementById("stopBtn");
  118. const closeBtn = document.getElementById("closeBtn");
  119. const clearAll = document.getElementById("clearAll");
  120. function clearTheInterval() {
  121. clearInterval(intervalId);
  122. runFlag = false;
  123. executeBtn.style.cursor = "pointer";
  124. }
  125. // Button function
  126. executeBtn.addEventListener("click", () => {
  127. codeTextArea = document.getElementById("CodeTextarea").value;
  128. let codeFunction = new Function(codeTextArea); // Use codeTextArea
  129. let executionCount = 0;
  130. const loopCount = parseInt(
  131. document.getElementById("loopCount").value,
  132. 10
  133. );
  134. const loopTimer =
  135. parseInt(document.getElementById("timers").value, 10) * 1000;
  136. if (runFlag === true) {
  137. console.log("别重复");
  138. return 0;
  139. }
  140. runFlag = true;
  141.  
  142. executeBtn.style.cursor = "not-allowed";
  143. intervalId = setInterval(() => {
  144. if (executionCount < loopCount) {
  145. try {
  146. codeFunction();
  147. successfulCount++;
  148. executionCount++;
  149. } catch (error) {
  150. console.error(`执行出错: ${error.message}`);
  151. }
  152. } else {
  153. clearTheInterval();
  154. alert("fetch执行已完成");
  155. }
  156. }, loopTimer); // Use getRandomTime() here
  157. });
  158.  
  159. stopBtn.addEventListener("click", () => {
  160. clearTheInterval();
  161. alert("fetch已停止");
  162. });
  163.  
  164. closeBtn.addEventListener("click", () => {
  165. hiddenBox(); // Hide the box
  166. });
  167.  
  168. clearAll.addEventListener("click", () => {
  169. console.log("yes");
  170. clearTheInterval();
  171. alert("fetch已停止和清空");
  172. codeTextArea = ""; // 清空代码变量
  173. document.getElementById("CodeTextarea").value = ""; // 清空文本区域
  174. });
  175. }
  176. };
  177.  
  178. // Run observer to watch for element
  179. const observer = new MutationObserver(checkForElement);
  180.  
  181. // Start observing
  182. observer.observe(document.body, {
  183. childList: true,
  184. subtree: true, // Observe all child nodes
  185. });
  186. })();

QingJ © 2025

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