Facebook狗推专用

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

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

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/490096/1345012/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.5
// @description  Facebook一键脚本,支持点赞、移除推荐,并根据好友数量条件手动控制页面。提供UI按钮以控制开关,状态跨页面持久化保存,开关状态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; color: white; cursor: pointer;";
  const activeButtonColor = "#34A853";
  const inactiveButtonColor = "#4267B2";

  const likeButton = document.createElement("button");
  likeButton.textContent = "一键点赞";
  likeButton.style = buttonStyle + "background-color: #4267B2; bottom: 50px;";
  document.body.appendChild(likeButton);

  const removeButton = document.createElement("button");
  removeButton.textContent = "移除推荐";
  removeButton.style =
    buttonStyle + "background-color: #4267B2; bottom: 100px;";
  document.body.appendChild(removeButton);

  const listpullup = document.createElement("button");
  listpullup.textContent = "一键列表上拉";
  listpullup.style =
    buttonStyle + "background-color: #4267B2; bottom: 150px;";
  document.body.appendChild(listpullup);

  const checkButton = document.createElement("button");
  checkButton.style = buttonStyle + "bottom: 200px;";
  document.body.appendChild(checkButton);

  let isChecking = false;
  let intervalId = null;

  function initializeButtonState() {
    isChecking = localStorage.getItem("fb-friendCheckEnabled") === "true";
    checkButton.textContent = isChecking
      ? "停止检查好友数量"
      : "开始检查好友数量";
    checkButton.style.backgroundColor = isChecking
      ? activeButtonColor
      : inactiveButtonColor;
    if (isChecking) {
      startChecking();
    }
  }

  checkButton.addEventListener("click", toggleChecking);

  function toggleChecking() {
    isChecking = !isChecking;
    localStorage.setItem("fb-friendCheckEnabled", isChecking);
    checkButton.textContent = isChecking
      ? "停止检查好友数量"
      : "开始检查好友数量";
    checkButton.style.backgroundColor = isChecking
      ? activeButtonColor
      : inactiveButtonColor;
    if (isChecking) {
      startChecking();
    } else {
      stopChecking();
    }
  }

  function startChecking() {
    if (intervalId) return;
    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) {
            localStorage.setItem("fb-friendCheckEnabled", isChecking);
            window.close();
          }
        }
      });
      if (!foundValidLink) {
        localStorage.setItem("fb-friendCheckEnabled", isChecking);
        window.close();
      }
    }, 500);
  }

  function stopChecking() {
    if (intervalId) {
      clearInterval(intervalId);
      intervalId = null;
    }
  }

  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() * (2000 - 1000) + 1000,
        );
        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);
  });

  listpullup.addEventListener("click", function () {
    const targetClassName =
      "x6s0dn4 xkh2ocl x1q0q8m5 x1qhh985 xu3j5b3 xcfux6l x26u7qi xm0m39n x13fuv20 x972fbf x9f619 x78zum5 x1q0g3np x1iyjqo2 xs83m0k x1qughib xat24cr x11i5rnm x1mh8g0r xdj266r x2lwn1j xeuugli x18d9i69 x4uap5 xkhd6sd xexx8yu x1n2onr6 x1ja2u2z";
    const elements = document.querySelectorAll(
      `div.${targetClassName.replace(/\s/g, ".")}`,
    );
    elements.forEach((element) => {
      if (element.textContent.includes("添加好友")) {
        const link = element.querySelector("a");
        if (link && link.href) {
          window.open(link.href, "_blank");
        }
      }
    });
  });

  initializeButtonState();
})();