Ortenskung hack / script 1.6

Automates crime

当前为 2025-09-18 提交的版本,查看 最新版本

// ==UserScript==
// @name         Ortenskung hack / script 1.6 
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Automates crime
// @match        https://www.ortenskung.com/en/*
// @grant        none
// ==/UserScript==



(function() {
    'use strict';

    // --- KEEP ALIVE CODE STARTS HERE ---

    // 1. Heartbeat: keeps JS engine awake
    setInterval(() => {
        console.log('Heartbeat: tab still active');
    }, 30000); // 30 seconds

    // 2. Silent audio: prevents tab suspension in some browsers
    try {
        const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
        const oscillator = audioCtx.createOscillator();
        oscillator.frequency.value = 0; // near silent
        oscillator.connect(audioCtx.destination);
        oscillator.start();
    } catch (err) {
        console.log('Audio context failed', err);
    }

    // --- KEEP ALIVE CODE ENDS HERE ---

    // your existing game automation code below
})();

function showYourGUI() {
  console.log('GUI shown');
}

function performAction() {
  console.log('Action performed because timers are ready');
}

(function() {
    'use strict';

    let running = false;   // tracks if automation is active
    let timer = null;      // holds setTimeout so we can cancel it
    let selectedCrimeId = 1; // default crime ID

    // ------------------ Create GUI ------------------
    const panel = document.createElement('div');
    panel.style.position = 'fixed';
    panel.style.top = '20px';
    panel.style.right = '20px';
    panel.style.background = '#333';
    panel.style.color = '#fff';
    panel.style.padding = '10px';
    panel.style.borderRadius = '8px';
    panel.style.zIndex = '9999';
    panel.style.fontFamily = 'sans-serif';
    panel.innerHTML = `
        <strong>Crime Bot</strong><br>
        <label for="crimeIdSelect">Crime ID:</label>
        <select id="crimeIdSelect" style="margin-top:5px; margin-bottom:5px;">
            ${Array.from({length:30}, (_,i)=>i+1)
                   .map(id => `<option value="${id}" ${id===1?'selected':''}>${id}</option>`).join('')}
        </select><br>
        <button id="crimeToggleBtn">Start</button>
    `;
    document.body.appendChild(panel);

    // Elements
    const toggleBtn = document.getElementById('crimeToggleBtn');
    const crimeIdSelect = document.getElementById('crimeIdSelect');

    // Dropdown change
    crimeIdSelect.addEventListener('change', () => {
        selectedCrimeId = parseInt(crimeIdSelect.value, 10);
        console.log('Selected crime ID:', selectedCrimeId);
    });

    // Start/Stop toggle
    toggleBtn.addEventListener('click', () => {
        running = !running;
        toggleBtn.textContent = running ? 'Stop' : 'Start';
        if (running) performNeighborhoodCrime();
        else if (timer) clearTimeout(timer);
    });

    // ------------------ Helper ------------------
    function waitForElement(selector, timeout = 5000) {
        return new Promise((resolve, reject) => {
            const interval = 100;
            let elapsed = 0;
            const timer = setInterval(() => {
                const el = document.querySelector(selector);
                if (el) {
                    clearInterval(timer);
                    resolve(el);
                }
                elapsed += interval;
                if (elapsed >= timeout) {
                    clearInterval(timer);
                    reject('Element not found: ' + selector);
                }
            }, interval);
        });
    }

    // ------------------ Main Loop ------------------
// ------------------ Main Loop ------------------
async function performNeighborhoodCrime() {
    if (!running) return; // bail if stopped

    try {
        // Step 0: Check timers
        const timerEl = document.querySelector('#my_timers > div.val');
        if (!timerEl) {
            console.log('No timer element found. Retrying in 5s...');
            timer = setTimeout(performNeighborhoodCrime, 5000);
            return;
        }

        const m = timerEl.textContent.trim().match(/^(\d+)\s*\/\s*(\d+)$/);
        if (!m) {
            console.log('Timer text not in n/n format. Retrying in 5s...');
            timer = setTimeout(performNeighborhoodCrime, 5000);
            return;
        }

        const used = parseInt(m[1], 10);
        const total = parseInt(m[2], 10);
        const available = total - used;
        console.log(`Timers used: ${used} / ${total}, Available: ${available}`);

        // Step 1: If no timers available, wait and retry
        if (available === 0) {
            console.log('No timers available. Waiting 5s...');
            timer = setTimeout(performNeighborhoodCrime, 5000);
            return; // Skip everything else
        }

        // Step 2: Only open crime GUI if timers are available
        if (!document.querySelector('#go_crimes_dialog')) {
            const crimeDialogBtn = document.querySelector('#go_crimes');
            if (crimeDialogBtn) crimeDialogBtn.click();
        }

        // Step 3: Click "Neighborhood" only if not already in it
        const neighborhoodBtn = Array.from(document.querySelectorAll('.crimes_button'))
                                     .find(el => el.textContent.trim() === "Neighborhood");
        if (neighborhoodBtn && !document.querySelector('#neighborhood_crimes')) {
            neighborhoodBtn.click();
        }

        // Step 4: Commit selected crime if ready
        const commitBtn = Array.from(document.querySelectorAll('.crime_button_small'))
                               .find(el => el.getAttribute('onclick')?.includes(`'id':'${selectedCrimeId}'`));
        if (!commitBtn) {
            console.log(`Crime button ID ${selectedCrimeId} not ready. Waiting 5s...`);
            timer = setTimeout(performNeighborhoodCrime, 5000);
            return;
        }

        commitBtn.click();

        // Step 5: Close notification after committing crime
        setTimeout(() => {
            const notifBtn = document.querySelector('.button.first');
            if (notifBtn) notifBtn.click();
        }, 1000);

        // Step 6: Wait 4s before next iteration
        timer = setTimeout(performNeighborhoodCrime, 4000);

    } catch (err) {
        console.log('Error in automation:', err);
        timer = setTimeout(performNeighborhoodCrime, 5000);
    }
}


})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址