fbtools

run admin tools

目前为 2023-08-26 提交的版本。查看 最新版本

  1. /*
  2. * @Author: xx
  3. * @Date: 2023-08-25 14:41:40
  4. * @LastEditTime: 2023-08-26 11:49:39
  5. * @Description:
  6. */
  7.  
  8. // ==UserScript==
  9. // @name fbtools
  10. // @namespace npm/vite-plugin-monkey
  11. // @version 0.0.2
  12. // @author monkey
  13. // @description run admin tools
  14. // @license MIT
  15. // @icon https://cdn3.iconfinder.com/data/icons/picons-social/57/46-facebook-512.png
  16. // @match https://adsmanager.facebook.com/adsmanager/manage/*
  17. // @grant GM.addElement
  18. // @grant GM.addStyle
  19. // @grant GM.deleteValue
  20. // @grant GM.getResourceUrl
  21. // @grant GM.getValue
  22. // @grant GM.info
  23. // @grant GM.listValues
  24. // @grant GM.notification
  25. // @grant GM.openInTab
  26. // @grant GM.registerMenuCommand
  27. // @grant GM.setClipboard
  28. // @grant GM.setValue
  29. // @grant GM.xmlHttpRequest
  30. // @grant GM_addElement
  31. // @grant GM_addStyle
  32. // @grant GM_addValueChangeListener
  33. // @grant GM_cookie
  34. // @grant GM_deleteValue
  35. // @grant GM_download
  36. // @grant GM_getResourceText
  37. // @grant GM_getResourceURL
  38. // @grant GM_getTab
  39. // @grant GM_getTabs
  40. // @grant GM_getValue
  41. // @grant GM_info
  42. // @grant GM_listValues
  43. // @grant GM_log
  44. // @grant GM_notification
  45. // @grant GM_openInTab
  46. // @grant GM_registerMenuCommand
  47. // @grant GM_removeValueChangeListener
  48. // @grant GM_saveTab
  49. // @grant GM_setClipboard
  50. // @grant GM_setValue
  51. // @grant GM_unregisterMenuCommand
  52. // @grant GM_webRequest
  53. // @grant GM_xmlhttpRequest
  54. // @run-at document-start
  55. // @grant unsafeWindow
  56. // @grant window.close
  57. // @grant window.focus
  58. // @grant window.onurlchange
  59. // ==/UserScript==
  60.  
  61. console.log("油猴脚本----")
  62.  
  63. const targetBackgroundImage = 'https://static.xx.fbcdn.net/rsrc.php/v3/yU/r/SLLGWtYOBPG.png';
  64. const targetBackgroundPosition = '0px -355px';
  65. const targetBackgroundPosition2 = '0px -370px';
  66.  
  67. const adClassName = "x8t9es0 x1fvot60 xxio538 x1heor9g xuxw1ft x6ikm8r x10wlt62 xlyipyv x1h4wwuj x1pd3egz xeuugli";
  68. const fushenText = "申请复审";
  69. const btnClass = "_43rm";
  70. const submitText = "提交";
  71. const okText = "确定";
  72.  
  73. const time_waitfor_fushen = 7000;
  74. const time_waitfor_submit = 2000;
  75. const time_waitfor_ok = 5000;
  76. const time_waitfor_next = 2000;
  77.  
  78. let clickInterval = null;
  79. let totalClickTimes = 0;
  80. let adClickIndex = 0;
  81. let adsElements = [];
  82.  
  83. window.onload = function () {
  84. console.log("页面加载完------- DOMContentLoaded")
  85.  
  86. setTimeout(function () {
  87. setInterval(createAutoFuShenButton, 1000);
  88. }, 1000);
  89. }
  90.  
  91. //传进复审按钮
  92. function createAutoFuShenButton() {
  93. const existingButton = document.getElementById('autoFuShenButton');
  94.  
  95. if (!existingButton) {
  96.  
  97. const outerDiv = document.querySelector('.x78zum5.xdmi676.x193iq5w.x6ikm8r.x10wlt62.x1n2onr6.x8t9es0.x1fvot60.xo1l8bm.xxio538');
  98.  
  99. if (outerDiv) {
  100. // 创建按钮元素
  101. const autoFuShenButton = document.createElement('button');
  102. autoFuShenButton.textContent = '自动复审';
  103. autoFuShenButton.id = 'autoFuShenButton';
  104. autoFuShenButton.style.backgroundColor = 'green';
  105. autoFuShenButton.style.fontSize = 'larger';
  106. autoFuShenButton.style.color = 'white';
  107.  
  108. autoFuShenButton.addEventListener("click", () => {
  109. console.log("开始自动复审");
  110. adsElements = getAdsElements();
  111. adClickIndex = 0;
  112. start();
  113. });
  114. // 将按钮添加到div中
  115. outerDiv.appendChild(autoFuShenButton);
  116. }
  117. }
  118. }
  119.  
  120.  
  121. //找到所有广告选项
  122. function getAdsElements() {
  123. const imageElements = document.querySelectorAll('i.img');
  124. let ads = [];
  125. imageElements.forEach((element) => {
  126. const backgroundImage = element.style.backgroundImage;
  127. const backgroundPosition = element.style.backgroundPosition;
  128.  
  129. if (backgroundImage === `url("${targetBackgroundImage}")` &&
  130. (backgroundPosition === targetBackgroundPosition || backgroundPosition === targetBackgroundPosition2)) {
  131. ads.push(element);
  132. }
  133. });
  134. console.log("找出的元素个数 --- " + ads.length)
  135. return ads
  136. }
  137.  
  138. //找到复审按钮并点击
  139. function clickFuShenBtn() {
  140. const elements = document.getElementsByClassName(adClassName);
  141. let elFushenBtn = null
  142. for (let element of elements) {
  143. if (element.textContent === fushenText) {
  144. elFushenBtn = element;
  145. // element.click();
  146. break; // Click the first matching element and then stop the loop
  147. }
  148. }
  149. if (totalClickTimes > elements.length + 5) {
  150. console.log("自动复审结束");
  151. return
  152. }
  153. console.log("点击次数-- " + totalClickTimes + " 广告个数 -- " + elements.length);
  154. totalClickTimes++;
  155. if (elFushenBtn != null) {
  156. console.log("点击复审");
  157. elFushenBtn.click();
  158. setTimeout(function () {
  159. clickSubmitButton();
  160. }, time_waitfor_submit);
  161. } else {
  162. console.log("没有找到复审按钮,中断本次任务");
  163. start();
  164. }
  165.  
  166. }
  167.  
  168. //找到提交按钮并点击
  169. function clickSubmitButton() {
  170. const buttons = document.getElementsByClassName(btnClass);
  171. let subBtn = null;
  172. for (let button of buttons) {
  173. if (button.textContent.trim() === submitText) {
  174. console.log("点击提交------");
  175. subBtn = button
  176. break;
  177. }
  178. }
  179. console.log("subBtn ----- " + subBtn);
  180. if (subBtn != null) {
  181. subBtn.click();
  182. setTimeout(function () {
  183. clickOKButton();
  184. }, time_waitfor_ok);
  185. }
  186. }
  187.  
  188. //找到ok按钮并点击
  189. function clickOKButton() {
  190. const buttons = document.getElementsByClassName(btnClass);
  191. let okBtn = null;
  192. for (let button of buttons) {
  193. if (button.textContent.trim() === okText) {
  194. console.log("点击确定------");
  195. okBtn = button
  196. break; // Click the first matching button and then stop the loop
  197. }
  198. }
  199. if (okBtn != null) {
  200. okBtn.click();
  201. }
  202. }
  203.  
  204. function clickAd() {
  205. if (adClickIndex < adsElements.length) {
  206. adsElements[adClickIndex].click();
  207. adClickIndex++;
  208.  
  209. setTimeout(() => {
  210. clickFuShenBtn();
  211. }, time_waitfor_fushen);
  212. } else {
  213. clearInterval(clickInterval);
  214. console.log("All matching elements clicked.");
  215. }
  216. }
  217.  
  218. function start() {
  219. // 在调用 start 函数之前先清除之前的间隔器
  220. if (clickInterval !== null) {
  221. clearInterval(clickInterval);
  222. clickInterval = null;
  223. }
  224. clickAd();
  225.  
  226. let time = time_waitfor_fushen + time_waitfor_submit + time_waitfor_ok + time_waitfor_next;
  227. clickInterval = setInterval(() => {
  228. clickAd();
  229. }, time);
  230. }