Skip to content

Instantly share code, notes, and snippets.

@jkremser
Created January 20, 2025 23:34
Show Gist options
  • Save jkremser/c30a542575e487cddc0674225f2c833a to your computer and use it in GitHub Desktop.
Save jkremser/c30a542575e487cddc0674225f2c833a to your computer and use it in GitHub Desktop.
icanteen tampermonkey script
// ==UserScript==
// @name to ical
// @namespace http://tampermonkey.net/
// @version 2025-01-20
// @description Make ical
// @author jkremser
// @match https://objednavky.obedyvbrne.cz/faces/secured/objednavky.jsp
// @icon https://www.google.com/s2/favicons?sz=64&domain=obedyvbrne.cz
// @require https://raw.githubusercontent.com/matthiasanderer/icsFormatter/refs/heads/master/icsFormatter.js
// @grant none
// ==/UserScript==
(async function() {
//'use strict';
//const { createEvent } = await import("https://cdn.jsdelivr.net/npm/[email protected]/+esm");
//const { createEvent } = await import("https://esm.run/ics") ;
var calEntry = icsFormatter();
const tBody = document.querySelector("#mainContext > table > tbody");
for (var j = 1; j < tBody.children.length; j++) {
const row = tBody.children[j];
const date = row.children[0].innerText;
const chunks = date.split('.');
const year = chunks[2];
const month = chunks[1];
const day = chunks[0];
const datum = new Date(Date.parse(`${year}-${month}-${day}`));
const jidlo = row.children[2].innerText.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
const jidloTitle = jidlo.replace(/ *\[[^\]]*\] */g, '').replace(/,\s*$/, '').replaceAll(';','').replaceAll('/DIA','').replaceAll('/Vyb','').replaceAll('/ZL','');
const ks = row.children[5].innerText;
console.log();
//console.log(datum.toLocaleString("en-US"));
var place = 'doma';
var end = new Date(datum.getTime() + 45*60000);
var description = ks;
calEntry.addEvent(jidloTitle, description, place, datum.toUTCString(), end.toUTCString());
}
//calEntry.download('jidelnicek.ics');
console.log(calEntry.calendar());
const foo = document.createElement('a');
foo.href = 'data:application/octet-stream;charset=utf-16le;base64,' + btoa(calEntry.calendar());
foo.download = 'jidelnicek.ics';
foo.innerHTML='jidelnicek.ics';
const parent = document.getElementById('content:filterDateForm');
parent.appendChild(foo);
//anchor.click();
//document.body.removeChild(anchor);
//URL.revokeObjectURL(url);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment