fbtools

run admin tools

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