Premium Revive Request

Harasses someone from HHU to revive you

As of 2021-07-28. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Premium Revive Request
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Harasses someone from HHU to revive you
// @author       not Mavri [2402357]
// @match        https://www.torn.com/*
// @grant        GM.xmlHttpRequest
// @grant        GM_addStyle
// @homepage     https://mavriware.me
// @require     https://cdn.jsdelivr.net/npm/axios@~0.21.1/dist/axios.min.js
// @require     https://cdn.jsdelivr.net/npm/axios-userscript-adapter@~0.1.2/dist/axiosGmxhrAdapter.min.js
// ==/UserScript==


'use strict';

setTimeout(renderButton, 500);

axios.defaults.adapter = axiosGmxhrAdapter;


GM_addStyle(`
    .imp {
    box-shadow:inset 0px 1px 0px 0px #cf866c;
    background:linear-gradient(to bottom, #d0451b 5%, #bc3315 100%);
    background-color:#d0451b;
    border-radius:1em;
    border:1px solid #942911;
    display:inline-block;
    cursor:pointer;
    color:#ffffff;
    font-family:Arial;
    font-size:.75em;
    padding:.3em .5em;
    text-decoration:none;
    text-shadow:0px 1px 0px #854629;
    margin-bottom: .7em;
}
.imp:hover {
    background:linear-gradient(to bottom, #bc3315 5%, #d0451b 100%);
    background-color:#bc3315;
}
.imp:active {
    position:relative;
    top:1px;
}
` );

function renderButton() {
    if (!document.getElementById('imp-button')) {
        var sidebar = getSidebar()
        if (sidebar.statusIcons.icons.hospital) { // true if ape's in hospital
            let elem;
            if (sidebar.windowSize != 'mobile') {
                elem = document.querySelector('#barLife')
            }
            if (sidebar.windowSize == 'mobile') {
                elem = document.querySelector('.header-buttons-wrapper')
            }
            if (elem != null) {
                let html = `<a href="#" class="imp" id="imp-button">REVIVE ME</a>`
                elem.children[0].insertAdjacentHTML('beforebegin', html);
                const impButton = document.getElementById('imp-button');
                impButton.addEventListener('click', function () {
                    checkAndTransmit()
                });
            }
        }
    }
    setTimeout(renderButton, 500)
}

function checkAndTransmit() {

    let sidebarData = getSidebar()
    let pid = sidebarData.user.userID
    let name = sidebarData.user.name
    let faction = sidebarData.statusIcons.icons.faction.subtitle.split(' of ')[1];

    let hospitalIcon = sidebarData.statusIcons.icons.hospital
    if (hospitalIcon == null) {
        alert('You are not in the hospital!')
    } else {
        var obj = {
            "userID": pid,
            "userName": name,
            "factionName": faction,
            "source": source
        }

        let source = "IMPS"

        console.log(obj)
        var jsonString = JSON.stringify(obj);
        let url = `http://CornelEsteSlab.go.ro:3001/revive`
        axios({
            method: 'post',
            url: url,
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            data: nig
        });
        /* // ! Broken, don't bother
        GM.xmlHttpRequest({
            method: 'POST',
            url: url,
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            data: jsonString,
            onload: function (response) {
                if (response.status == '200') {
                    alert('Request sent :)')
                    console.log(response.response)
                } else {
                    //alert(JSON.parse(response.responseText).reason)
                    alert(response.responseText)
                }
            },
            onerror: function (error) {
                alert('Something is down, look in console and contact Mavri#0001 on Discord')
                console.log(error)
            }
        })
        */
    }
}

checkAndTransmit()

function getSidebar() {
    let key = Object.keys(sessionStorage).find(key => /sidebarData\d+/.test(key));
    let sidebarData = JSON.parse(sessionStorage.getItem(key))
    return sidebarData
}