Facebook狗推专用

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

目前為 2024-03-18 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/490096/1344912/Facebook%E7%8B%97%E6%8E%A8%E4%B8%93%E7%94%A8.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Facebook狗推专用
// @namespace    http://tampermonkey.net/
// @version      2.1.1
// @description  Facebook一键脚本,支持点赞、移除推荐,并根据好友数量条件自动关闭页面。提供UI按钮以控制开关,状态跨页面持久化保存。
// @author       亦安
// @match        https://www.facebook.com/*
// @grant        none
// ==/UserScript==

(function () {
  "use strict";
  const buttonStyle =
    "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;";

  const likeButton = document.createElement("button");
  likeButton.textContent = "一键点赞";
  likeButton.style = buttonStyle;
  document.body.appendChild(likeButton);

  const removeButton = document.createElement("button");
  removeButton.textContent = "移除推荐";
  removeButton.style = buttonStyle + "bottom: 50px;";
  document.body.appendChild(removeButton);

  const checkButton = document.createElement("button");
  checkButton.textContent = "开始检查好友数量";
  checkButton.style = buttonStyle + "bottom: 150px;";
  document.body.appendChild(checkButton);

  let isChecking = false;
  let intervalId = null;

  const savedState = localStorage.getItem("fb-friendCheckEnabled");
  if (savedState === "true") {
    toggleChecking();
  }

  checkButton.addEventListener("click", toggleChecking);

  function toggleChecking() {
    isChecking = !isChecking;
    localStorage.setItem("fb-friendCheckEnabled", isChecking);
    checkButton.textContent = isChecking
      ? "停止检查好友数量"
      : "开始检查好友数量";

    if (isChecking) {
      startChecking();
    } else if (intervalId) {
      clearInterval(intervalId);
      intervalId = null;
    }
  }

  function startChecking() {
    intervalId = setInterval(() => {
      let foundValidLink = false;
      const links = document.querySelectorAll("a");
      links.forEach((link) => {
        if (link.textContent.includes("位好友")) {
          foundValidLink = true;
          const friendCountStr = link.textContent
            .split(" ")[0]
            .replace(/,/g, "");
          const friendCount = parseInt(friendCountStr, 10);
          if (friendCount < 1 || friendCount > 1000) {
            window.close();
          }
        }
      });
      if (!foundValidLink) {
        window.close();
      }
    }, 500);
  }

  likeButton.addEventListener("click", function () {
    const likeButtons = Array.from(
      document.querySelectorAll('div[aria-label="赞"][role="button"]'),
    );
    const numberOfLikes = Math.floor(Math.random() * 8) + 3;

    for (let i = 0; i < numberOfLikes; i++) {
      const randomIndex = Math.floor(Math.random() * likeButtons.length);
      const buttonToClick = likeButtons[randomIndex];
      if (buttonToClick) {
        setTimeout(
          () => buttonToClick.click(),
          Math.random() * (1500 - 500) + 500,
        );
        likeButtons.splice(randomIndex, 1);
      }
    }
  });

  removeButton.addEventListener("click", function () {
    setInterval(() => {
      const buttons = document.querySelectorAll('div[role="none"]');
      buttons.forEach(function (button) {
        if (
          button.innerText.includes("移除") ||
          button.innerText.includes("删除")
        ) {
          button.click();
        }
      });
    }, 1000);
  });
})();