Move Torn Start Fight Button

Move Torn "Start Fight" Button on top of Primary Weapon

当前为 2023-03-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Move Torn Start Fight Button
// @namespace    https://github.com/0xymandias
// @version      0.1
// @description  Move Torn "Start Fight" Button on top of Primary Weapon
// @author       smokey_ [2492729]
// @match        https://www.torn.com/loader.php?*
// @license      WTFPL
// ==/UserScript==

// Copyright © 2031 smokey_ [2492729]. Email me @ <[email protected]>
// This work is free. You can redistribute it and/or modify it under the
// terms of the Do What The Fuck You Want To Public License, Version 2,
// as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.

(function() {
    'use strict';

    // function to move start fight button next to equipped weapon image
    function moveStartFightButton() {
        console.log('moveStartFightButton called');
        const startFightButton = document.querySelector('.torn-btn.btn___RxE8_.undefined.silver'); // start fight button
        const weaponImage = document.querySelector('.weaponImage___tUzwP img'); // equipped weapon image
        const weaponWrapper = document.querySelector('.weaponWrapper___h3buK'); // weapon wrapper element
        console.log('startFightButton', startFightButton);
        console.log('weaponImage', weaponImage);
        console.log('weaponWrapper', weaponWrapper);


        if (startFightButton && weaponImage && weaponWrapper) {
            console.log('all elements found');
            const buttonWrapper = document.createElement('div'); // create new div element
            buttonWrapper.classList.add('button-wrapper');
            buttonWrapper.appendChild(startFightButton); // append start fight button to new div element
            weaponWrapper.insertBefore(buttonWrapper, weaponImage.nextSibling); // insert new div element after equipped weapon image
            console.log('buttonWrapper', buttonWrapper);

            // Position the button wrapper over the weapon image
            buttonWrapper.style.position = 'absolute';
            buttonWrapper.style.top = weaponImage.offsetTop + 'px';
            buttonWrapper.style.left = '+15px'; // set left position to move it to the left
        }
    }

    window.addEventListener('load', function() {
        console.log('Page loaded');
        setTimeout(function() {
            moveStartFightButton();
            console.log('moveStartFightButton done');
        }, 1000);
    });
})();