woj503 / Insert

// ==UserScript==
// @name        Insert
// @namespace   /home/adam/Pulpit/script.js
// @include     http://localhost/bot*
// @include     https://shoppingcart.aliexpress.com/order/confirm_order.html*
// @version     1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require     http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js
// @resource    http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css
// @grant       GM_addStyle
// @match       https://shoppingcart.aliexpress.com/order/confirm_order.html*
// @license MIT
// ==/UserScript==

$("head").append (
    '<link '
  + 'href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/ui-darkness/jquery-ui.min.css" '
  + 'rel="stylesheet" type="text/css">');

this.$ = this.jQuery = jQuery.noConflict(true);


 $(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: true,
      height:200,
      modal: false,
      buttons: {
        "Add data": function() {
          addDataToForm();
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });

$('body').prepend('<div id="dialog-confirm" title="Dodaj dane">'+
  '<textarea id="text" style="width: 263px; height: 157px;"></textarea>'+
'</div>');


function addDataToForm()
{
  var string = $('#text').val();
  
  string = string.replace(/ą/g, 'a').replace(/Ą/g, 'A')
        .replace(/ć/g, 'c').replace(/Ć/g, 'C')
        .replace(/ę/g, 'e').replace(/Ę/g, 'E')
        .replace(/ł/g, 'l').replace(/Ł/g, 'L')
        .replace(/ń/g, 'n').replace(/Ń/g, 'N')
        .replace(/ó/g, 'o').replace(/Ó/g, 'O')
        .replace(/ś/g, 's').replace(/Ś/g, 'S')
        .replace(/ż/g, 'z').replace(/Ż/g, 'Z')
        .replace(/ź/g, 'z').replace(/Ź/g, 'Z');
  
   var data = string.split("\n");
  
  data[2] = data[2].split(" ");
  
  var zip = (data[2]).shift().replace("-", "");
  
  var city = (data[2]).join(" ");
  
  data[4] = data[4].split(" ");
  
  console.log(data);
  
  //insert State
  $("input[name='province']").val('PL');
  
  $("option[value='PL']").attr('selected', 'selected');
  
  //insert first and lastname
  $("input[name='contactPerson']").val(data[0]);
  //insert street
  $("input[name='address']").val(data[1]);
  //insert city
  $("input[name='city']").val(city);
  //insert zipcode
  $("input[name='zip']").val(zip);
  //insert mobile
  $("input[name='mobileNo']").val(data[4][1]);
  
}