Premium Revive Request

Harasses someone from HHU to revive you

当前为 2021-07-28 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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
}