There are 1 previous version of this script.
// ==UserScript==
// @name vkiCal
// @namespace http://userscripts.org/users/ale925
// @description Создает объект iCalendar на страницах событий ВКонтакте
// @include http://vkontakte.ru/event*
// ==/UserScript==
// @include *
const rumont = {
"янв" : "01",
"фев" : "02",
"мар" : "03",
"апр" : "04",
"мая" : "05",
"июн" : "06",
"июл" : "07",
"авг" : "08",
"сен" : "09",
"окт" : "10",
"ноя" : "11",
"дек" : "12"
};
var summary = '';
var location = '';
var description = '';
var time_start = '';
var time_end = '';
var allLabelsTD = document.evaluate("//td[@class='label']", document, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for ( var i = 0; i < allLabelsTD.snapshotLength; i++) {
var dataHTML;
var thisLink = allLabelsTD.snapshotItem(i);
var label = thisLink.innerHTML.toString();
GM_log(label);
switch (label) {
case "Название:":
dataHTML = thisLink.nextSibling.nextSibling.firstChild.firstChild.innerHTML;
if (dataHTML) {
GM_log(dataHTML.toString());
summary = dataHTML.toString();
}
break;
case "Адрес:":
dataHTML = thisLink.nextSibling.nextSibling.firstChild.innerHTML;
if (dataHTML) {
GM_log(dataHTML.toString());
location = dataHTML.toString();
}
break;
case "Начало:":
dataHTML = thisLink.nextSibling.nextSibling.firstChild.innerHTML;
if (dataHTML) {
GM_log(dataHTML.toString());
time_start = dataHTML.toString();
}
break;
case "Окончание:":
dataHTML = thisLink.nextSibling.nextSibling.firstChild.innerHTML;
if (dataHTML) {
GM_log(dataHTML.toString());
time_end = dataHTML.toString();
}
break;
}
}
var descDiv = document.getElementById('description');
description = descDiv.childNodes[3].childNodes[1].childNodes[1].innerHTML
.toString();
description = description.replace(/<br>/g, "\\n");
// 18 мая 2009 в 19:00
var regexp = /(\d+) ([^ ]+) (\d\d\d\d)\D+(\d+):(\d+)/;
var matches = time_start.match(regexp);
var start_td = new Date(matches[3], rumont[matches[2]] - 1, matches[1],
matches[4], matches[5], 0);
var year = start_td.getUTCFullYear();
var month = start_td.getUTCMonth() + 1;
var day = start_td.getUTCDate();
var hours = start_td.getUTCHours();
var mins = start_td.getUTCMinutes();
var secs = start_td.getUTCSeconds();
time_start = year + (month < 10 ? '0' + month : month.toString())
+ (day < 10 ? '0' + day : day.toString()) + 'T'
+ (hours < 10 ? '0' + hours : hours.toString())
+ (mins < 10 ? '0' + mins : mins.toString())
+ (secs < 10 ? '0' + secs : secs.toString()) + 'Z';
matches = time_end.match(regexp);
var end_td = new Date(matches[3], rumont[matches[2]] - 1, matches[1],
matches[4], matches[5], 0);
year = end_td.getUTCFullYear();
month = end_td.getUTCMonth() + 1;
day = end_td.getUTCDate();
hours = end_td.getUTCHours();
mins = end_td.getUTCMinutes();
secs = end_td.getUTCSeconds();
time_end = year + (month < 10 ? '0' + month : month.toString())
+ (day < 10 ? '0' + day : day.toString()) + 'T'
+ (hours < 10 ? '0' + hours : hours.toString())
+ (mins < 10 ? '0' + mins : mins.toString())
+ (secs < 10 ? '0' + secs : secs.toString()) + 'Z';
// TIMESTAMP (UTC)
var now = new Date();
year = now.getUTCFullYear();
month = now.getUTCMonth();
day = now.getUTCDate();
hours = now.getUTCHours();
mins = now.getUTCMinutes();
secs = now.getUTCSeconds();
timestamp = year + (month < 10 ? '0' + month : month.toString())
+ (day < 10 ? '0' + day : day.toString()) + 'T'
+ (hours < 10 ? '0' + hours : hours.toString())
+ (mins < 10 ? '0' + mins : mins.toString())
+ (secs < 10 ? '0' + secs : secs.toString()) + 'Z';
// UID
var uid = 'vkiCal-' + timestamp;
description = "DESCRIPTION:" + description;
var crlfIndex = 73;
while (crlfIndex < description.length) {
description = description.substring(0, crlfIndex) + "\n "
+ description.substring(crlfIndex);
crlfIndex += 74;
}
description = description.substring(12);
var cal_string = [
"BEGIN:VCALENDAR",
"VERSION:2.0",
"METHOD:PUBLISH",
"BEGIN:VEVENT",
"DTSTART:" + time_start,
"DTEND:" + time_end,
"SUMMARY:" + summary,
"LOCATION:" + location,
"DESCRIPTION:" + description,
"UID:" + uid,
"SEQUENCE:0",
"DTSTAMP:" + timestamp,
"END:VEVENT",
"END:VCALENDAR"
].join("\n");
var navOL = document.evaluate("//ol[@id='nav']", document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var ical_li = document.createElement("li");
var ical_a = document.createElement("a");
var ical_text = document.createTextNode("Объект iCalendar");
ical_a.href = "data:text/calendar;charset=utf-8,"
+ encodeURIComponent(cal_string);
ical_a.appendChild(ical_text);
ical_li.appendChild(ical_a);
navOL.appendChild(ical_li);
