Facebook-yian

Facebook一键脚本,支持点赞、移除推荐,并根据好友数量条件手动控制页面。提供UI按钮以控制开关,状态跨页面持久化保存,开关状态UI美化。

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/490096/1345708/Facebook-yian.js

  1. // ==UserScript==
  2. // @name Facebook狗推专用
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.2.2
  5. // @description Facebook一键脚本,支持点赞、移除推荐,并根据好友数量条件手动控制页面。提供UI按钮以控制开关,状态跨页面持久化保存,开关状态UI美化。
  6. // @author 亦安
  7. // @match https://www.facebook.com/*
  8. // @grant none
  9. // @downloadURL https://update.greasyfork.org/scripts/490096/Facebook%E7%8B%97%E6%8E%A8%E4%B8%93%E7%94%A8.user.js
  10. // @updateURL https://update.greasyfork.org/scripts/490096/Facebook%E7%8B%97%E6%8E%A8%E4%B8%93%E7%94%A8.meta.js
  11. // ==/UserScript==
  12.  
  13.  
  14.  
  15. (function () {
  16. "use strict";
  17.  
  18. // 读取初始状态
  19. let isChecking = localStorage.getItem("fb-friendCheckEnabled") === "true";
  20. let checkInterval;
  21.  
  22. const settings = {
  23. likeButton: {
  24. text: "一键点赞",
  25. bottom: "50px",
  26. action: likeAction,
  27. },
  28. removeButton: {
  29. text: "移除推荐",
  30. bottom: "100px",
  31. action: removeRecommendations,
  32. },
  33. listPullupButton: {
  34. text: "一键列表上拉",
  35. bottom: "150px",
  36. action: listPullupAction,
  37. },
  38. };
  39.  
  40. function toggleFriendCheck() {
  41. isChecking = !isChecking;
  42. localStorage.setItem("fb-friendCheckEnabled", isChecking.toString());
  43. updateButtonState();
  44. manageFriendCheck();
  45. }
  46.  
  47. function updateButtonState() {
  48. const button = document.getElementById("fb-enhanced-checkFriendButton");
  49. if (button) {
  50. button.textContent = isChecking ? "停止检查好友数量" : "开始检查好友数量";
  51. }
  52. }
  53.  
  54. function manageFriendCheck() {
  55. if (isChecking) {
  56. startFriendCheck();
  57. } else {
  58. if (checkInterval) clearInterval(checkInterval);
  59. }
  60. }
  61.  
  62. function startFriendCheck() {
  63. if (checkInterval) clearInterval(checkInterval);
  64. checkInterval = setInterval(checkFriends, 500);
  65. }
  66.  
  67. function checkFriends() {
  68. const links = document.querySelectorAll("a");
  69. for (let link of links) {
  70. if (link.textContent.includes("位好友")) {
  71. const friendCount = parseInt(link.textContent.split(" ")[0].replace(/,/g, ""), 10);
  72. if (friendCount < 10 || friendCount > 1000) {
  73. window.close();
  74. return;
  75. }
  76. }
  77. }
  78. }
  79.  
  80. function createEnhancedButton() {
  81. let button = document.createElement("button");
  82. button.id = "fb-enhanced-checkFriendButton";
  83. button.textContent = isChecking ? "停止检查好友数量" : "开始检查好友数量";
  84. button.style = "position: fixed; bottom: 200px; right: 20px; z-index: 10000; padding: 10px 15px; font-size: 16px; border: none; border-radius: 5px; color: white; cursor: pointer; background-color: #4267B2;";
  85. button.onclick = toggleFriendCheck;
  86. document.body.appendChild(button);
  87. }
  88.  
  89. function createButton({ text, bottom, action }) {
  90. let btn = document.createElement("button");
  91. btn.textContent = text;
  92. btn.style = `position: fixed; bottom: ${bottom}; right: 20px; z-index: 10000; padding: 10px 15px; font-size: 16px; border: none; border-radius: 5px; color: white; cursor: pointer; background-color: #4267B2;`;
  93. btn.addEventListener("click", action);
  94. document.body.appendChild(btn);
  95. return btn;
  96. }
  97.  
  98. // 以下为代码2中的其他功能实现
  99. function likeAction() {
  100. const likeButtons = Array.from(
  101. document.querySelectorAll('div[aria-label="赞"][role="button"]'),
  102. );
  103. const numberOfLikes = Math.floor(Math.random() * 8) + 3;
  104. for (let i = 0; i < numberOfLikes; i++) {
  105. const randomIndex = Math.floor(Math.random() * likeButtons.length);
  106. const buttonToClick = likeButtons[randomIndex];
  107. if (buttonToClick) {
  108. setTimeout(
  109. () => buttonToClick.click(),
  110. Math.random() * (2000 - 1000) + 1000,
  111. );
  112. likeButtons.splice(randomIndex, 1);
  113. }
  114. }
  115. }
  116.  
  117. function removeRecommendations() {
  118. setInterval(() => {
  119. const buttons = document.querySelectorAll('div[role="none"]');
  120. buttons.forEach(function (button) {
  121. if (
  122. button.innerText.includes("移除") ||
  123. button.innerText.includes("删除")
  124. ) {
  125. button.click();
  126. }
  127. });
  128. }, 1000);
  129. }
  130. function listPullupAction() {
  131. const targetClassName =
  132. "x6s0dn4 xkh2ocl x1q0q8m5 x1qhh985 xu3j5b3 xcfux6l x26u7qi xm0m39n x13fuv20 x972fbf x9f619 x78zum5 x1q0g3np x1iyjqo2 xs83m0k x1qughib xat24cr x11i5rnm x1mh8g0r xdj266r xexx8yu x1n2onr6 x1ja2u2z";
  133. const elements = document.querySelectorAll(
  134. `div.${targetClassName.replace(/\s/g, ".")}`,
  135. );
  136. const friendLinks = [];
  137. elements.forEach((element) => {
  138. if (element.textContent.includes("添加好友")) {
  139. const link = element.querySelector("a");
  140. if (link && link.href) {
  141. friendLinks.push(link.href);
  142. }
  143. }
  144. });
  145.  
  146. function openLinksInBatches(links, batchSize, interval) {
  147. let index = 0;
  148. function openBatch() {
  149. const batch = links.slice(index, index + batchSize);
  150. batch.forEach((link) => window.open(link, "_blank"));
  151. index += batchSize;
  152. if (index < links.length) {
  153. setTimeout(openBatch, interval);
  154. }
  155. }
  156. openBatch();
  157. }
  158. openLinksInBatches(friendLinks, 10, 20000);
  159. }
  160.  
  161. function initialize() {
  162. Object.values(settings).forEach((setting) => {
  163. createButton(setting);
  164. });
  165. createEnhancedButton(); // 创建增强检查好友数量的按钮
  166. updateButtonState();
  167. manageFriendCheck();
  168. }
  169.  
  170. initialize();
  171. })();