WoWnik / Ссылки на Биллинг

// ==UserScript==
// @name Ссылки на Биллинг
// @namespace http://tampermonkey.net/
// @version 0.1
// @author You
// @license MIT
// @include *://*/Tester/*
// @include *://*/tester/*
// @include *://*/Tester
// @include *://*/tester
// @require https://unpkg.com/babel-standalone@6/babel.min.js
// @require https://unpkg.com/react@16/umd/react.development.js
// @require https://unpkg.com/react-dom@16/umd/react-dom.development.js
// @grant none
// ==/UserScript==


(function () {
    'use strict';
    var partnerDomain = 'https://partner-' + window.location.hostname;
    var siteDomain = window.location.origin;
    if (window.location.origin == 'https://www.moedelo.org') {
        partnerDomain = 'https://mdpartner.org';
    }
    if (window.location.hostname == 'localhost') {
        partnerDomain = 'http://localhost:12592';
        siteDomain = 'http://localhost:8080';
    }


    var userLogin = document.getElementsByTagName("span")[1].innerText;
    var regex = new RegExp("([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})");
    if (userLogin.match(regex)) {
        var encodedUserLogin = encodeURIComponent(userLogin);
//alert(window.location.hostname + "\n" + window.location.origin);


        var messageBox = document.getElementById('message');


        var billing1 = document.createElement('a');
        billing1.href = partnerDomain + '/billing/Default.aspx?login=' + encodedUserLogin;
        billing1.innerText = 'Ссылка на Биллинг 1.0';
        messageBox.appendChild(billing1);


        messageBox.appendChild(document.createElement('br'));


        var billing2 = document.createElement('a');
        billing2.href = partnerDomain + '/New/Billing/CreateBill?login=' + encodedUserLogin;
        billing2.innerText = 'Выставить счёт';
        messageBox.appendChild(billing2);


        messageBox.appendChild(document.createElement('br'));


        var pb = document.createElement('a');
        pb.href = partnerDomain + '/New/Billing/CreateBillFromBackofficeBilling?client=' + encodedUserLogin;
        pb.innerText = 'Выставить счёт в продуктовом биллинге';
        messageBox.appendChild(pb);


        messageBox.appendChild(document.createElement('br'));


        var pay = document.createElement('a');
        pay.href = siteDomain + '/Pay';
        pay.innerText = 'Pay в ЛК';
        messageBox.appendChild(pay);


        messageBox.appendChild(document.createElement('br'));


        var marketplace = document.createElement('a');
        marketplace.href = siteDomain + '/Marketplace';
        marketplace.innerText = 'Marketplace';
        messageBox.appendChild(marketplace);
    }


// Создать дочернюю фирму
    var TesterEnding = ".web.tester@moedelo.org";

    function generateLogin() {
        var date = Date.now();
        return date + TesterEnding;
    }

    function createAffiliatedFirm(e) {
        e.preventDefault();
        e.stopPropagation();
        var url = '/AccountManagement/AccountBackend/CreateCompany';
        var attributes = {
            AdminName: "Company",
            AdminPatronymic: "Name",
            AdminSurname: "Affiliated",
            CompanyName: "Affiliated Company",
            Email: generateLogin(),
            Inn: "000000000000",
            LegalType: 2,
            Phone: "+71111111111",
            TaxitionSystemType: 1
        };
        var request = new XMLHttpRequest();
        var formData = new FormData();
        var entries = Object.entries(attributes);
        for (var i = 0; i < entries.length; i += 1) {
            formData.append(entries[i][0], entries[i][1]);
        }
        request.open('POST', url);
        request.onload = function () {
            document.location.reload();
            alert("Создана фирма с логином " + attributes.Email);
        };
        request.send(formData);
    }

//render
    const element = document.createElement("td");
    const parentDiv = Array.from(document.querySelectorAll("tr > td > div > a")).filter(function (item) {
        return item.firstChild.data === "Профессиональный аутсорсер"
    })[0].parentElement.parentElement.parentElement;
    parentDiv.appendChild(element);


    const e = React.createElement;
    const createAffiliatedFirmButton = e(
        "div",
        {},
        e(
            "a",
            {
                id: "createAffiliatedFirm",
                href: "#",
                onClick: createAffiliatedFirm
            },
            "Создать дочернюю фирму"
        )
    );


    ReactDOM.render(createAffiliatedFirmButton, element);
})();