Update builder.html
Browse files- builder.html +39 -248
    	
        builder.html
    CHANGED
    
    | @@ -1,258 +1,49 @@ | |
| 1 | 
             
            <!DOCTYPE html>
         | 
| 2 | 
             
            <html lang="en">
         | 
| 3 | 
             
            <head>
         | 
| 4 | 
            -
              <meta charset=" | 
| 5 | 
            -
              <title> | 
| 6 | 
            -
              <link rel="stylesheet" href="https:// | 
| 7 | 
            -
              <script src="https:// | 
| 8 | 
            -
              <script src="https:// | 
| 9 | 
            -
              <script src="https://unpkg.com/grapesjs-custom-code"></script>
         | 
| 10 | 
            -
              <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
         | 
| 11 | 
            -
              <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
         | 
| 12 | 
            -
              <style>
         | 
| 13 | 
            -
                /* Ваш существующий CSS */
         | 
| 14 | 
            -
                body, html {
         | 
| 15 | 
            -
                  height: 100%;
         | 
| 16 | 
            -
                  margin: 0;
         | 
| 17 | 
            -
                }
         | 
| 18 | 
            -
                .image-container {
         | 
| 19 | 
            -
                  display: flex;
         | 
| 20 | 
            -
                  justify-content: space-between;
         | 
| 21 | 
            -
                  margin-top: 20px; /* Поднятие картинок выше формы */
         | 
| 22 | 
            -
                }
         | 
| 23 | 
            -
                .image-container img {
         | 
| 24 | 
            -
                  width: 30%;
         | 
| 25 | 
            -
                  height: auto;
         | 
| 26 | 
            -
                  margin: 0 10px; /* Увеличение расстояния между картинками */
         | 
| 27 | 
            -
                }
         | 
| 28 | 
            -
                @media (max-width: 768px) {
         | 
| 29 | 
            -
                  .image-container {
         | 
| 30 | 
            -
                    flex-direction: column;
         | 
| 31 | 
            -
                  }
         | 
| 32 | 
            -
                  .image-container img {
         | 
| 33 | 
            -
                    width: 100%;
         | 
| 34 | 
            -
                    margin: 10px 0; /* Увеличение расстояния между картинками на мобильных устройствах */
         | 
| 35 | 
            -
                  }
         | 
| 36 | 
            -
                }
         | 
| 37 | 
            -
                /* Стили для контейнера управления */
         | 
| 38 | 
            -
                .controls-container {
         | 
| 39 | 
            -
                  background-color: #302f2f; /* Черный фон контейнера */
         | 
| 40 | 
            -
                  padding: 15px 0; /* Отступы сверху и снизу */
         | 
| 41 | 
            -
                  text-align: center; /* Выравнивание по центру */
         | 
| 42 | 
            -
                }
         | 
| 43 | 
            -
                .controls-container label,
         | 
| 44 | 
            -
                .controls-container button {
         | 
| 45 | 
            -
                  margin-left: 15px; /* Отступ слева */
         | 
| 46 | 
            -
                }
         | 
| 47 | 
            -
                /* Стили для кнопки "Скачать HTML" */
         | 
| 48 | 
            -
                #export-html {
         | 
| 49 | 
            -
                  background-color: #ccc; /* Серый фон кнопки */
         | 
| 50 | 
            -
                  color: #000; /* Черный цвет текста кнопки */
         | 
| 51 | 
            -
                  border: none;
         | 
| 52 | 
            -
                  padding: 10px 15px; /* Размер кнопки */
         | 
| 53 | 
            -
                  font-size: 16px; /* Размер текста кнопки */
         | 
| 54 | 
            -
                  cursor: pointer;
         | 
| 55 | 
            -
                  border-radius: 5px; /* Скругление углов */
         | 
| 56 | 
            -
                  transition: background-color 0.3s ease; /* Плавный переход при наведении */
         | 
| 57 | 
            -
                }
         | 
| 58 | 
            -
                #export-html:hover {
         | 
| 59 | 
            -
                  background-color: #bbb; /* Фон кнопки при наведении */
         | 
| 60 | 
            -
                }
         | 
| 61 | 
            -
                /* Стили для надписей возле галочек */
         | 
| 62 | 
            -
                .controls-container label {
         | 
| 63 | 
            -
                  color: #fff; /* Белый цвет текста */
         | 
| 64 | 
            -
                }
         | 
| 65 | 
            -
              </style>
         | 
| 66 | 
             
            </head>
         | 
| 67 | 
             
            <body>
         | 
| 68 | 
            -
              <div id=" | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
                   | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
                     | 
| 90 | 
            -
             | 
| 91 | 
            -
                 | 
| 92 | 
            -
             | 
