Fight Button Position Adjuster

Adjusts the position of the "Join Fight" button

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Fight Button Position Adjuster
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license MIT
// @description  Adjusts the position of the "Join Fight" button
// @match        https://www.torn.com/loader.php?sid=attack&user2ID*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const adjustButtonPosition = () => {
        // Find the button using the exact classes from your HTML
        const button = document.querySelector('button.torn-btn.btn___RxE8_.silver[type="submit"]');
        console.log('Button found:', button);

        if (button) {
            console.log('Button text:', button.textContent.trim());

            if (button.textContent.trim() === "Join fight") {
                console.log('Join Fight button detected');

                // Use the exact class name from your CSS selector
                const dialogDiv = document.querySelector('.dialog___Q0GdI');
                console.log('Dialog div found:', dialogDiv);

                if (dialogDiv) {
                    // Apply the style and verify it was applied
                    dialogDiv.setAttribute('style', 'margin-top: 260px !important');
                    console.log('Current dialog style:', dialogDiv.getAttribute('style'));

                    // Double check if style was applied
                    const computedStyle = window.getComputedStyle(dialogDiv);
                    console.log('Computed margin-top:', computedStyle.marginTop);
                }
            }
        }
    };

    // Create a more specific mutation observer
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            // Check if the mutation involves our target elements
            if (mutation.target.classList &&
                (mutation.target.classList.contains('dialog___Q0GdI') ||
                 mutation.target.classList.contains('btn___RxE8_'))) {
                adjustButtonPosition();
            }
        });
    });

    // Observe specific elements if they exist
    const startObserving = () => {
        const targetNode = document.querySelector('.playerWindow___aDeDI');
        if (targetNode) {
            observer.observe(targetNode, {
                childList: true,
                subtree: true,
                attributes: true,
                characterData: true,
                attributeFilter: ['class', 'style']
            });
            console.log('Observer started');
        }
    };

    // Initial setup
    const init = () => {
        console.log('Script initializing...');
        adjustButtonPosition();
        startObserving();
    };

    // Run on page load
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }

    // Backup interval check
    setInterval(adjustButtonPosition, 1000);
})();