[Brick-Kill] Postfarmer

Sends automated messages on Brick Hill forums.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// discord.gg/JjszyaD63A

// ==UserScript==
// @name         [Brick-Kill] Postfarmer
// @version      6
// @description  Sends automated messages on Brick Hill forums.
// @author       Spacekiller
// @match        *://www.brick-hill.com/*
// @icon         https://www.brick-hill.com/favicon.ico
// @license      MIT
// @namespace    bhpostfarmer
// ==/UserScript==

(function() {
    'use strict';

    /*-    SETTINGS    -*/
    const config = {
        post: {
            title: "put stuff here", // Title of the post.
            body: "put stuff\nhere", // Text of the post.
            categoryID: 2, // Forum category ID, Off-Topic is 2 for example.
            randomCategory: false, // Set to true to enable random category selection.
            interval: 60, // Don't go below 60 seconds, cause that's the limit.
            enabled: true // True or false to enable post spam.
        },
        reply: {
            body: "put stuff\nhere", // Text of the reply.
            postID: 100000, // ID of the forum thread you want to target.
            interval: 15, // Don't go below 15 seconds, cause that's the limit.
            enabled: false // True or false to enable reply spam.
        },
        comment: {
            comment: "put stuff here", // Text of the comment.
            commentable_id: 375378, // ID of a shop item or a game.
            interval: 30, // Don't go below 30 seconds, cause that's the limit.
            polymorphic_type: 1,
            enabled: false // True or false to enable comment spam.
        },
        message: {
            title: "put stuff here", // Title of the message.
            reply: "put stuff\nhere", // Text of the post.
            recipient: 4787, // ID of the user you want to target.
            interval: 30, // Don't go below 30 seconds, cause that's the limit.
            enabled: false // True or false to enable message spam.
        }
    };
    /*-                -*/

    function getRandomCategoryID() {
        return Math.floor(Math.random() * 14) + 1; // Generates a random number between 1 and 14
    }

    function sendRequest(url, method, body) {
        const token = document.querySelector('input[name="_token"]').value;
        const requestBody = new FormData();
        for (const key in body) {
            requestBody.append(key, body[key]);
        }
        requestBody.append('_token', token);

        return fetch(url, {
            method: method,
            body: requestBody
        });
    }

    function handleRequest(config, sendFunction) {
        if (!config.enabled) return;
        sendFunction();
        const nextExecution = Date.now() + config.interval * 1000;
        const delay = nextExecution - Date.now();
        setTimeout(() => handleRequest(config, sendFunction), delay);
    }

    function handlePostRequest() {
        let categoryID = config.post.randomCategory ? getRandomCategoryID() : config.post.categoryID;
        const url = `https://www.brick-hill.com/forum/${categoryID}/create`;
        const body = {
            title: config.post.title,
            body: config.post.body
        };
        sendRequest(url, 'POST', body);
    }

    function handleReplyRequest() {
        const url = `https://www.brick-hill.com/forum/reply/${config.reply.postID}`;
        const body = {
            body: config.reply.body
        };
        sendRequest(url, 'POST', body);
    }

    function handleCommentRequest() {
        const url = `https://www.brick-hill.com/comments/create`;
        const body = {
            comment: config.comment.comment,
            commentable_id: config.comment.commentable_id,
            polymorphic_type: config.comment.polymorphic_type
        };
        sendRequest(url, 'POST', body);
    }

    function handleMessageRequest() {
        const url = `https://www.brick-hill.com/messages`;
        const body = {
            title: config.message.title,
            recipient: config.message.recipient,
            reply: config.message.reply
        };
        sendRequest(url, 'POST', body);
    }

    handleRequest(config.post, handlePostRequest);
    handleRequest(config.reply, handleReplyRequest);
    handleRequest(config.comment, handleCommentRequest);
    handleRequest(config.message, handleMessageRequest);

})();