aboutsummaryrefslogblamecommitdiff
path: root/dist/background.js
blob: 6ea17e1dbbcf8524b84c65514f9bccea96214097 (plain) (tree)
1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
!function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=848)}({109:function(t,e,n){"use strict";const r=n(172),i=Symbol("max"),a=Symbol("length"),o=Symbol("lengthCalculator"),s=Symbol("allowStale"),u=Symbol("maxAge"),l=Symbol("dispose"),h=Symbol("noDisposeOnSet"),c=Symbol("lruList"),f=Symbol("cache"),d=Symbol("updateAgeOnGet"),v=()=>1;const p=(t,e,n)=>{const r=t[f].get(e);if(r){const e=r.value;if(g(t,e)){if(m(t,r),!t[s])return}else n&&(t[d]&&(r.value.now=Date.now()),t[c].unshiftNode(r));return e.value}},g=(t,e)=>{if(!e||!e.maxAge&&!t[u])return!1;const n=Date.now()-e.now;return e.maxAge?n>e.maxAge:t[u]&&n>t[u]},y=t=>{if(t[a]>t[i])for(let e=t[c].tail;t[a]>t[i]&&null!==e;){const n=e.prev;m(t,e),e=n}},m=(t,e)=>{if(e){const n=e.value;t[l]&&t[l](n.key,n.value),t[a]-=n.length,t[f].delete(n.key),t[c].removeNode(e)}};class w{constructor(t,e,n,r,i){this.key=t,this.value=e,this.length=n,this.now=r,this.maxAge=i||0}}const b=(t,e,n,r)=>{let i=n.value;g(t,i)&&(m(t,n),t[s]||(i=void 0)),i&&e.call(r,i.value,i.key,t)};t.exports=class{constructor(t){if("number"==typeof t&&(t={max:t}),t||(t={}),t.max&&("number"!=typeof t.max||t.max<0))throw new TypeError("max must be a non-negative number");this[i]=t.max||1/0;const e=t.length||v;if(this[o]="function"!=typeof e?v:e,this[s]=t.stale||!1,t.maxAge&&"number"!=typeof t.maxAge)throw new TypeError("maxAge must be a number");this[u]=t.maxAge||0,this[l]=t.dispose,this[h]=t.noDisposeOnSet||!1,this[d]=t.updateAgeOnGet||!1,this.reset()}set max(t){if("number"!=typeof t||t<0)throw new TypeError("max must be a non-negative number");this[i]=t||1/0,y(this)}get max(){return this[i]}set allowStale(t){this[s]=!!t}get allowStale(){return this[s]}set maxAge(t){if("number"!=typeof t)throw new TypeError("maxAge must be a non-negative number");this[u]=t,y(this)}get maxAge(){return this[u]}set lengthCalculator(t){"function"!=typeof t&&(t=v),t!==this[o]&&(this[o]=t,this[a]=0,this[c].forEach(t=>{t.length=this[o](t.value,t.key),this[a]+=t.length})),y(this)}get lengthCalculator(){return this[o]}get length(){return this[a]}get itemCount(){return this[c].length}rforEach(t,e){e=e||this;for(let n=this[c].tail;null!==n;){const r=n.prev;b(this,t,n,e),n=r}}forEach(t,e){e=e||this;for(let n=this[c].head;null!==n;){const r=n.next;b(this,t,n,e),n=r}}keys(){return this[c].toArray().map(t=>t.key)}values(){return this[c].toArray().map(t=>t.value)}reset(){this[l]&&this[c]&&this[c].length&&this[c].forEach(t=>this[l](t.key,t.value)),this[f]=new Map,this[c]=new r,this[a]=0}dump(){return this[c].map(t=>!g(this,t)&&{k:t.key,v:t.value,e:t.now+(t.maxAge||0)}).toArray().filter(t=>t)}dumpLru(){return this[c]}set(t,e,n){if((n=n||this[u])&&"number"!=typeof n)throw new TypeError("maxAge must be a number");const r=n?Date.now():0,s=this[o](e,t);if(this[f].has(t)){if(s>this[i])return m(this,this[f].get(t)),!1;const o=this[f].get(t).value;return this[l]&&(this[h]||this[l](t,o.value)),o.now=r,o.maxAge=n,o.value=e,this[a]+=s-o.length,o.length=s,this.get(t),y(this),!0}const d=new w(t,e,s,r,n);return d.length>this[i]?(this[l]&&this[l](t,e),!1):(this[a]+=d.length,this[c].unshift(d),this[f].set(t,this[c].head),y(this),!0)}has(t){if(!this[f].has(t))return!1;const e=this[f].get(t).value;return!g(this,e)}get(t){return p(this,t,!0)}peek(t){return p(this,t,!1)}pop(){const t=this[c].tail;return t?(m(this,t),t.value):null}del(t){m(this,this[f].get(t))}load(t){this.reset();const e=Date.now();for(let n=t.length-1;n>=0;n--){const r=t[n],i=r.e||0;if(0===i)this.set(r.k,r.v);else{const t=i-e;t>0&&this.set(r.k,r.v,t)}}}prune(){this[f].forEach((t,e)=>p(this,e,!1))}}},172:function(t,e,n){"use strict";function r(t){var e=this;if(e instanceof r||(e=new r),e.tail=null,e.head=null,e.length=0,t&&"function"==typeof t.forEach)t.forEach(function(t){e.push(t)});else if(arguments.length>0)for(var n=0,i=arguments.length;n<i;n++)e.push(arguments[n]);return e}function i(t,e){t.tail=new o(e,t.tail,null,t),t.head||(t.head=t.tail),t.length++}function a(t,e){t.head=new o(e,null,t.head,t),t.tail||(t.tail=t.head),t.length++}function o(t,e,n,r){if(!(this instanceof o))return new o(t,e,n,r);this.list=r,this.value=t,e?(e.next=this,this.prev=e):this.prev=null,n?(n.prev=this,this.next=n):this.next=null}t.exports=r,r.Node=o,r.create=r,r.prototype.removeNode=function(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");var e=t.next,n=t.prev;e&&(e.prev=n),n&&(n.next=e),t===this.head&&(this.head=e),t===this.tail&&(this.tail=n),t.list.length--,t.next=null,t.prev=null,t.list=null},r.prototype.unshiftNode=function(t){if(t!==this.head){t.list&&t.list.removeNode(t);var e=this.head;t.list=this,t.next=e,e&&(e.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}},r.prototype.pushNode=function(t){if(t!==this.tail){t.list&&t.list.removeNode(t);var e=this.tail;t.list=this,t.prev=e,e&&(e.next=t),this.tail=t,this.head||(this.head=t),this.length++}},r.prototype.push=function(){for(var t=0,e=arguments.length;t<e;t++)i(this,arguments[t]);return this.length},r.prototype.unshift=function(){for(var t=0,e=arguments.length;t<e;t++)a(this,arguments[t]);return this.length},r.prototype.pop=function(){if(this.tail){var t=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,t}},r.prototype.shift=function(){if(this.head){var t=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,t}},r.prototype.forEach=function(t,e){e=e||this;for(var n=this.head,r=0;null!==n;r++)t.call(e,n.value,r,this),n=n.next},r.prototype.forEachReverse=function(t,e){e=e||this;for(var n=this.tail,r=this.length-1;null!==n;r--)t.call(e,n.value,r,this),n=n.prev},r.prototype.get=function(t){for(var e=0,n=this.head;null!==n&&e<t;e++)n=n.next;if(e===t&&null!==n)return n.value},r.prototype.getReverse=function(t){for(var e=0,n=this.tail;null!==n&&e<t;e++)n=n.prev;if(e===t&&null!==n)return n.value},r.prototype.map=function(t,e){e=e||this;for(var n=new r,i=this.head;null!==i;)n.push(t.call(e,i.value,this)),i=i.next;return n},r.prototype.mapReverse=function(t,e){e=e||this;for(var n=new r,i=this.tail;null!==i;)n.push(t.call(e,i.value,this)),i=i.prev;return n},r.prototype.reduce=function(t,e){var n,r=this.head;if(arguments.length>1)n=e;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");r=this.head.next,n=this.head.value}for(var i=0;null!==r;i++)n=t(n,r.value,i),r=r.next;return n},r.prototype.reduceReverse=function(t,e){var n,r=this.tail;if(arguments.length>1)n=e;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");r=this.tail.prev,n=this.tail.value}for(var i=this.length-1;null!==r;i--)n=t(n,r.value,i),r=r.prev;return n},r.prototype.toArray=function(){for(var t=new Array(this.length),e=0,n=this.head;null!==n;e++)t[e]=n.value,n=n.next;return t},r.prototype.toArrayReverse=function(){for(var t=new Array(this.length),e=0,n=this.tail;null!==n;e++)t[e]=n.value,n=n.prev;return t},r.prototype.slice=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var n=new r;if(e<t||e<0)return n;t<0&&(t=0),e>this.length&&(e=this.length);for(var i=0,a=this.head;null!==a&&i<t;i++)a=a.next;for(;null!==a&&i<e;i++,a=a.next)n.push(a.value);return n},r.prototype.sliceReverse=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var n=new r;if(e<t||e<0)return n;t<0&&(t=0),e>this.length&&(e=this.length);for(var i=this.length,a=this.tail;null!==a&&i>e;i--)a=a.prev;for(;null!==a&&i>t;i--,a=a.prev)n.push(a.value);return n},r.prototype.reverse=function(){for(var t=this.head,e=this.tail,n=t;null!==n;n=n.prev){var r=n.prev;n.prev=n.next,n.next=r}return this.head=e,this.tail=t,this};try{n(173)(r)}catch(t){}},173:function(t,e,n){"use strict";t.exports=function(t){t.prototype[Symbol.iterator]=function*(){for(let t=this.head;t;t=t.next)yield t.value}}},27:function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}n.d(e,"c",function(){return c}),n.d(e,"a",function(){return d}),n.d(e,"b",function(){return v});var o="updatePatterns",s="getPatterns",u="updateCalendars",l="getCalendars",h="getCalEvents",c=Object.freeze({updatePatterns:Symbol(o),getPatterns:Symbol(s),updateCalendars:Symbol(u),getCalendars:Symbol(l),getCalEvents:Symbol(h)});function f(t){switch(t){case c.updatePatterns:return o;case c.getPatterns:return s;case c.updateCalendars:return u;case c.getCalendars:return l;case c.getCalEvents:return h;default:console.error("unreachable")}}var d=function(){function t(e,n,i){r(this,t),this.id=e,this.type=n,this.data=i}var e,n,a;return e=t,(n=[{key:"genResp",value:function(e){return new t(this.id,this.type,e)}},{key:"deflate",value:function(){return{id:this.id,type:f(this.type),data:this.data}}}])&&i(e.prototype,n),a&&i(e,a),t}();a(d,"inflate",function(t){return new d(t.id,function(t){switch(t){case o:return c.updatePatterns;case s:return c.getPatterns;case u:return c.updateCalendars;case l:return c.getCalendars;case h:return c.getCalEvents;default:console.error("unreachable")}}(t.type),t.data)});var v=function t(e){var n=this;r(this,t),a(this,"sendMsg",function(t){var e,r,i=t.type,a=t.data,o=n.requestCallback,s=new Promise(function(t){e=t});return r=o.ids.length>0?o.ids.pop():o.maxId++,o.inFlight[r]=e,n.port.postMessage(new d(r,i,a).deflate()),s});var i=chrome.runtime.connect({name:e});i.onMessage.addListener(function(t){console.log(t);var e=(t.type,n.requestCallback),r=e.inFlight[t.id];console.assert(void 0!==r),e.ids.push(t.id),r(t)}),this.port=i,this.requestCallback={inFlight:{},ids:[],maxId:0}}},43:function(t,e,n){"use strict";n.d(e,"e",function(){return d}),n.d(e,"b",function(){return v}),n.d(e,"f",function(){return p}),n.d(e,"g",function(){return g}),n.d(e,"c",function(){return y}),n.d(e,"d",function(){return m}),n.d(e,"a",function(){return b});var r=n(109),i=n.n(r);function a(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function o(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function s(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!e||n.length!==e);r=!0);}catch(t){i=!0,a=t}finally{try{r||null==s.return||s.return()}finally{if(i)throw a}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var u="https://www.googleapis.com/calendar/v3",l=Object.freeze({invalidSyncToken:Symbol("invalidSyncToken"),notLoggedIn:Symbol("notLoggedIn"),notLoggedOut:Symbol("notLoggedOut"),otherError:Symbol("otherError")});function h(t){return Object.entries(t).filter(function(t){var e=s(t,2);e[0];return e[1]}).map(function(t){var e=s(t,2),n=e[0],r=e[1];return"".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(r))}).join("&")}var c=null;function f(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise(function(e){return chrome.identity.getAuthToken({interactive:t},function(t){return e([t,!chrome.runtime.lastError])})}).then(function(t){var e=s(t,2),n=e[0];if(e[1])return n;throw l.notLoggedIn})}function d(){return null===c?f(!1).then(function(){return c=!0}).catch(function(){return c=!1}).then(function(){return c}):Promise.resolve(c)}function v(){return d().then(function(t){if(t)return f(!1);throw l.notLoggedIn})}function p(){return d().then(function(t){if(t)throw l.notLoggedOut;return f(!0).then(function(){return c=!0})})}function g(){return v().then(function(t){return fetch("https://accounts.google.com/o/oauth2/revoke?".concat(h({token:t})),{method:"GET",async:!0}).then(function(e){return function(t){return new Promise(function(e){return chrome.identity.removeCachedAuthToken({token:t},function(){return e()})})}(t)})}).then(function(){return c=!1})}function y(t){return fetch("".concat(u,"/users/me/calendarList?").concat(h({access_token:t})),{method:"GET",async:!0}).then(function(t){return t.json()}).then(function(t){return t.items})}function m(t){return fetch("".concat(u,"/colors?").concat(h({access_token:t})),{method:"GET",async:!0}).then(function(t){return t.json()})}function w(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:100,s=[];return function n(c,f){return fetch("".concat(u,"/calendars/").concat(t,"/events?").concat(h({access_token:e,pageToken:c,syncToken:f,timeMin:r,timeMax:i,maxResults:a})),{method:"GET",async:!0}).then(function(t){if(200===t.status)return t.json();throw 410===t.status?l.invalidSyncToken:l.otherError}).then(function(t){return s.push.apply(s,o(t.items)),t.nextPageToken?n(t.nextPageToken,""):{nextSyncToken:t.nextSyncToken,results:s}})}("",n)}var b=function(){function t(e,n){var r=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{maxCachedItems:100,nDaysPerSlot:10,largeQuery:10};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.calId=e,this.name=n,this.syncToken="",this.cache=new i.a({max:a.maxCachedItems,dispose:function(t,e){return r.onRemoveSlot(t,e)}}),this.eventMeta={},this.options=a,this.divider=864e5*this.options.nDaysPerSlot}var e,n,r;return e=t,(n=[{key:"dateToCacheKey",value:function(t){return Math.floor(t/this.divider)}},{key:"dateRangeToCacheKeys",value:function(t){return{start:this.dateToCacheKey(t.start),end:this.dateToCacheKey(new Date(t.end.getTime()-1))}}},{key:"getSlot",value:function(t){if(this.cache.has(t))return this.cache.get(t);var e={};return this.cache.set(t,e),e}},{key:"onRemoveSlot",value:function(t,e){for(var n in e){console.assert(this.eventMeta[n]);var r=this.eventMeta[n].keys;r.delete(t),0===r.size&&delete this.eventMeta[n]}}},{key:"slotStartDate",value:function(t){return new Date(t*this.divider)}},{key:"slotEndDate",value:function(t){return new Date((t+1)*this.divider)}},{key:"addEvent",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.eventMeta.hasOwnProperty(t.id)&&this.removeEvent(t);for(var n=this.dateRangeToCacheKeys(t),r=n.start,i=n.end,a=this.cache.length,o=new Set,s=r;s<=i;s++)o.add(s),this.cache.has(s)||a++;if(this.eventMeta[t.id]={keys:o,summary:t.summary},e||!(a>this.options.maxCachedItems))if(r===i)this.getSlot(r)[t.id]={start:t.start,end:t.end,id:t.id};else{this.getSlot(r)[t.id]={start:t.start,end:this.slotEndDate(r),id:t.id},this.getSlot(i)[t.id]={start:this.slotStartDate(i),end:t.end,id:t.id};for(var u=r+1;u<i;u++)this.getSlot(u)[t.id]={start:this.slotStartDate(u),end:this.slotEndDate(u),id:t.id}}}},{key:"removeEvent",value:function(t){var e=this,n=this.eventMeta[t.id].keys;console.assert(n),n.forEach(function(n){return delete e.getSlot(n)[t.id]}),delete this.eventMeta[t.id]}},{key:"getSlotEvents",value:function(t,e,n){var r=this.getSlot(t),i=[];for(var a in r)r[a].start>=n||r[a].end<=e||i.push({id:a,start:r[a].start<e?e:r[a].start,end:r[a].end>n?n:r[a].end,summary:this.eventMeta[a].summary});return i}},{key:"getCachedEvents",value:function(t){for(var e=this.dateRangeToCacheKeys(t),n=e.start,r=e.end,i=this.getSlotEvents(n,t.start,t.end),a=n+1;a<r;a++){var s=this.getSlot(a);for(var u in s)i.push(s[u])}return r>n&&i.push.apply(i,o(this.getSlotEvents(r,t.start,t.end))),i}},{key:"sync",value:function(){var t=this;return this.token.then(function(e){return w(t.calId,e,t.syncToken).then(function(n){var r=n.results.map(function(n){return n.start?Promise.resolve(n):function(t,e,n){return fetch("".concat(u,"/calendars/").concat(t,"/events/").concat(e,"?").concat(h({access_token:n})),{method:"GET",async:!0}).then(function(t){return t.json()})}(t.calId,n.id,e)});return Promise.all(r).then(function(e){e.forEach(function(e){e.start=new Date(e.start.dateTime),e.end=new Date(e.end.dateTime),"confirmed"===e.status?t.addEvent(e):"cancelled"===e.status&&t.removeEvent(e)}),t.syncToken=n.nextSyncToken})})}).catch(function(e){if(e!==l.invalidSyncToken)throw e;t.syncToken="",t.sync()})}},{key:"getEvents",value:function(t,e){for(var n=this,r=this.dateRangeToCacheKeys({start:t,end:e}),i={},a=r.start;a<=r.end;a++)this.cache.has(a)||(i.hasOwnProperty("start")||(i.start=a),i.end=a);return console.log("start: ".concat(t," end: ").concat(e)),i.hasOwnProperty("start")?(console.assert(i.start<=i.end),i.end-i.start+1>this.options.largeQuery?(console.log("encounter large query, use direct fetch"),this.token.then(function(r){return w(n.calId,r,null,t.toISOString(),e.toISOString()).then(function(n){var r=[];return n.results.forEach(function(t){console.assert(t.start),t.start=new Date(t.start.dateTime),t.end=new Date(t.end.dateTime),r.push(t)}),r.filter(function(n){return!(n.start>=e||n.end<=t)}).map(function(n){return{id:n.id,start:n.start<t?t:n.start,end:n.end>e?e:n.end,summary:n.summary}})})})):(console.log("fetching short event list"),this.token.then(function(t){return w(n.calId,t,null,n.slotStartDate(i.start).toISOString(),n.slotEndDate(i.end).toISOString()).then(function(t){t.results.forEach(function(t){"confirmed"===t.status&&(console.assert(t.start),t.start=new Date(t.start.dateTime),t.end=new Date(t.end.dateTime),n.addEvent(t,!0))}),""===n.syncToken&&(n.syncToken=t.nextSyncToken)})}).then(function(){return n.sync()}).then(function(){return n.getCachedEvents({start:t,end:e})}))):(console.log("cache hit"),this.sync().then(function(){return n.getCachedEvents({start:t,end:e})}))}},{key:"token",get:function(){return v()}}])&&a(e.prototype,n),r&&a(e,r),t}()},848:function(t,e,n){"use strict";n.r(e);var r=n(43),i=n(27),a=[],o=[],s={},u={};chrome.runtime.onConnect.addListener(function(t){console.assert("main"==t.name),t.onMessage.addListener(function(e){var n=i.a.inflate(e);if(console.log(n),n.type==i.c.updatePatterns)"analyze"==n.data.id?o=n.data.patterns:a=n.data.patterns,t.postMessage(n.genResp(null));else if(n.type==i.c.getPatterns){var l;l="analyze"==n.data.id?o:a,t.postMessage(n.genResp(l))}else if(n.type==i.c.updateCalendars){for(var h in s=n.data)u.hasOwnProperty(h)||(u[h]=new r.a(h,s[h].summary));t.postMessage(n.genResp(null))}else if(n.type==i.c.getCalendars){var c=s;n.data.enabledOnly&&(c=Object.keys(s).filter(function(t){return s[t].enabled}).reduce(function(t,e){return t[e]=s[e],t},{})),t.postMessage(n.genResp(c))}else n.type==i.c.getCalEvents?u[n.data.id].getEvents(new Date(n.data.start),new Date(n.data.end)).catch(function(t){return console.log("cannot load calendar ".concat(n.data.id),t),[]}).then(function(e){console.log(e);var r=n.genResp(e.map(function(t){return{id:t.id,start:t.start.getTime(),end:t.end.getTime()}}));console.log(r),t.postMessage(r)}):console.error("unknown msg type")})}),chrome.browserAction.onClicked.addListener(function(){chrome.tabs.create({url:"index.html"})})}});