| 93 | 
            -
                  .panel {
         | 
| 94 | 
            -
                    width: 90%;
         | 
| 95 | 
            -
                    max-width: 700px;
         | 
| 96 | 
            -
                    border-radius: 3px;
         | 
| 97 | 
            -
                    padding: 30px 20px;
         | 
| 98 | 
            -
                    margin: 150px auto 0px;
         | 
| 99 | 
            -
                    background-color: #d983a6;
         | 
| 100 | 
            -
                    box-shadow: 0px 3px 10px 0px rgba(0,0,0,0.25);
         | 
| 101 | 
            -
                    color: rgba(255,255,255,0.75);
         | 
| 102 | 
            -
                    font: caption;
         | 
| 103 | 
            -
                    font-weight: 100;
         | 
| 104 | 
            -
                    text-align: center;
         | 
| 105 | 
            -
                  }
         | 
| 106 | 
            -
                  .welcome {
         | 
| 107 | 
            -
                    text-align: center;
         | 
| 108 | 
            -
                    font-weight: 100;
         | 
| 109 | 
            -
                    margin: 0px;
         | 
| 110 | 
            -
                  }
         | 
| 111 | 
            -
                  .logo {
         | 
| 112 | 
            -
                    width: 70px;
         | 
| 113 | 
            -
                    height: 70px;
         | 
| 114 | 
            -
                    vertical-align: middle;
         | 
| 115 | 
            -
                    border-radius: 50%; /* Скругление углов для логотипа */
         | 
| 116 | 
            -
                  }
         | 
| 117 | 
            -
                  .big-title {
         | 
| 118 | 
            -
                    text-align: center;
         | 
| 119 | 
            -
                    font-size: 3.5rem;
         | 
| 120 | 
            -
                    margin: 15px 0;
         | 
| 121 | 
            -
                  }
         | 
| 122 | 
            -
                  .description {
         | 
| 123 | 
            -
                    text-align: justify;
         | 
| 124 | 
            -
                    font-size: 1rem;
         | 
| 125 | 
            -
                    line-height: 1.5rem;
         | 
| 126 | 
            -
                  }
         | 
| 127 | 
            -
                  .centered-form {
         | 
| 128 | 
            -
                    display: inline-block;
         | 
| 129 | 
            -
                    text-align: left;
         | 
| 130 | 
            -
                  }
         | 
| 131 | 
            -
                  .centered-form input {
         | 
| 132 | 
            -
                    display: block;
         | 
| 133 | 
            -
                    width: 100%;
         | 
| 134 | 
            -
                    margin-bottom: 10px;
         | 
| 135 | 
            -
                  }
         | 
| 136 | 
            -
                  .checkbox-label {
         | 
| 137 | 
            -
                    display: flex;
         | 
| 138 | 
            -
                    align-items: center;
         | 
| 139 | 
            -
                    margin-bottom: 10px;
         | 
| 140 | 
            -
                    padding: 0;
         | 
| 141 | 
            -
                  }
         | 
| 142 | 
            -
                  .checkbox-label input[type="checkbox"] {
         | 
| 143 | 
            -
                    margin: 0;
         | 
| 144 | 
            -
                    width: 100%;
         | 
| 145 | 
            -
                    height: 100%;
         | 
| 146 | 
            -
                    flex-basis: 0;
         | 
| 147 | 
            -
                    autocomplete: off;
         | 
| 148 | 
            -
                  }
         | 
| 149 | 
            -
                  .checkbox-label span {
         | 
| 150 | 
            -
                    margin-left: 15px; /* Добавление отступа справа */
         | 
| 151 | 
            -
                  }
         | 
| 152 | 
            -
                  .add-button {
         | 
| 153 | 
            -
                    display: block;
         | 
| 154 | 
            -
                    margin: 20px auto 0;
         | 
| 155 | 
            -
                    padding: 10px 20px;
         | 
| 156 | 
            -
                    font-size: 1rem;
         | 
| 157 | 
            -
                    color: #fff;
         | 
| 158 | 
            -
                    background-color: #007bff;
         | 
| 159 | 
            -
                    border: none;
         | 
| 160 | 
            -
                    border-radius: 5px;
         | 
| 161 | 
            -
                    cursor: pointer;
         | 
| 162 | 
            -
                  }
         | 
| 163 | 
            -
                </style>
         | 
| 164 | 
            -
              </div>
         | 
| 165 | 
            -
             | 
| 166 | 
            -
              <!-- Интерфейс для выбора скриптов -->
         | 
| 167 | 
            -
              <div class="controls-container">
         | 
| 168 | 
            -
                <label><input type="checkbox" id="script1-checkbox" value="https://example.com/your-additional-script1.js" checked> Соб. хост</label>
         | 
