Skip to content

Commit

Permalink
finally working with events that go across days and with events that …
Browse files Browse the repository at this point in the history
…started in previous week or view. making it full featured now
  • Loading branch information
Ortega-Dan committed Apr 22, 2023
1 parent cdf591e commit e485804
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

// Single calendar event element container... css description string
const calEventElement = "div.ynRLnc"
const firstDayElement = "div.KSxb4d"
const monthsAndYearsOfViewElement = "div.rSoRzd"

// week and daily hours margins
const weeklyHoursMargin = 40
Expand Down Expand Up @@ -84,6 +86,16 @@ $("html").keydown(function (event) {
// Running functionality con Ctrl + i or Ctrl + k (case insensitive)
if (event.altKey === true && (event.code === "KeyI" || event.code === "KeyK" || event.code === "KeyO")) {

// getting date of first day in view
var firstDayInWeek = $(firstDayElement).first().text()
// var firstDayInWeek = $(firstDayElement).first().attr("aria-label")
var yearOfFirstDayInWeek = $(monthsAndYearsOfViewElement).first().text().split(" ")[1]
if (isNaN(yearOfFirstDayInWeek) == true) {
yearOfFirstDayInWeek = $(monthsAndYearsOfViewElement).first().text().split(" ")[3]
}
var monthOfFirstDayInWeek = $(monthsAndYearsOfViewElement).first().text().split(" ")[0]
var dateOfFirstDayInView = new Date(monthOfFirstDayInWeek + " " + firstDayInWeek + ", " + yearOfFirstDayInWeek + " 00:00")

event.preventDefault()
event.stopPropagation()

Expand Down Expand Up @@ -177,6 +189,10 @@ $("html").keydown(function (event) {

// getting actual dates
var startDateTime = new Date(fromDate + " " + fromTime);
// not including and event that starts before the beginning of the first day in the current view
if (startDateTime < dateOfFirstDayInView) {
return
}
var endDateTime = new Date(toDate + " " + toTime);

var hoursLength = getHoursDiffBetweenTwoDateObjs(startDateTime, endDateTime)
Expand Down

0 comments on commit e485804

Please sign in to comment.