Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
rzd autofill
// ==UserScript==
// @name rzd
// @namespace https://gist.github.com/justdanpo
// @version 0.1
// @description rzd
// @author den_po
// @include https://pass.rzd.ru/tickets/*
// @run-at document-end
// @grant none
// ==/UserScript==
setTimeout(function() {
var fieldnames=[ "lastName", "firstName", "midName", "gender", "birthdate", "docNumber", "docType", "personTariff"];
if(fieldnames.every(function(fn){return document.getElementsByName(fn).length>0?1:0;})){
var data=[
["Фамилия", "Имя1", "Отчество1", "Мужской", "01.02.1985", "1111 222222", "Паспорт РФ", "Полный"],
["Фамилия", "Имя2", "Отчество2", "Женский", "02.03.2015", "IРЛ 333333", "Свидетельство о рождении", "Детский"]
];
//добавить бланки пассажиров
while(document.getElementsByClassName("j-pass-num").length<data.length){
Array.from(document.getElementsByClassName("link-plus-text")).filter(function(f){return f.textContent.search("Добавить пассажира")>=0;})[0].click();
}
function setOptionValue(elem, value){
elem.value = Array.from(elem.children).find(function(f){return f.textContent==value;}).value;
}
function dofield(fieldnum) {
var fieldname = fieldnames[fieldnum];
var fields = document.getElementsByName(fieldname);
if(fields.length != data.length)throw fieldname + " =(";
for(user=0; user< data.length; user++) {
var elem=fields[user];
if(elem.tagName=="SELECT"){
setOptionValue(elem, data[user][fieldnum]);
}else {
elem.value = data[user][fieldnum];
}
$("[name='"+fieldname+"']").eq(user).trigger('change');
}
if(fieldnum<fieldnames.length-1) {
setTimeout(dofield, 20, fieldnum+1);
}else {
setTimeout(function(){
//снять страхование от несчастных случаев
Array.from(document.getElementsByName("bInsurance")).filter(function(f){return f.checked;}).forEach(function(f){f.click();});
setTimeout(function(){
//снять медицинские расходы
Array.from(document.getElementsByName("MedicalInsuranceCheckbox")).filter(function(f){return f.checked;}).forEach(function(f){f.click();});
}, 20);
}, 20);
}
}
dofield(0);
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.