Last active
September 13, 2019 12:09
-
-
Save da411d/6430c112ddf4042857c3d671502d6864 to your computer and use it in GitHub Desktop.
Скрипт для конвертування електронного квитка в файл Google-календаря (https://booking.uz.gov.ua/result/.../)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
HTMLDocument.prototype.qq = HTMLDocument.prototype.querySelector; | |
HTMLDocument.prototype.qqq = HTMLDocument.prototype.querySelectorAll; | |
HTMLElement.prototype.qq = HTMLElement.prototype.querySelector; | |
HTMLElement.prototype.qqq = HTMLElement.prototype.querySelectorAll; | |
function download(filename, text) { | |
var element = document.createElement('a'); | |
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | |
element.setAttribute('download', filename); | |
element.style.display = 'none'; | |
document.body.appendChild(element); | |
element.click(); | |
document.body.removeChild(element); | |
} | |
document.qqq(".blank.electronic table.ticket").forEach((ticket) => { | |
var order_num = ticket.qq(".order_num").innerText; | |
var name = ""; | |
var car_num = -1; | |
var seat = -1; | |
var time_start = -1; | |
var time_end = -1; | |
var to = false; | |
ticket.qqq("tr").forEach((row) => { | |
// Прізвище-Ім'я | |
if(row.innerText.indexOf("Прізвище") != -1){ | |
name = row.qq("td[colspan='2']").innerText; | |
} | |
// Вагон | |
if(row.innerText.indexOf("Вагон") != -1){ | |
car_num = row.qq(".align-right").innerText.split(" ")[0]; | |
} | |
// Місце | |
if(row.innerText.indexOf("Місце") != -1){ | |
seat = row.qq(".align-right").innerText.split(" ")[0]; | |
} | |
// Відправлення | |
if(row.innerText.indexOf("відпр.") != -1){ | |
time_start = row.qq(".ticket_info").innerText.split(" "); | |
time_start = time_start[0].split(".").reverse().join("") + "T" + time_start[1].split(":").join("")+"00"; | |
} | |
// Прибуття | |
if(row.innerText.indexOf("приб.") != -1){ | |
time_end = row.qq(".ticket_info").innerText.split(" "); | |
time_end = time_end[0].split(".").reverse().join("") + "T" + time_end[1].split(":").join("")+"00"; | |
} | |
// Призначення | |
if(row.innerText.indexOf("Призначення") != -1){ | |
to = row.querySelector(".upper.ticket_info").innerText; | |
} | |
}) | |
var title = "🚂 Поїзд "; | |
if(to == "ІВАНО-ФРАНКІВСЬК"){ | |
title += "додому"; | |
}else{ | |
title += "в "+(to[0].toUpperCase() + to.substr(1).toLowerCase()); | |
} | |
var data = [ | |
"BEGIN:VCALENDAR", | |
"VERSION:2.0", | |
"CALSCALE:GREGORIAN", | |
"PRODID:adamgibbons/ics", | |
"BEGIN:VEVENT", | |
"SUMMARY:" + title, | |
"DTSTART:" + time_start, | |
"DTEND:" + time_end, | |
"DESCRIPTION:" + order_num + "\\n" + car_num + ">" + seat, | |
"STATUS:CONFIRMED", | |
"END:VEVENT", | |
"END:VCALENDAR" | |
].join("\n"); | |
download("CALENDAR-" + name.replace(/\s/g, "_") + "-" + to + "-" + time_start + ".ics", data); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment