Torn: Gimme beers + Empty Blood Bag

Gimme beers and empty blood bags!

// ==UserScript==
// @name           Torn: Gimme beers + Empty Blood Bag
// @namespace      lugburz.gimme_beers
// @version        0.1.4
// @description    Gimme beers and empty blood bags!
// @author         Lugburz, zstorm [2268511]
// @match          https://www.torn.com/shops.php?step=bitsnbobs*
// @match          https://www.torn.com/shops.php?step=pharmacy*
// @grant          none
// @icon           https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @license         MIT
// ==/UserScript==

//====================UPDATE:===============================
// 0.1.4  Add another buttons at Pharmacy to buy Empty Blood Bag.
// 0.1.3  Adapt the script from lugburz.gimme_beers.
//========================================================


function addBtnBeer() {
    if ($('div.content-title > h4').size() > 0 && $('#buyBeerBtn').size() < 1) {
        const button = `<button id="buyBeerBtn" style="color: var(--default-blue-color); cursor: pointer; margin-right: 0;">Buy Beers</button>
                        <span id="buyBeerResult" style="font-size: 12px; font-weight: 100;"></span>`;
        $('div.content-title > h4').append(button);
        $('#buyBeerBtn').on('click', async () => {
            $('#buyBeerResult').text('');
            await getAction({
                type: 'post',
                action: 'shops.php',
                data: {
                    step: 'buyShopItem',
                    ID: 180,
                    amount: 100,
                    shoparea: 103
                },
                success: (str) => {
                    try {
                        const msg = JSON.parse(str);
                        $('#buyBeerResult').html(msg.text).css('color', msg.success ? 'green' : 'red');
                    } catch (e) {
                        console.log(e);
                    }
                }
            });
        });
    }
};

function addBtnEmptyBloodBag() {
    if ($('div.content-title > h4').size() > 0 && $('#buyEBBBtn').size() < 1) {
        const btn = `<button id="buyEBBBtn" style="color: var(--default-blue-color); cursor: pointer; margin-right: 0;">Buy Empty Blood Bag</button>
                        <span id="buyEBBResult" style="font-size: 12px; font-weight: 100;"></span>`;
        $('div.content-title > h4').append(btn);
        $('#buyEBBBtn').on('click', async () => {
            $('#buyEBBResult').text('');
            await getAction({
                type: 'post',
                action: 'shops.php',
                data: {
                    step: 'buyShopItem',
                    ID: 731,
                    amount: 100,
                    shoparea: 110
                },
                success: (str) => {
                    try {
                        const msg = JSON.parse(str);
                        $('#buyEBBResult').html(msg.text).css('color', msg.success ? 'green' : 'red');
                    } catch (e) {
                        console.log(e);
                    }
                }
            });
        });
    }
};

(function() {
    'use strict';

    const currentUrl = window.location.href;

    if (currentUrl.startsWith('https://www.torn.com/shops.php?step=bitsnbobs')) {
        addBtnBeer();
    } else if (currentUrl.startsWith('https://www.torn.com/shops.php?step=pharmacy')) {
        addBtnEmptyBloodBag();
    }
})();