MafiaOrder Auto Crime

Automatically commit a crime in MafiaOrderwith

当前为 2023-11-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         MafiaOrder Auto Crime
// @namespace    Phantom Script
// @version      0.1
// @description  Automatically commit a crime in MafiaOrderwith
// @author       ErrorNullTag
// @match        https://www.mafiaorder.com/*
// @grant        none
// ==/UserScript==


// Guide

//Hello everyone, this is the guide in the code that'll walk you through setting up each crime level, and it's timer to change as you go.
//Crimes are based on their Energy Value, so I've put a comment in front of the Energy Value so you can see it, likewise each level of crime has a timer between usage, I'll comment it too for you.
//Good luck, have fun, and Break The Status Quo!
// - Phantom

(function() {
    'use strict';

    const $ = window.jQuery;

    let buttonClicked = false;
    let lastCSFR = "";
    const CSFR_CHANGE_INTERVAL = 3000;

    async function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    async function commitCrimeJQuery() {
        if (buttonClicked) {
            return;
        }

        const crimeBtn = $('a.btn.btn-xl.btn-default:contains("Commit Crime"):contains("10 Energy")'); // Here my Children is the Energy, below is "10 Energy" for the first crime, change it's value to your current crime for usage.
        const isInJail = $('.alert-danger:contains("sent you to jail")').length > 0;

        if (isInJail) {
            console.log("You are in jail, waiting for 30 seconds...");
            await sleep(30000); //                                         30 seconds Jailtime Timer, Can be altered as this is a global jailtime check, seperate from just crime, Wink Wink.
            console.log("Jail time is up.");
            window.history.back(); // Go back to the previous page
        } else {
                console.log(`Waiting for 5 seconds...`);
                await sleep(5000); //                                      5 second Crime Timer, Should be altered to be two to three seconds longer than whichever crime's timer is set.
            }

            if (crimeBtn.length > 0 && crimeBtn.attr('href').includes('_CSFR=')) {
                buttonClicked = true;
                crimeBtn.click();
                buttonClicked = false;
            }
        }

    function getCurrentCSFR() {
        const url = window.location.href;
        const match = url.match(/_CSFR=([a-f0-9]+)/i);
        if (match) {
            return match[1];
        }
        return "";
    }

    const observer = new MutationObserver(async (mutationsList, observer) => {
        for (const mutation of mutationsList) {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                const currentCSFR = getCurrentCSFR();
                if (currentCSFR !== lastCSFR) {
                    lastCSFR = currentCSFR;
                    setTimeout(() => {
                        commitCrimeJQuery();
                    }, CSFR_CHANGE_INTERVAL);
                }
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

    $(document).ready(() => {
        commitCrimeJQuery();
    });

})();