Move Torn Start Fight Button

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

目前為 2023-03-30 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    });
})();