Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #4: #calendar createDefaultEvent() #6

Merged
merged 1 commit into from Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -34,6 +34,7 @@ <h1>Random Clean Code Tip and Code Review Tip</h1>
>ryanmcdermott/code-review-tips</a
>.</i
>
<button id="calendar">Set up calendar reminder</button>
</p>
<main>
<section>
Expand Down
32 changes: 32 additions & 0 deletions script.js
Expand Up @@ -90,6 +90,34 @@ function removeBackToTopLink(string) {
);
}

function getUTCFormattedDateString(date) {
return date.toISOString().replaceAll(/[-.:]/g, "");
}

function createCalendarEvent(
summary,
start = "20160204T090000Z",
end = "20160204T100000Z"
) {
const icsString =
"BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Random Code Tips//NONSGML v1.0//EN\nBEGIN:VEVENT" +
"\nRRULE:FREQ=WEEKLY" +
"\nDTSTART:" +
start +
"\nDTEND:" +
end +
"\nSUMMARY:" +
summary +
"\nEND:VEVENT\nEND:VCALENDAR";

window.open("data:text/calendar;charset=utf8," + escape(icsString));
}

function createDefaultEvent() {
const now = getUTCFormattedDateString(new Date());
createCalendarEvent("Random Code Tips", now, now);
}

(async function run() {
const fetcher = new Fetcher();

Expand Down Expand Up @@ -117,4 +145,8 @@ function removeBackToTopLink(string) {
document.querySelector("#tip_details_go_here_2").innerHTML = weaklySanitize(
marked(removeBackToTopLink(details2))
);

document
.querySelector("#calendar")
.addEventListener("click", createDefaultEvent);
})();