| 169 | 
            -
                <label><input type="checkbox" id="script2-checkbox" value="https://example.com/your-additional-script2.js"> ВК + АП</label>
         | 
| 170 | 
            -
                <label><input type="checkbox" id="script3-checkbox" value="https://example.com/your-additional-script3.js"> Виджет Тильда</label>
         | 
| 171 | 
            -
                <label><input type="checkbox" id="script4-checkbox" value="https://example.com/your-additional-script4.js"> Виджет Геткурс</label>
         | 
| 172 | 
            -
                <button id="add-custom-script">Добавить свой скрипт и скачать HTML</button>
         | 
| 173 | 
            -
              </div>
         | 
| 174 | 
            -
             | 
| 175 | 
            -
              <script type="text/javascript" src="https://huggingface.co/spaces/DMTuit/psy_vk/resolve/main/js/sav_html.js"></script>
         | 
| 176 | 
            -
             | 
| 177 | 
            -
              <script type="text/javascript">
         | 
| 178 | 
            -
                var editor = grapesjs.init({
         | 
| 179 | 
            -
                  showOffsets: 1,
         | 
| 180 | 
            -
                  noticeOnUnload: 0,
         | 
| 181 | 
            -
                  container: '#gjs',
         | 
| 182 | 
            -
                  height: '100%',
         | 
| 183 | 
            -
                  fromElement: true,
         | 
| 184 | 
            -
                  storageManager: { autoload: 0 },
         | 
| 185 | 
            -
                  plugins: ['grapesjs-plugin-forms', 'grapesjs-custom-code'],
         | 
| 186 | 
            -
                  pluginsOpts: {
         | 
| 187 | 
            -
                    'grapesjs-plugin-forms': {
         | 
| 188 | 
            -
                      // options
         | 
| 189 | 
            -
                    },
         | 
| 190 | 
            -
                    'grapesjs-custom-code': {
         | 
| 191 | 
            -
                      blockCustomCode: {
         | 
| 192 | 
            -
                        label: 'Custom Code',
         | 
| 193 | 
            -
                        category: 'Extra',
         | 
| 194 | 
            -
                        attributes: { class: 'fa fa-code' }
         | 
| 195 | 
            -
                      },
         | 
| 196 | 
            -
                      modalTitle: 'Insert your code',
         | 
| 197 | 
            -
                      buttonLabel: 'Save',
         | 
| 198 | 
            -
                      placeholderScript: '// Your JavaScript code here', // Плейсхолдер для скрипта
         | 
| 199 | 
            -
                      codeViewOptions: {
         | 
| 200 | 
            -
                        theme: 'hopscotch',
         | 
| 201 | 
            -
                        readOnly: 0
         | 
| 202 | 
            -
                      }
         | 
| 203 | 
            -
                    }
         | 
| 204 | 
            -
                  }
         | 
| 205 | 
            -
                });
         | 
| 206 | 
            -
             | 
| 207 | 
            -
                document.getElementById('add-custom-script').addEventListener('click', function() {
         | 
| 208 | 
            -
                  Swal.fire({
         | 
| 209 | 
            -
                    title: 'Добавить свой скрипт',
         | 
| 210 | 
            -
                    input: 'textarea',
         | 
| 211 | 
            -
                    inputPlaceholder: 'Введите ваш скрипт здесь...',
         | 
| 212 | 
            -
                    showCancelButton: true,
         | 
| 213 | 
            -
                    confirmButtonText: 'Сохранить и скачать',
         | 
| 214 | 
            -
                    cancelButtonText: 'Отмена',
         | 
| 215 | 
            -
                    inputValidator: (value) => {
         | 
| 216 | 
            -
                      if (!value) {
         | 
| 217 | 
            -
                        return 'Вы должны ввести скрипт!'
         | 
| 218 | 
            -
                      }
         | 
| 219 | 
            -
                    }
         | 
| 220 | 
            -
                  }).then((result) => {
         | 
| 221 | 
            -
                    if (result.isConfirmed) {
         | 
| 222 | 
            -
                      const script = `<script>${result.value}<\/script>`;
         | 
| 223 | 
            -
                      const htmlCode = editor.getHtml();
         | 
| 224 | 
            -
                      const newHtml = htmlCode + script;
         | 
| 225 | 
            -
                      editor.setComponents(newHtml);
         | 
| 226 | 
            -
             | 
| 227 | 
            -
                      // Скачивание HTML-файла с добавленным скриптом
         | 
| 228 | 
            -
                      const cssCode = editor.getCss();
         | 
| 229 | 
            -
                      const jsCode = editor.getJs();
         | 
| 230 | 
            -
             | 
| 231 | 
            -
                      const fullHtml = `
         | 
| 232 | 
            -
                        <!DOCTYPE html>
         | 
| 233 | 
            -
                        <html>
         | 
| 234 | 
            -
                        <head>
         | 
| 235 | 
            -
                          <style>${cssCode}</style>
         | 
| 236 | 
            -
                        </head>
         | 
| 237 | 
            -
                        <body>
         | 
| 238 | 
            -
                          ${newHtml}
         | 
| 239 | 
            -
                          <script>${jsCode}<\/script>
         | 
| 240 | 
            -
                        </body>
         | 
| 241 | 
            -
                        </html>
         | 
| 242 | 
            -
                      `;
         | 
| 243 | 
            -
             | 
| 244 | 
            -
                      const blob = new Blob([fullHtml], { type: 'text/html' });
         | 
| 245 | 
            -
                      const url = URL.createObjectURL(blob);
         | 
| 246 | 
            -
                      const a = document.createElement('a');
         | 
| 247 | 
            -
                      a.href = url;
         | 
| 248 | 
            -
                      a.download = 'page.html';
         | 
| 249 | 
            -
                      a.click();
         | 
| 250 | 
             
                    }
         | 
| 251 | 
             
                  });
         | 
| 252 | 
            -
                });
         | 
