Torn Custom Plane Image

Sets a custom plane image on the Torn Travel page.

当前为 2025-03-15 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Torn Custom Plane Image
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Sets a custom plane image on the Torn Travel page.
// @author       You
// @match        https://www.torn.com/page.php?sid=travel
// @match        https://www.torn.com/preferences.php
// @grant        GM_setValue
// @grant        GM_getValue
// @License MIT
// ==/UserScript==

(function() {
    'use strict';

    const defaultImage = "https://i.pinimg.com/originals/98/5e/ad/985ead90bd841958d2bb4b09ca60d123.gif";

    function replacePlaneImage() {
        const planeImage = document.querySelector('.planeImage___Kbn3b');
        if (!planeImage) return;

        const customImage = GM_getValue('permanentPlaneImage') || defaultImage;
        planeImage.src = customImage;

        // Center the image
        planeImage.style.position = 'absolute';
        planeImage.style.top = '50%';
        planeImage.style.left = '50%';
        planeImage.style.transform = 'translate(-50%, -50%)';
        planeImage.style.maxWidth = '778px';
        planeImage.style.maxHeight = '300px';
        planeImage.style.width = 'auto';
        planeImage.style.height = 'auto';
    }

    function addImageButton() {
        if (!window.location.href.startsWith("https://www.torn.com/preferences.php")) return;

        const imageButton = document.createElement('button');
        imageButton.textContent = 'Set Plane Image';
        imageButton.style.padding = '8px 12px';
        imageButton.style.margin = '5px';
        imageButton.style.cursor = 'pointer';
        imageButton.style.backgroundColor = '#3498db';
        imageButton.style.color = 'white';
        imageButton.style.border = 'none';
        imageButton.style.borderRadius = '3px';
        imageButton.style.fontSize = '14px';

        // Position the button on the right side of the screen
        imageButton.style.position = 'fixed';
        imageButton.style.top = '50%';
        imageButton.style.right = '20px'; // Adjust this value to change the distance from the right
        imageButton.style.transform = 'translateY(-50%)';
        imageButton.style.zIndex = '9999'; // Ensure it's above other elements

        imageButton.addEventListener('click', () => {
            const imageUrl = prompt("Please enter the image URL");
            if (imageUrl){
                GM_setValue('permanentPlaneImage', imageUrl);
                replacePlaneImage();
            }
        });

        document.body.appendChild(imageButton);
    }

    replacePlaneImage();
    addImageButton();

    const observer = new MutationObserver(mutations => {
        replacePlaneImage();
    });

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