This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleCalBookmarklet.txt
1 lines (1 loc) · 13.9 KB
/
googleCalBookmarklet.txt
1
javascript:(function()%7Bvar%20saveAs%20%3D%20saveAs%20%7C%7C%20function%20(e)%20%7B%20%22use%20strict%22%3B%20if%20(typeof%20e%20%3D%3D%3D%20%22undefined%22%20%7C%7C%20typeof%20navigator%20!%3D%3D%20%22undefined%22%20%26%26%20%2FMSIE%20%5B1-9%5D%5C.%2F.test(navigator.userAgent))%20%7B%20return%20%7D%20var%20t%20%3D%20e.document%2C%20n%20%3D%20function%20()%20%7B%20return%20e.URL%20%7C%7C%20e.webkitURL%20%7C%7C%20e%20%7D%2C%20r%20%3D%20t.createElementNS(%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%2C%20%22a%22)%2C%20o%20%3D%20%22download%22%20in%20r%2C%20a%20%3D%20function%20(e)%20%7B%20var%20t%20%3D%20new%20MouseEvent(%22click%22)%3B%20e.dispatchEvent(t)%20%7D%2C%20i%20%3D%20%2Fconstructor%2Fi.test(e.HTMLElement)%20%7C%7C%20e.safari%2C%20f%20%3D%20%2FCriOS%5C%2F%5B%5Cd%5D%2B%2F.test(navigator.userAgent)%2C%20u%20%3D%20function%20(t)%20%7B%20(e.setImmediate%20%7C%7C%20e.setTimeout)(function%20()%20%7B%20throw%20t%20%7D%2C%200)%20%7D%2C%20s%20%3D%20%22application%2Foctet-stream%22%2C%20d%20%3D%201e3%20*%2040%2C%20c%20%3D%20function%20(e)%20%7B%20var%20t%20%3D%20function%20()%20%7B%20if%20(typeof%20e%20%3D%3D%3D%20%22string%22)%20%7B%20n().revokeObjectURL(e)%20%7D%20else%20%7B%20e.remove()%20%7D%20%7D%3B%20setTimeout(t%2C%20d)%20%7D%2C%20l%20%3D%20function%20(e%2C%20t%2C%20n)%20%7B%20t%20%3D%20%5B%5D.concat(t)%3B%20var%20r%20%3D%20t.length%3B%20while%20(r--)%20%7B%20var%20o%20%3D%20e%5B%22on%22%20%2B%20t%5Br%5D%5D%3B%20if%20(typeof%20o%20%3D%3D%3D%20%22function%22)%20%7B%20try%20%7B%20o.call(e%2C%20n%20%7C%7C%20e)%20%7D%20catch%20(a)%20%7B%20u(a)%20%7D%20%7D%20%7D%20%7D%2C%20p%20%3D%20function%20(e)%20%7B%20if%20(%2F%5E%5Cs*(%3F%3Atext%5C%2F%5CS*%7Capplication%5C%2Fxml%7C%5CS*%5C%2F%5CS*%5C%2Bxml)%5Cs*%3B.*charset%5Cs*%3D%5Cs*utf-8%2Fi.test(e.type))%20%7B%20return%20new%20Blob(%5BString.fromCharCode(65279)%2C%20e%5D%2C%20%7B%20type%3A%20e.type%20%7D)%20%7D%20return%20e%20%7D%2C%20v%20%3D%20function%20(t%2C%20u%2C%20d)%20%7B%20if%20(!d)%20%7B%20t%20%3D%20p(t)%20%7D%20var%20v%20%3D%20this%2C%20w%20%3D%20t.type%2C%20m%20%3D%20w%20%3D%3D%3D%20s%2C%20y%2C%20h%20%3D%20function%20()%20%7B%20l(v%2C%20%22writestart%20progress%20write%20writeend%22.split(%22%20%22))%20%7D%2C%20S%20%3D%20function%20()%20%7B%20if%20((f%20%7C%7C%20m%20%26%26%20i)%20%26%26%20e.FileReader)%20%7B%20var%20r%20%3D%20new%20FileReader%3B%20r.onloadend%20%3D%20function%20()%20%7B%20var%20t%20%3D%20f%20%3F%20r.result%20%3A%20r.result.replace(%2F%5Edata%3A%5B%5E%3B%5D*%3B%2F%2C%20%22data%3Aattachment%2Ffile%3B%22)%3B%20var%20n%20%3D%20e.open(t%2C%20%22_blank%22)%3B%20if%20(!n)%20e.location.href%20%3D%20t%3B%20t%20%3D%20undefined%3B%20v.readyState%20%3D%20v.DONE%3B%20h()%20%7D%3B%20r.readAsDataURL(t)%3B%20v.readyState%20%3D%20v.INIT%3B%20return%20%7D%20if%20(!y)%20%7B%20y%20%3D%20n().createObjectURL(t)%20%7D%20if%20(m)%20%7B%20e.location.href%20%3D%20y%20%7D%20else%20%7B%20var%20o%20%3D%20e.open(y%2C%20%22_blank%22)%3B%20if%20(!o)%20%7B%20e.location.href%20%3D%20y%20%7D%20%7D%20v.readyState%20%3D%20v.DONE%3B%20h()%3B%20c(y)%20%7D%3B%20v.readyState%20%3D%20v.INIT%3B%20if%20(o)%20%7B%20y%20%3D%20n().createObjectURL(t)%3B%20setTimeout(function%20()%20%7B%20r.href%20%3D%20y%3B%20r.download%20%3D%20u%3B%20a(r)%3B%20h()%3B%20c(y)%3B%20v.readyState%20%3D%20v.DONE%20%7D)%3B%20return%20%7D%20S()%20%7D%2C%20w%20%3D%20v.prototype%2C%20m%20%3D%20function%20(e%2C%20t%2C%20n)%20%7B%20return%20new%20v(e%2C%20t%20%7C%7C%20e.name%20%7C%7C%20%22download%22%2C%20n)%20%7D%3B%20if%20(typeof%20navigator%20!%3D%3D%20%22undefined%22%20%26%26%20navigator.msSaveOrOpenBlob)%20%7B%20return%20function%20(e%2C%20t%2C%20n)%20%7B%20t%20%3D%20t%20%7C%7C%20e.name%20%7C%7C%20%22download%22%3B%20if%20(!n)%20%7B%20e%20%3D%20p(e)%20%7D%20return%20navigator.msSaveOrOpenBlob(e%2C%20t)%20%7D%20%7D%20w.abort%20%3D%20function%20()%20%7B%20%7D%3B%20w.readyState%20%3D%20w.INIT%20%3D%200%3B%20w.WRITING%20%3D%201%3B%20w.DONE%20%3D%202%3B%20w.error%20%3D%20w.onwritestart%20%3D%20w.onprogress%20%3D%20w.onwrite%20%3D%20w.onabort%20%3D%20w.onerror%20%3D%20w.onwriteend%20%3D%20null%3B%20return%20m%20%7D(typeof%20self%20!%3D%3D%20%22undefined%22%20%26%26%20self%20%7C%7C%20typeof%20window%20!%3D%3D%20%22undefined%22%20%26%26%20window%20%7C%7C%20this.content)%3B%20if%20(typeof%20module%20!%3D%3D%20%22undefined%22%20%26%26%20module.exports)%20%7B%20module.exports.saveAs%20%3D%20saveAs%20%7D%20else%20if%20(typeof%20define%20!%3D%3D%20%22undefined%22%20%26%26%20define%20!%3D%3D%20null%20%26%26%20define.amd%20!%3D%3D%20null)%20%7B%20define(%22FileSaver.js%22%2C%20function%20()%20%7B%20return%20saveAs%20%7D)%20%7D%0A%0Avar%20ics%20%3D%20function%20(e%2C%20t)%20%7B%20%22use%20strict%22%3B%20%7B%20if%20(!(navigator.userAgent.indexOf(%22MSIE%22)%20%3E%20-1%20%26%26%20-1%20%3D%3D%20navigator.userAgent.indexOf(%22MSIE%2010%22)))%20%7B%20void%200%20%3D%3D%3D%20e%20%26%26%20(e%20%3D%20%22default%22)%2C%20void%200%20%3D%3D%3D%20t%20%26%26%20(t%20%3D%20%22Calendar%22)%3B%20var%20r%20%3D%20-1%20!%3D%3D%20navigator.appVersion.indexOf(%22Win%22)%20%3F%20%22%5Cr%5Cn%22%20%3A%20%22%5Cn%22%2C%20n%20%3D%20%5B%5D%2C%20i%20%3D%20%5B%22BEGIN%3AVCALENDAR%22%2C%20%22PRODID%3A%22%20%2B%20t%2C%20%22VERSION%3A2.0%22%5D.join(r)%2C%20o%20%3D%20r%20%2B%20%22END%3AVCALENDAR%22%2C%20a%20%3D%20%5B%22SU%22%2C%20%22MO%22%2C%20%22TU%22%2C%20%22WE%22%2C%20%22TH%22%2C%20%22FR%22%2C%20%22SA%22%5D%3B%20return%20%7B%20events%3A%20function%20()%20%7B%20return%20n%20%7D%2C%20calendar%3A%20function%20()%20%7B%20return%20i%20%2B%20r%20%2B%20n.join(r)%20%2B%20o%20%7D%2C%20addEvent%3A%20function%20(t%2C%20i%2C%20o%2C%20l%2C%20u%2C%20s)%20%7B%20if%20(void%200%20%3D%3D%3D%20t%20%7C%7C%20void%200%20%3D%3D%3D%20i%20%7C%7C%20void%200%20%3D%3D%3D%20o%20%7C%7C%20void%200%20%3D%3D%3D%20l%20%7C%7C%20void%200%20%3D%3D%3D%20u)%20return%20!1%3B%20if%20(s%20%26%26%20!s.rrule)%20%7B%20if%20(%22YEARLY%22%20!%3D%3D%20s.freq%20%26%26%20%22MONTHLY%22%20!%3D%3D%20s.freq%20%26%26%20%22WEEKLY%22%20!%3D%3D%20s.freq%20%26%26%20%22DAILY%22%20!%3D%3D%20s.freq)%20throw%20%22Recurrence%20rrule%20frequency%20must%20be%20provided%20and%20be%20one%20of%20the%20following%3A%20'YEARLY'%2C%20'MONTHLY'%2C%20'WEEKLY'%2C%20or%20'DAILY'%22%3B%20if%20(s.until%20%26%26%20isNaN(Date.parse(s.until)))%20throw%20%22Recurrence%20rrule%20'until'%20must%20be%20a%20valid%20date%20string%22%3B%20if%20(s.interval%20%26%26%20isNaN(parseInt(s.interval)))%20throw%20%22Recurrence%20rrule%20'interval'%20must%20be%20an%20integer%22%3B%20if%20(s.count%20%26%26%20isNaN(parseInt(s.count)))%20throw%20%22Recurrence%20rrule%20'count'%20must%20be%20an%20integer%22%3B%20if%20(void%200%20!%3D%3D%20s.byday)%20%7B%20if%20(%22%5Bobject%20Array%5D%22%20!%3D%3D%20Object.prototype.toString.call(s.byday))%20throw%20%22Recurrence%20rrule%20'byday'%20must%20be%20an%20array%22%3B%20if%20(s.byday.length%20%3E%207)%20throw%20%22Recurrence%20rrule%20'byday'%20array%20must%20not%20be%20longer%20than%20the%207%20days%20in%20a%20week%22%3B%20s.byday%20%3D%20s.byday.filter(function%20(e%2C%20t)%20%7B%20return%20s.byday.indexOf(e)%20%3D%3D%20t%20%7D)%3B%20for%20(var%20c%20in%20s.byday)%20if%20(a.indexOf(s.byday%5Bc%5D)%20%3C%200)%20throw%20%22Recurrence%20rrule%20'byday'%20values%20must%20include%20only%20the%20following%3A%20'SU'%2C%20'MO'%2C%20'TU'%2C%20'WE'%2C%20'TH'%2C%20'FR'%2C%20'SA'%22%20%7D%20%7D%20var%20g%20%3D%20new%20Date(l)%2C%20d%20%3D%20new%20Date(u)%2C%20f%20%3D%20new%20Date%2C%20S%20%3D%20(%220000%22%20%2B%20g.getFullYear().toString()).slice(-4)%2C%20E%20%3D%20(%2200%22%20%2B%20(g.getMonth()%20%2B%201).toString()).slice(-2)%2C%20v%20%3D%20(%2200%22%20%2B%20g.getDate().toString()).slice(-2)%2C%20y%20%3D%20(%2200%22%20%2B%20g.getHours().toString()).slice(-2)%2C%20A%20%3D%20(%2200%22%20%2B%20g.getMinutes().toString()).slice(-2)%2C%20T%20%3D%20(%2200%22%20%2B%20g.getSeconds().toString()).slice(-2)%2C%20b%20%3D%20(%220000%22%20%2B%20d.getFullYear().toString()).slice(-4)%2C%20D%20%3D%20(%2200%22%20%2B%20(d.getMonth()%20%2B%201).toString()).slice(-2)%2C%20N%20%3D%20(%2200%22%20%2B%20d.getDate().toString()).slice(-2)%2C%20h%20%3D%20(%2200%22%20%2B%20d.getHours().toString()).slice(-2)%2C%20I%20%3D%20(%2200%22%20%2B%20d.getMinutes().toString()).slice(-2)%2C%20R%20%3D%20(%2200%22%20%2B%20d.getMinutes().toString()).slice(-2)%2C%20M%20%3D%20(%220000%22%20%2B%20f.getFullYear().toString()).slice(-4)%2C%20w%20%3D%20(%2200%22%20%2B%20(f.getMonth()%20%2B%201).toString()).slice(-2)%2C%20L%20%3D%20(%2200%22%20%2B%20f.getDate().toString()).slice(-2)%2C%20O%20%3D%20(%2200%22%20%2B%20f.getHours().toString()).slice(-2)%2C%20p%20%3D%20(%2200%22%20%2B%20f.getMinutes().toString()).slice(-2)%2C%20Y%20%3D%20(%2200%22%20%2B%20f.getMinutes().toString()).slice(-2)%2C%20U%20%3D%20%22%22%2C%20V%20%3D%20%22%22%3B%20y%20%2B%20A%20%2B%20T%20%2B%20h%20%2B%20I%20%2B%20R%20!%3D%200%20%26%26%20(U%20%3D%20%22T%22%20%2B%20y%20%2B%20A%20%2B%20T%2C%20V%20%3D%20%22T%22%20%2B%20h%20%2B%20I%20%2B%20R)%3B%20var%20B%2C%20C%20%3D%20S%20%2B%20E%20%2B%20v%20%2B%20U%2C%20j%20%3D%20b%20%2B%20D%20%2B%20N%20%2B%20V%2C%20m%20%3D%20M%20%2B%20w%20%2B%20L%20%2B%20(%22T%22%20%2B%20O%20%2B%20p%20%2B%20Y)%3B%20if%20(s)%20if%20(s.rrule)%20B%20%3D%20s.rrule%3B%20else%20%7B%20if%20(B%20%3D%20%22rrule%3AFREQ%3D%22%20%2B%20s.freq%2C%20s.until)%20%7B%20var%20x%20%3D%20new%20Date(Date.parse(s.until)).toISOString()%3B%20B%20%2B%3D%20%22%3BUNTIL%3D%22%20%2B%20x.substring(0%2C%20x.length%20-%2013).replace(%2F%5B-%5D%2Fg%2C%20%22%22)%20%2B%20%22000000Z%22%20%7D%20s.interval%20%26%26%20(B%20%2B%3D%20%22%3BINTERVAL%3D%22%20%2B%20s.interval)%2C%20s.count%20%26%26%20(B%20%2B%3D%20%22%3BCOUNT%3D%22%20%2B%20s.count)%2C%20s.byday%20%26%26%20s.byday.length%20%3E%200%20%26%26%20(B%20%2B%3D%20%22%3BBYDAY%3D%22%20%2B%20s.byday.join(%22%2C%22))%20%7D%20(new%20Date).toISOString()%3B%20var%20H%20%3D%20%5B%22BEGIN%3AVEVENT%22%2C%20%22UID%3A%22%20%2B%20n.length%20%2B%20%22%40%22%20%2B%20e%2C%20%22CLASS%3APUBLIC%22%2C%20%22DESCRIPTION%3A%22%20%2B%20i%2C%20%22DTSTAMP%3BVALUE%3DDATE-TIME%3A%22%20%2B%20m%2C%20%22DTSTART%3BVALUE%3DDATE-TIME%3A%22%20%2B%20C%2C%20%22DTEND%3BVALUE%3DDATE-TIME%3A%22%20%2B%20j%2C%20%22LOCATION%3A%22%20%2B%20o%2C%20%22SUMMARY%3BLANGUAGE%3Den-us%3A%22%20%2B%20t%2C%20%22TRANSP%3ATRANSPARENT%22%2C%20%22END%3AVEVENT%22%5D%3B%20return%20B%20%26%26%20H.splice(4%2C%200%2C%20B)%2C%20H%20%3D%20H.join(r)%2C%20n.push(H)%2C%20H%20%7D%2C%20download%3A%20function%20(e%2C%20t)%20%7B%20if%20(n.length%20%3C%201)%20return%20!1%3B%20t%20%3D%20void%200%20!%3D%3D%20t%20%3F%20t%20%3A%20%22.ics%22%2C%20e%20%3D%20void%200%20!%3D%3D%20e%20%3F%20e%20%3A%20%22calendar%22%3B%20var%20a%2C%20l%20%3D%20i%20%2B%20r%20%2B%20n.join(r)%20%2B%20o%3B%20if%20(-1%20%3D%3D%3D%20navigator.userAgent.indexOf(%22MSIE%2010%22))%20a%20%3D%20new%20Blob(%5Bl%5D)%3B%20else%20%7B%20var%20u%20%3D%20new%20BlobBuilder%3B%20u.append(l)%2C%20a%20%3D%20u.getBlob(%22text%2Fx-vCalendar%3Bcharset%3D%22%20%2B%20document.characterSet)%20%7D%20return%20saveAs(a%2C%20e%20%2B%20t)%2C%20l%20%7D%2C%20build%3A%20function%20()%20%7B%20return%20!(n.length%20%3C%201)%20%26%26%20i%20%2B%20r%20%2B%20n.join(r)%20%2B%20o%20%7D%20%7D%20%7D%20console.log(%22Unsupported%20Browser%22)%20%7D%20%7D%3B%0A%0A%0A%0A%0A%0Aconst%20frame%20%3D%20document.querySelector(%22%23ptifrmtgtframe%22).contentWindow.document%3B%0Aconst%20table%20%3D%20frame.querySelector(%22%23ACE_width%22)%3B%0Aconst%20monthValue%20%3D%20frame.querySelector(%22%23DERIVED_SCH_CAL_MONTH_XLAT%22).value%3B%0Aconst%20firstCells%20%3D%20table.querySelectorAll(%22td%3Afirst-child%22)%3B%0A%0A%0Aconst%20currentYear%20%3D%20new%20Date().getFullYear()%3B%0Aconst%20calendar%20%3D%20ics(parseInt(%22%22%2B%20monthValue%20%2B%20currentYear%2C%2010))%3B%0A%0Alet%20numberOfShifts%20%3D%200%3B%0A%0A%0AfirstCells.forEach((cell)%20%3D%3E%20%7B%0A%20%20%20%20const%20text%20%3D%20cell.innerText.trim()%3B%0A%0A%0A%20%20%20%20if%20(%2F%5E%5Cd%2B%5Cn%2F.test(text)%20%26%26%20!%2F%5CbOFF%5Cb%2F.test(text))%20%7B%0A%20%20%20%20%20%20%20%20const%20lines%20%3D%20text.split(%22%5Cn%22)%3B%0A%20%20%20%20%20%20%20%20lines.splice(1%2C%205)%3B%0A%20%20%20%20%20%20%20%20const%20shift%20%3D%20lines%5B1%5D.split(%22-%22).map(s%20%3D%3E%20s.trim())%3B%0A%0A%0A%20%20%20%20%20%20%20%20const%20%5BstartShift%2C%20endShift%5D%20%3D%20shift.map(s%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20%5Bhour%2C%20minute%5D%20%3D%20s.split(%22%3A%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20ampm%20%3D%20minute.slice(-2)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20let%20adjustedHour%20%3D%20parseInt(hour%2C%2010)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(adjustedHour%20!%3D%3D%2012%20%26%26%20ampm%20%3D%3D%3D%20%22PM%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adjustedHour%20%2B%3D%2012%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%20else%20if%20(adjustedHour%20%3D%3D%3D%2012%20%26%26%20ampm%20%3D%3D%3D%20%22AM%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adjustedHour%20%3D%200%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20hour%3A%20adjustedHour%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20minute%3A%20parseInt(minute%2C%2010)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%0A%20%20%20%20%20%20%20%20const%20month%20%3D%20parseInt(monthValue%2C%2010)%20-%201%3B%0A%20%20%20%20%20%20%20%20const%20day%20%3D%20parseInt(lines%5B0%5D%2C%2010)%3B%0A%20%20%20%20%20%20%20%20const%20startDate%20%3D%20new%20Date(currentYear%2C%20month%2C%20day%2C%20startShift.hour%2C%20startShift.minute%2C%200)%3B%0A%20%20%20%20%20%20%20%20const%20endDate%20%3D%20new%20Date(currentYear%2C%20month%2C%20day%2C%20endShift.hour%2C%20endShift.minute%2C%200)%3B%0A%0A%20%20%20%20%20%20%20%20calendar.addEvent(%22Work%22%2C%20%22%22%2C%20%22%22%2C%20startDate%2C%20endDate)%3B%0A%0A%20%20%20%20%20%20%20%20numberOfShifts%2B%2B%3B%0A%20%20%20%20%7D%0A%7D)%3B%0A%0Acalendar.download(%60WorkSchedule%24%7BmonthValue%7D%2F%24%7BcurrentYear%7D-%24%7BnumberOfShifts%7D%60)%3B%0A%0A%0AsetTimeout(()%20%3D%3E%20%7B%0A%20%20%20%20window.open(%22https%3A%2F%2Fcalendar.google.com%2Fcalendar%2Fu%2F0%2Fr%2Fsettings%2Fexport%22%2C%20%22_blank%22)%0A%7D%2C%202000)%3B%7D)()%3B