| 253 | 
            -
              </script>
         | 
| 254 | 
            -
             | 
| 255 | 
            -
              <!-- Функцию экспорта вынес в sav_html.js-->
         | 
| 256 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 257 | 
             
            </body>
         | 
| 258 | 
             
            </html>
         | 
|  | |
| 1 | 
             
            <!DOCTYPE html>
         | 
| 2 | 
             
            <html lang="en">
         | 
| 3 | 
             
            <head>
         | 
| 4 | 
            +
              <meta charset="UTF-8">
         | 
| 5 | 
            +
              <title>Telegram Bot Visual Editor</title>
         | 
| 6 | 
            +
              <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/drawflow/dist/drawflow.min.css">
         | 
| 7 | 
            +
              <script src="https://cdn.jsdelivr.net/npm/drawflow/dist/drawflow.min.js"></script>
         | 
| 8 | 
            +
              <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 9 | 
             
            </head>
         | 
| 10 | 
             
            <body>
         | 
| 11 | 
            +
              <div id="drawflow" style="width: 800px; height: 600px; border: 1px solid black;"></div>
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              <script>
         | 
| 14 | 
            +
                const id = document.getElementById("drawflow");
         | 
| 15 | 
            +
                const editor = new Drawflow(id);
         | 
| 16 | 
            +
                editor.start();
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                // Добавление узлов
         | 
| 19 | 
            +
                editor.addNode('StartCommand', 0, 1, 150, 300, 'telegram', { command: '/start', response: 'Привет! Я ваш бот.' });
         | 
| 20 | 
            +
                editor.addNode('EchoCommand', 0, 1, 400, 300, 'telegram', { response: '{{message}}' });
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                // Генерация и отправка кода на сервер
         | 
| 23 | 
            +
                function generateAndSendPythonCode() {
         | 
| 24 | 
            +
                  const nodes = editor.getNodes();
         | 
| 25 | 
            +
                  let code = '';
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  nodes.forEach(node => {
         | 
| 28 | 
            +
                    if (node.data.command) {
         | 
| 29 | 
            +
                      code += `def ${node.data.command.slice(1)}(update: Update, context: CallbackContext) -> None:\n`;
         | 
| 30 | 
            +
                      code += `    update.message.reply_text('${node.data.response}')\n`;
         | 
| 31 | 
            +
                      code += `\n`;
         | 
| 32 | 
            +
                    } else if (node.data.response) {
         | 
| 33 | 
            +
                      code += `def echo(update: Update, context: CallbackContext) -> None:\n`;
         | 
| 34 | 
            +
                      code += `    update.message.reply_text(update.message.text)\n`;
         | 
| 35 | 
            +
                      code += `\n`;
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 36 | 
             
                    }
         | 
| 37 | 
             
                  });
         | 
|  | |
|  | |
|  | |
|  | |
| 38 |  | 
| 39 | 
            +
                  axios.post('/execute', { command: '/start', code: code })
         | 
| 40 | 
            +
                    .then(response => {
         | 
| 41 | 
            +
                      console.log(response.data);
         | 
| 42 | 
            +
                    })
         | 
| 43 | 
            +
                    .catch(error => {
         | 
| 44 | 
            +
                      console.error(error);
         | 
| 45 | 
            +
                    });
         | 
| 46 | 
            +
                }
         | 
| 47 | 
            +
              </script>
         | 
| 48 | 
             
            </body>
         | 
| 49 | 
             
            </html>
         |