Facebook autoclick

Automatic facebook poke. Clicks on poke back every second.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Facebook autoclick
// @namespace    http://github.com/and3k5
// @version      2025-04-28
// @description  Automatic facebook poke. Clicks on poke back every second.
// @homepageURL  https://github.com/and3k5/auto-facebook-poke
// @supportURL   https://github.com/and3k5/auto-facebook-poke/issues
// @copyright    2025 And3k5
// @author       And3k5
// @match        https://www.facebook.com/pokes*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    "use strict";
    const button = document
        .evaluate(
            "//body//*//span[text()[contains(.,'Pokes')]]",
            document.body,
            null,
            XPathResult.FIRST_ORDERED_NODE_TYPE,
            null
        )
        .singleNodeValue.appendChild(document.createElement("button"));
    button.textContent = "_";
    button.type = "button";
    button.style.fontSize = "12pt";
    button.style.verticalAlign = "baseline";
    button.style.overflow = "visible";
    button.style.borderRadius = "50px";
    button.style.margin = "6px";
    button.style.marginLeft = "20px";
    button.style.cursor = "pointer";

    const spinner = button.appendChild(document.createElement("span"));
    spinner.textContent = "|";
    const animation = spinner.animate(
        [
            { transform: "rotate(0)" },
            { transform: "rotate(360deg)" },
        ],
        {
            duration: 1000,
            iterations: 1,
        }
    );

    let intervalId = null;
    const pokeBack = () =>
        document
            .evaluate(
                "//*[text()[contains(.,'Poke Back')]]",
                document.body,
                null,
                XPathResult.FIRST_ORDERED_NODE_TYPE,
                null
            )
            .singleNodeValue?.click();
    const setActiveState = () => {
        button.childNodes[0].textContent = "Stop auto poke";
        spinner.style.display = "inline-block";
    };
    const start = () => {
        if (intervalId != null) return;
        intervalId = setInterval(() => {
            pokeBack();
            animation.currentTime = 0;
        }, 1000);
        setActiveState();
    };
    const setIdleState = () => {
        button.childNodes[0].textContent = "Start auto poke";
        spinner.style.display = "none";
    };
    const stop = () => {
        if (intervalId == null) return;
        clearInterval(intervalId);
        intervalId = null;
        setIdleState();
    };
    setIdleState();
    button.addEventListener("click", () => {
        if (intervalId == null) return start();
        else stop();
    });
})();