Greasy Fork

Facebook一键脚本

Facebook一键脚本,目前支持点赞与移除推荐

目前为 2024-03-17 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.cloud/scripts/490096/1344515/Facebook%E4%B8%80%E9%94%AE%E8%84%9A%E6%9C%AC.js

// ==UserScript==
// @name         Facebook一键脚本
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Facebook一键脚本,目前支持点赞与移除推荐
// @author       亦安
// @match        https://www.facebook.com/*
// @grant        none
// ==/UserScript==

(function () {
  "use strict";
  const likeButton = document.createElement("button");
  likeButton.textContent = "一键点赞";
  likeButton.style =
    "position: fixed; bottom: 60px; right: 20px; z-index: 10000; padding: 10px; fontSize: 16px;";
  document.body.appendChild(likeButton);
  const removeButton = document.createElement("button");
  removeButton.textContent = "移除推荐";
  removeButton.style =
    "position: fixed; bottom: 20px; right: 20px; z-index: 10000; padding: 10px; fontSize: 16px;";
  document.body.appendChild(removeButton);
  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);
  });
})();