Facebook狗推专用

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

目前为 2024-03-18 提交的版本,查看 最新版本

此脚本不应直接安装,它是供其他脚本使用的外部库。如果你需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/490096/1344912/Facebook%E7%8B%97%E6%8E%A8%E4%B8%93%E7%94%A8.js

  1. // ==UserScript==
  2. // @name Facebook狗推专用
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.1.1
  5. // @description Facebook一键脚本,支持点赞、移除推荐,并根据好友数量条件自动关闭页面。提供UI按钮以控制开关,状态跨页面持久化保存。
  6. // @author 亦安
  7. // @match https://www.facebook.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. "use strict";
  13. const buttonStyle =
  14. "position: fixed; bottom: 100px; right: 20px; z-index: 10000; padding: 10px 15px; font-size: 16px; border: none; border-radius: 5px; background-color: #4267B2; color: white; cursor: pointer;";
  15.  
  16. const likeButton = document.createElement("button");
  17. likeButton.textContent = "一键点赞";
  18. likeButton.style = buttonStyle;
  19. document.body.appendChild(likeButton);
  20.  
  21. const removeButton = document.createElement("button");
  22. removeButton.textContent = "移除推荐";
  23. removeButton.style = buttonStyle + "bottom: 50px;";
  24. document.body.appendChild(removeButton);
  25.  
  26. const checkButton = document.createElement("button");
  27. checkButton.textContent = "开始检查好友数量";
  28. checkButton.style = buttonStyle + "bottom: 150px;";
  29. document.body.appendChild(checkButton);
  30.  
  31. let isChecking = false;
  32. let intervalId = null;
  33.  
  34. const savedState = localStorage.getItem("fb-friendCheckEnabled");
  35. if (savedState === "true") {
  36. toggleChecking();
  37. }
  38.  
  39. checkButton.addEventListener("click", toggleChecking);
  40.  
  41. function toggleChecking() {
  42. isChecking = !isChecking;
  43. localStorage.setItem("fb-friendCheckEnabled", isChecking);
  44. checkButton.textContent = isChecking
  45. ? "停止检查好友数量"
  46. : "开始检查好友数量";
  47.  
  48. if (isChecking) {
  49. startChecking();
  50. } else if (intervalId) {
  51. clearInterval(intervalId);
  52. intervalId = null;
  53. }
  54. }
  55.  
  56. function startChecking() {
  57. intervalId = setInterval(() => {
  58. let foundValidLink = false;
  59. const links = document.querySelectorAll("a");
  60. links.forEach((link) => {
  61. if (link.textContent.includes("位好友")) {
  62. foundValidLink = true;
  63. const friendCountStr = link.textContent
  64. .split(" ")[0]
  65. .replace(/,/g, "");
  66. const friendCount = parseInt(friendCountStr, 10);
  67. if (friendCount < 1 || friendCount > 1000) {
  68. window.close();
  69. }
  70. }
  71. });
  72. if (!foundValidLink) {
  73. window.close();
  74. }
  75. }, 500);
  76. }
  77.  
  78. likeButton.addEventListener("click", function () {
  79. const likeButtons = Array.from(
  80. document.querySelectorAll('div[aria-label="赞"][role="button"]'),
  81. );
  82. const numberOfLikes = Math.floor(Math.random() * 8) + 3;
  83.  
  84. for (let i = 0; i < numberOfLikes; i++) {
  85. const randomIndex = Math.floor(Math.random() * likeButtons.length);
  86. const buttonToClick = likeButtons[randomIndex];
  87. if (buttonToClick) {
  88. setTimeout(
  89. () => buttonToClick.click(),
  90. Math.random() * (1500 - 500) + 500,
  91. );
  92. likeButtons.splice(randomIndex, 1);
  93. }
  94. }
  95. });
  96.  
  97. removeButton.addEventListener("click", function () {
  98. setInterval(() => {
  99. const buttons = document.querySelectorAll('div[role="none"]');
  100. buttons.forEach(function (button) {
  101. if (
  102. button.innerText.includes("移除") ||
  103. button.innerText.includes("删除")
  104. ) {
  105. button.click();
  106. }
  107. });
  108. }, 1000);
  109. });
  110. })();