-
Notifications
You must be signed in to change notification settings - Fork 0
/
fb_birthday_cal_maker.min.js
15 lines (13 loc) · 6.87 KB
/
fb_birthday_cal_maker.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// update this map as per your current day, Enter when is your next monday, tuesday etc.. MM/dd
var map = {
"monday":"07/29",
"tuesday":"07/30",
"wednesday":"07/31",
"thursday":"08/01",
"friday":"08/02",
"saturday":"08/03",
"sunday": "08/04"
};
// update the current year in which your living below. (Request the time travelers to check your calendar and verfiy that the value you entered is correct )
var year = "2019";
var _global="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:this;function bom(e,t){return void 0===t?t={autoBom:!1}:"object"!=typeof t&&(console.warn("Deprecated: Expected third argument to be a object"),t={autoBom:!t}),t.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([String.fromCharCode(65279),e],{type:e.type}):e}function download(e,t,n){var o=new XMLHttpRequest;o.open("GET",e),o.responseType="blob",o.onload=function(){saveAs(o.response,t,n)},o.onerror=function(){console.error("could not download file")},o.send()}function corsEnabled(e){var t=new XMLHttpRequest;t.open("HEAD",e,!1);try{t.send()}catch(e){}return t.status>=200&&t.status<=299}function click(e){try{e.dispatchEvent(new MouseEvent("click"))}catch(n){var t=document.createEvent("MouseEvents");t.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),e.dispatchEvent(t)}}var saveAs=_global.saveAs||("object"!=typeof window||window!==_global?function(){}:"download"in HTMLAnchorElement.prototype?function(e,t,n){var o=_global.URL||_global.webkitURL,r=document.createElement("a");t=t||e.name||"download",r.download=t,r.rel="noopener","string"==typeof e?(r.href=e,r.origin!==location.origin?corsEnabled(r.href)?download(e,t,n):click(r,r.target="_blank"):click(r)):(r.href=o.createObjectURL(e),setTimeout(function(){o.revokeObjectURL(r.href)},4e4),setTimeout(function(){click(r)},0))}:"msSaveOrOpenBlob"in navigator?function(e,t,n){if(t=t||e.name||"download","string"==typeof e)if(corsEnabled(e))download(e,t,n);else{var o=document.createElement("a");o.href=e,o.target="_blank",setTimeout(function(){click(o)})}else navigator.msSaveOrOpenBlob(bom(e,n),t)}:function(e,t,n,o){if((o=o||open("","_blank"))&&(o.document.title=o.document.body.innerText="downloading..."),"string"==typeof e)return download(e,t,n);var r="application/octet-stream"===e.type,a=/constructor/i.test(_global.HTMLElement)||_global.safari,i=/CriOS\/[\d]+/.test(navigator.userAgent);if((i||r&&a)&&"undefined"!=typeof FileReader){var l=new FileReader;l.onloadend=function(){var e=l.result;e=i?e:e.replace(/^data:[^;]*;/,"data:attachment/file;"),o?o.location.href=e:location=e,o=null},l.readAsDataURL(e)}else{var c=_global.URL||_global.webkitURL,s=c.createObjectURL(e);o?o.location=s:location.href=s,o=null,setTimeout(function(){c.revokeObjectURL(s)},4e4)}});_global.saveAs=saveAs.saveAs=saveAs,"undefined"!=typeof module&&(module.exports=saveAs);var ics=function(e,t){"use strict";if(!(navigator.userAgent.indexOf("MSIE")>-1&&-1==navigator.userAgent.indexOf("MSIE 10"))){void 0===e&&(e="default"),void 0===t&&(t="Calendar");var n=-1!==navigator.appVersion.indexOf("Win")?"\r\n":"\n",o=[],r=["BEGIN:VCALENDAR","PRODID:"+t,"VERSION:2.0"].join(n),a=n+"END:VCALENDAR",i=["SU","MO","TU","WE","TH","FR","SA"];return{events:function(){return o},calendar:function(){return r+n+o.join(n)+a},addEvent:function(t,r,a,l,c,s){if(void 0===t||void 0===r||void 0===a||void 0===l||void 0===c)return!1;if(s&&!s.rrule){if("YEARLY"!==s.freq&&"MONTHLY"!==s.freq&&"WEEKLY"!==s.freq&&"DAILY"!==s.freq)throw"Recurrence rrule frequency must be provided and be one of the following: 'YEARLY', 'MONTHLY', 'WEEKLY', or 'DAILY'";if(s.until&&isNaN(Date.parse(s.until)))throw"Recurrence rrule 'until' must be a valid date string";if(s.interval&&isNaN(parseInt(s.interval)))throw"Recurrence rrule 'interval' must be an integer";if(s.count&&isNaN(parseInt(s.count)))throw"Recurrence rrule 'count' must be an integer";if(void 0!==s.byday){if("[object Array]"!==Object.prototype.toString.call(s.byday))throw"Recurrence rrule 'byday' must be an array";if(s.byday.length>7)throw"Recurrence rrule 'byday' array must not be longer than the 7 days in a week";for(var d in s.byday=s.byday.filter(function(e,t){return s.byday.indexOf(e)==t}),s.byday)if(i.indexOf(s.byday[d])<0)throw"Recurrence rrule 'byday' values must include only the following: 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'"}}var u=new Date(l),f=new Date(c),g=new Date,b=("0000"+u.getFullYear().toString()).slice(-4),v=("00"+(u.getMonth()+1).toString()).slice(-2),y=("00"+u.getDate().toString()).slice(-2),p=("00"+u.getHours().toString()).slice(-2),E=("00"+u.getMinutes().toString()).slice(-2),w=("00"+u.getSeconds().toString()).slice(-2),h=("0000"+f.getFullYear().toString()).slice(-4),m=("00"+(f.getMonth()+1).toString()).slice(-2),A=("00"+f.getDate().toString()).slice(-2),S=("00"+f.getHours().toString()).slice(-2),T=("00"+f.getMinutes().toString()).slice(-2),R=("00"+f.getMinutes().toString()).slice(-2),L="",D="";p+E+w+S+T+R!=0&&(L="T"+p+E+w,D="T"+S+T+R);var M,N=b+v+y+L,O=h+m+A+D,I=("0000"+g.getFullYear().toString()).slice(-4)+("00"+(g.getMonth()+1).toString()).slice(-2)+("00"+g.getDate().toString()).slice(-2)+"T"+("00"+g.getHours().toString()).slice(-2)+("00"+g.getMinutes().toString()).slice(-2)+("00"+g.getMinutes().toString()).slice(-2);if(s)if(s.rrule)M=s.rrule;else{if(M="rrule:FREQ="+s.freq,s.until){var U=new Date(Date.parse(s.until)).toISOString();M+=";UNTIL="+U.substring(0,U.length-13).replace(/[-]/g,"")+"000000Z"}s.interval&&(M+=";INTERVAL="+s.interval),s.count&&(M+=";COUNT="+s.count),s.byday&&s.byday.length>0&&(M+=";BYDAY="+s.byday.join(","))}(new Date).toISOString();var k=["BEGIN:VEVENT","UID:"+o.length+"@"+e,"CLASS:PUBLIC","DESCRIPTION:"+r,"DTSTAMP;VALUE=DATE-TIME:"+I,"DTSTART;VALUE=DATE-TIME:"+N,"DTEND;VALUE=DATE-TIME:"+O,"LOCATION:"+a,"SUMMARY;LANGUAGE=en-us:"+t,"TRANSP:TRANSPARENT","END:VEVENT"];return M&&k.splice(4,0,M),k=k.join(n),o.push(k),k},download:function(e,t){if(o.length<1)return!1;t=void 0!==t?t:".ics",e=void 0!==e?e:"calendar";var i,l=r+n+o.join(n)+a;if(-1===navigator.userAgent.indexOf("MSIE 10"))i=new Blob([l]);else{var c=new BlobBuilder;c.append(l),i=c.getBlob("text/x-vCalendar;charset="+document.characterSet)}return saveAs(i,e+t),l},build:function(){return!(o.length<1)&&r+n+o.join(n)+a}}}console.log("Unsupported Browser")},k=document.getElementsByTagName("a"),cal=ics(),rrule={freq:"YEARLY",count:100,interval:1};for(i=0;i<k.length;i++)try{var href=k[i].getAttribute("href"),dtc=k[i].getAttribute("data-tooltip-content");if(null!=href&&null!=dtc){var name=dtc.split("(")[0],birthday=dtc.split("(")[1].split(")")[0];map[birthday.toLowerCase()]&&(birthday=map[birthday.toLowerCase()]);var m=birthday.split("/")[0],d=birthday.split("/")[1],y=year;cal.addEvent(name+"'s Birthday",name+"'s Birthday",href,m+"/"+d+"/"+y,m+"/"+d+"/"+y)}}catch(e){console.log(e)}cal.download("fb_birthday_cal_maker");