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:35:23
  5. * @Description:
  6. */
  7.  
  8. // ==UserScript==
  9. // @name fbtools
  10. // @namespace npm/vite-plugin-monkey
  11. // @version 0.0.1
  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.  
  66. const adClassName = "x8t9es0 x1fvot60 xxio538 x1heor9g xuxw1ft x6ikm8r x10wlt62 xlyipyv x1h4wwuj x1pd3egz xeuugli";
  67. const fushenText = "申请复审";
  68. const btnClass = "_43rm";
  69. const submitText = "提交";
  70. const okText = "确定";
  71.  
  72. const time_waitfor_fushen = 7000;
  73. const time_waitfor_submit = 2000;
  74. const time_waitfor_ok = 5000;
  75. const time_waitfor_next = 2000;
  76.  
  77. let clickInterval = null;
  78. let totalClickTimes = 0;
  79. let adClickIndex = 0;
  80. let adsElements = [];
  81.  
  82. window.onload = function () {
  83. console.log("页面加载完------- DOMContentLoaded")
  84.  
  85. setTimeout(function () {
  86. setInterval(createAutoFuShenButton, 1000);
  87. }, 1000);
  88. }
  89.  
  90. //传进复审按钮
  91. function createAutoFuShenButton() {
  92. const existingButton = document.getElementById('autoFuShenButton');
  93.  
  94. if (!existingButton) {
  95.  
  96. const outerDiv = document.querySelector('.x78zum5.xdmi676.x193iq5w.x6ikm8r.x10wlt62.x1n2onr6.x8t9es0.x1fvot60.xo1l8bm.xxio538');
  97.  
  98. if (outerDiv) {
  99. // 创建按钮元素
  100. const autoFuShenButton = document.createElement('button');
  101. autoFuShenButton.textContent = '自动复审';
  102. autoFuShenButton.id = 'autoFuShenButton';
  103. autoFuShenButton.style.backgroundColor = 'green';
  104. autoFuShenButton.style.fontSize = 'larger';
  105. autoFuShenButton.style.color = 'white';
  106.  
  107. autoFuShenButton.addEventListener("click", () => {
  108. console.log("开始自动复审");
  109. adsElements = getAdsElements();
  110. adClickIndex = 0;
  111. start();
  112. });
  113. // 将按钮添加到div中
  114. outerDiv.appendChild(autoFuShenButton);
  115. }
  116. }
  117. }
  118.  
  119.  
  120. //找到所有广告选项
  121. function getAdsElements() {
  122. const imageElements = document.querySelectorAll('i.img');
  123. let ads = [];
  124. imageElements.forEach((element) => {
  125. const backgroundImage = element.style.backgroundImage;
  126. const backgroundPosition = element.style.backgroundPosition;
  127.  
  128. if (backgroundImage === `url("${targetBackgroundImage}")` &&
  129. backgroundPosition === targetBackgroundPosition) {
  130. ads.push(element);
  131. }
  132. });
  133. console.log("找出的元素个数 --- " + ads.length)
  134. return ads
  135. }
  136.  
  137. //找到复审按钮并点击
  138. function clickFuShenBtn() {
  139. const elements = document.getElementsByClassName(adClassName);
  140. let elFushenBtn = null
  141. for (let element of elements) {
  142. if (element.textContent === fushenText) {
  143. elFushenBtn = element;
  144. // element.click();
  145. break; // Click the first matching element and then stop the loop
  146. }
  147. }
  148. if (totalClickTimes > elements.length + 5) {
  149. console.log("自动复审结束");
  150. return
  151. }
  152. console.log("点击次数-- " + totalClickTimes + " 广告个数 -- " + elements.length);
  153. totalClickTimes++;
  154. if (elFushenBtn != null) {
  155. console.log("点击复审");
  156. elFushenBtn.click();
  157. setTimeout(function () {
  158. clickSubmitButton();
  159. }, time_waitfor_submit);
  160. } else {
  161. console.log("没有找到复审按钮,中断本次任务");
  162. start();
  163. }
  164.  
  165. }
  166.  
  167. //找到提交按钮并点击
  168. function clickSubmitButton() {
  169. const buttons = document.getElementsByClassName(btnClass);
  170. let subBtn = null;
  171. for (let button of buttons) {
  172. if (button.textContent.trim() === submitText) {
  173. console.log("点击提交------");
  174. subBtn = button
  175. break;
  176. }
  177. }
  178. console.log("subBtn ----- " + subBtn);
  179. if (subBtn != null) {
  180. subBtn.click();
  181. setTimeout(function () {
  182. clickOKButton();
  183. }, time_waitfor_ok);
  184. }
  185. }
  186.  
  187. //找到ok按钮并点击
  188. function clickOKButton() {
  189. const buttons = document.getElementsByClassName(btnClass);
  190. let okBtn = null;
  191. for (let button of buttons) {
  192. if (button.textContent.trim() === okText) {
  193. console.log("点击确定------");
  194. okBtn = button
  195. break; // Click the first matching button and then stop the loop
  196. }
  197. }
  198. if (okBtn != null) {
  199. okBtn.click();
  200. }
  201. }
  202.  
  203. function clickAd() {
  204. if (adClickIndex < adsElements.length) {
  205. adsElements[adClickIndex].click();
  206. adClickIndex++;
  207.  
  208. setTimeout(() => {
  209. clickFuShenBtn();
  210. }, time_waitfor_fushen);
  211. } else {
  212. clearInterval(clickInterval);
  213. console.log("All matching elements clicked.");
  214. }
  215. }
  216.  
  217. function start() {
  218. // 在调用 start 函数之前先清除之前的间隔器
  219. if (clickInterval !== null) {
  220. clearInterval(clickInterval);
  221. clickInterval = null;
  222. }
  223. clickAd();
  224.  
  225. let time = time_waitfor_fushen + time_waitfor_submit + time_waitfor_ok + time_waitfor_next;
  226. clickInterval = setInterval(() => {
  227. clickAd();
  228. }, time);
  229. }