Universign Отключение загрузки PDF - PullRequest
0 голосов
/ 12 февраля 2020

Примечание. Код, который я написал, не отшлифован, он предназначен только для создания прототипов, поэтому, пожалуйста, извините, если у меня есть какие-либо плохие практики, и исправьте меня, если я это сделаю! Спасибо.

Как отключить или удалить кнопку загрузки в форме подписи Universign?

У меня есть форма, встроенная в такой фрейм.

<iframe src="https://app.universign.com/sig/sign/(form id goes here)"  sandbox='allow-scripts allow-same-origin

Я написал скрипт для управления и использования cors -where API для получения всех необходимых файлов, таких как css файлы, сценарии и т. Д. c.

И я создал iframe на моей собственной странице, чтобы обойти CORS.

Проблема в том, что они используют WebPack и Angular, если я не ошибаюсь, и они создают страницу с JavaScript на go. Пока они его строят, им присваивается baseUrl , который равен http://app.universign.com/sig/, и я попытался добавить прокси-сервер CORS ( cors -where ) перед baseUrl для каждой функции, но она все еще не работает. Они выбирают json объекты для определения некоторых конфигураций через запрос POST.

Как я могу обойти это и сделать этот iframe редактируемым, я наткнулся на эту стену и мне нужно кое-что подумать, чтобы преодолеть это. Любая помощь приветствуется.

Обратите внимание, что мне удалось получить css и js, поместив их в iframe. Единственная оставшаяся проблема - сторона JavaScript, где она вытягивает конфигурации.

Код, который я написал:

<html>

<head>
<title></title>
<style>
    * {
        margin: 0 padding:0
    }

    body {
        margin: 0;
        padding: 0;
        text-align: center
    }

    #hold_my_iframe {
        padding: 0px;
        margin: 0 auto;
        width: 100%;
        height: 100%
    }
</style>
</head>

<body>


<table border=0 cellspacing=0 cellpadding=0 id="hold_my_iframe"
    sandbox="allow-forms allow-popups allow-scripts allow-same-origin">

    <iframe id="frame" src="javascript:void(0)" style="height: 80%; width: 60%;"></iframe>

</table>

<!-- This paragraph is used to display the source code of their main.js, which has the beginUrl variable -->
<p id="paragraph"></p>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
    integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script>
    (function ($) {

        function getIndicesOf(searchStr, str, caseSensitive) {
            var searchStrLen = searchStr.length;
            if (searchStrLen == 0) {
                return [];
            }
            var startIndex = 0, index, indices = [];
            if (!caseSensitive) {
                str = str.toLowerCase();
                searchStr = searchStr.toLowerCase();
            }
            while ((index = str.indexOf(searchStr, startIndex)) > -1) {
                indices.push(index);
                startIndex = index + searchStrLen;
            }
            return indices;
        }

        var frame = $("#frame");

        var htmlDoc;
        var htmlWrapper = $(document.createElement("html"))[0];
        var url = "https://app.universign.com/sig/";
        var cssLocations = [];
        var jsLocations = [];
        $.ajax({

            url: "http://cors-anywhere.herokuapp.com/https://app.universign.com/sig/sign/3b362bc3-5aba-40bd-96cd-6c2e1254410b",
            method: "GET",

            success: function (data) {
                htmlDoc = $(data);
                console.log(htmlDoc);
                htmlDoc.each(function (index, el) {
                    if ($(el).is("base")) {
                        // Setting up the base URL, this is used by href and src attributes to fetch images etc. 
                        // It basically specifies where the data should be pulled from

                        $(el).attr("href", "https://app.universign.com/sig/");
                    }
                    if ($(el).is("link")) {
                        var attribute = $(el).attr("href");

                        if (attribute !== "assets/favicon.ico" && attribute !== undefined && attribute !== null) {
                            cssLocations.push(attribute);
                        }
                    } else if ($(el).is("script")) {
                        var attribute = $(el).attr("src");

                        if (attribute !== undefined && attribute !== null) {
                            jsLocations.push(attribute);
                        }
                    }
                });
            },

            async: false,

        });

        cssLocations.reverse();
        jsLocations.reverse();

        console.log(htmlDoc);
        cssLocations.forEach(function (el) {
            console.log(el)
            $.ajax(
                {
                    url: "https://cors-anywhere.herokuapp.com/https://app.universign.com/sig/" + el,
                    method: "GET",

                    success: function (data) {
                        htmlDoc.splice(11, 0, $.parseHTML("<style>" + data + "</style>")[0]);
                        console.log(htmlDoc);
                    },
                    async: false,
                });
        });

        var shouldI = true;
        jsLocations.forEach(function (el) {
            console.log(el);
            $.ajax(
                {
                    url: "https://cors-anywhere.herokuapp.com/https://app.universign.com/sig/" + el,
                    method: "GET",

                    success: function (data) {
                        var indices = getIndicesOf("baseUrl +", data, true);
                        console.log(indices);
                        indices.forEach(function(el){
                        if(shouldI){
                            var endData = data.slice(0, indices[0]) + "'https://cors-anywhere.herokuapp.com/' +" + data.slice(indices[0], data.length);
                            $("#paragraph").html(endData);
                            shouldI = false;

                            data = endData;
                            }
                        });
                        htmlDoc.splice(19, 0, $("<script>" + data + "</" + "script>")[0]);
                        console.log(htmlDoc)
                    },
                    async: false,
                })
        });

        htmlDoc.each(function (index, el) {
            if (el !== null && el !== undefined) {
                htmlWrapper.appendChild(el);
            }
        });

        frame.attr("srcdoc", htmlWrapper.innerHTML);
    })(jQuery)



</script>
</body>

</html>

Вы можете найти их исходный код здесь: Источник

...