1function webjack_form(config) {
2 'use strict';
3
4 config.params = config.params || [];
5 config.cookies = config.cookies || [];
6
7 const url = 'https://webjack.ru/webhooks/form/' + config.webhook + '/';
8
9 const params = JSON.parse(localStorage.getItem('__wj_params') || '{}');
10 const urlParams = new URLSearchParams(window.location.search.substring(1));
11 config.params.forEach(name => {
12 const value = urlParams.get(name);
13 if(value) params[name] = value;
14 });
15 localStorage.setItem('__wj_params', JSON.stringify(params));
16
17 function getParams() {
18 const r = {};
19 config.params.forEach(name => {
20 r[name] = params[name];
21 });
22 return r;
23 }
24
25 function getCookies() {
26 const cookies = new Map((document.cookie || '').split(';').map(item => {
27 const delim = item.indexOf('=');
28 const key = item.substring(0, delim).trim();
29 const value = decodeURIComponent(item.substring(delim + 1));
30 return [key, value];
31 }));
32 const r = {};
33 config.cookies.forEach(name => {
34 r[name] = cookies.get(name);
35 });
36 return r;
37 }
38
39 window.addEventListener('submit', function(event) {
40 const formdata = new FormData(event.target);
...
</html>