Fill Bank Vault

Gives you several monetary values to pre-fill the property vault fields

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Fill Bank Vault
// @namespace    https://greatest.deepsurf.us/en/scripts/386032-fill-bank-vault
// @version      1.0
// @description  Gives you several monetary values to pre-fill the property vault fields
// @author       cryosis7 [926640]
// @match        *.torn.com/properties.php*
// ==/UserScript==

'use strict'

const amounts = ['1m', '5m', '10m', '20m', '30m'];

setObserver();

/**
 * Watches the properties page and loads the buttons when the vault is visible.
 */
function setObserver() {
    if (document.querySelector('#properties-page-wrap'))
        new MutationObserver(mutations => mutations.forEach(mutation => {
            console.log(mutations)
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('property-option')) {
                    console.log(node);
                    addButtons()
                }
            })
        })).observe(document.querySelector('#properties-page-wrap'), { childList: true })
}

/**
 * Adds the buttons to the dom and a listener on the withdraw/deposit buttons.
 */
function addButtons() {
    if (!document.querySelectorAll('.preset-btn').length) {
        let presetTitle = elementCreator('div', { 'class': 'title-black top-round m-top10', 'role': 'heading', 'aria-level': '5' }, 'Vault Presets')
        let presetButtons = elementCreator('div', { 'class': 'cont-gray bottom-round' })
        amounts.forEach(x => presetButtons.appendChild(elementCreator('button', { 'class': 'torn-btn preset-btn', 'style': 'margin:5px' }, '$' + x)));
        let presetContainer = elementCreator('div', { 'class': 'preset-container-wrap' }, null, [presetTitle, presetButtons]);

        presetContainer.querySelectorAll('.preset-btn').forEach(button => button.addEventListener('click', () => {
            Array.from(document.querySelectorAll('.input-money-group'))
                .filter(inputFields => inputFields.querySelector('[name="withdraw"]') || inputFields.querySelector('[name="deposit"]'))
                .forEach(element => {
                    element.querySelector(['input[type="text"]']).value = button.innerText.replace('$', '');
                    element.querySelector(['input[type="text"]']).click();
                })
        }));

        let vaultNode = document.querySelector('div.vault-wrap');
        vaultNode.parentNode.insertBefore(presetContainer, vaultNode.previousElementSibling);
    }
}

/**
 * Creates an HTML element according to the given parameters
 * 
 * @param {String} type The HTML type to create ('div')
 * @param {Object} attributes Attributes to set {'class': 'wrapper'}
 * @param {String} innerHtml Inner text/html
 * @param {Array} innerElements Any elements to insert into the new node
 */
function elementCreator(type = 'div', attributes, innerHtml, innerElements) {
    let el = document.createElement(type);
    for (let attribute in attributes)
        el.setAttribute(attribute, attributes[attribute])
    if (innerHtml) el.innerHTML = innerHtml;
    for (let index in innerElements)
        el.appendChild(innerElements[index]);
    return el
}