Pochta form 22

autocomplete recipient information

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Pochta form 22
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  autocomplete recipient information 
// @author       Polyakov Andrey ([email protected])
// @match        https://www.pochta.ru/tracking
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  //
  var newRecipientInfo = {
    Recipient: '', // ФИО или наименование организации
    RecipientAddress: '', // Адрес (населенный пункт, улица, дом, квартира)
    RecipientIndex: '', // Индекс
    RecipientDocumentIssueDate: '', // Когда выдан
    RecipientDocumentIssuer: '', // Кем выдан
    RecipientDocumentNumber: '', // Номер
    RecipientDocumentSerie: '', // Серия
    RecipientDocumentType: 'Паспорт РФ', // Тип документа
    RecipientRegistrationAddress: '' // Адрес регистрации (не заполняется, если совпадает с адресом получателя)
  };

  var objToParams = function(obj) {
    var str = "";
    for (var key in obj) {
      if (str !== "") {
        str += "&";
      }
      str += key + "=" + encodeURIComponent(obj[key]);
    }
    return str;
  };


  window.onload = function() {
    if (window.jQuery) {
      // jQuery is loaded
      jQuery('body').on('click', 'a', function(e) {
        var el = $(this);
        var href = $(this).attr('href');
        var params = JSON.parse('{"' + decodeURI(href).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');
        e.preventDefault();
        if (href.match(/^\/form\?type=F22/) && !href.match(/RecipientAddress/)) {
          var updatedParams = Object.assign(params, newRecipientInfo);
          window.open(objToParams(updatedParams), '_blank');
        }
      });
    } else {
      // jQuery is not loaded
      alert("Jquery не подргрузился, скорее всего сайт лежит");
    }
  };
})();