diff --git a/CHANGELOG.md b/CHANGELOG.md index 7315edb..280b1d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.0.4 - 2021-09-27 +### Added +- Added `README.md`. +- Added the option to set the closing and opening days via html for debugging purposes. + +### Fixed +- Fixed an issue where you really couldn't see what time it would close on the upcoming closing day when simulating the time. + ## 1.0.3 - 2021-09-26 ### Fixed - Fixed an issue where the `html` tag was not being hidden once the script had loaded. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ba0f6f7 --- /dev/null +++ b/README.md @@ -0,0 +1,271 @@ +# Sunset to Sunset +This script was developed to help with closing down of a website from sunset on Friday to sunset on Saturday. It displays a banner leading up to the Sabbath notifying visitors of the site when it will not be available. + +## Features +- Automatically show a banner on the top of your site notifying visitors when your site will close. +- Show a message during the Sabbath hours letting visitors know why you are closed and when your site will be back online. + +## Dependencies +The Sunset to Sunset script is dependent on a date time library called [Luxon](https://moment.github.io/luxon/#/) to calculate closing and opening times based off of the sunset times at the location that is entered. A goal is to eventually include this in the Sunset to Sunset script to avoid the need to load two separate scripts. + +## Installation +Whichever method you choose, either **Download** or **CDN**, it’s best to include all these files in the head so that they load right away. It’s not ideal to have render-blocking scripts in the head but the reason we recommend putting them in the head is to avoid the flash of the rendered page before the Sabbath message gets rendered. Feel free to submit a PR for improved installation methods. + +### Download +- **CSS** + - [sunset-to-sunset.css](https://unpkg.com/sunset-to-sunset@1.0.4/dist/assets/sunset-to-sunset.css), minified +- **Javascript** + - [luxon.min.js](https://cdn.jsdelivr.net/npm/luxon@2.0.2/build/global/luxon.min.js), minified library for working with dates and times in JavaScript. + - [polyfills-legacy.53eda98a.js](https://unpkg.com/sunset-to-sunset@1.0.4/dist/assets/polyfills-legacy.53eda98a.js), legacy bundle for outdated browser support. + - [sunset-to-sunset.min.js](https://unpkg.com/sunset-to-sunset@1.0.4/dist/assets/sunset-to-sunset.min.js), minified + - [sunset-to-sunset-legacy.min.js](https://unpkg.com/sunset-to-sunset@1.0.4/dist/assets/sunset-to-sunset-legacy.min.js), minified for legacy browsers + +``` html + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` + +### CDN +Link directly to the Sunset to Sunset files on [unpkg](https://unpkg.com/). +``` html + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` + + +## Usage +Sunset to sunset needs some initial configuration needed for it to work correctly for your location. It will work out of the box without configuration but it won't be for your location. + +## Custom Templates +Sunset to sunset has some built-in banner and message templates that will be shown at the appropriate times but sometimes you need to define your own wording. You can do that with the html `template` elements. + +### Special Template Tags +You can add the following two tags to your custom templates to render the closing time and the opening times. + +#### Closing Time +``` html + +``` +#### Opening Time +``` html + +``` + +### Formatting Times +There are three methods for setting the format on the calculated times in your custom templates: + +1. **[Token](#token):** Allows you to set what order each part of the date and time appear so it looks the same for everyone. +2. **[Locale](#locale):** Using whatever the user's browser's date/time format is set to. +3. **[Default](#default):** Basically let the script decide for you. + +#### Token +This is the most flexible formatting option as it allows you to define the order of the date/time parts and the formatting. To use the `token` format include the [special closing and opening time tags](#special-template-tags) with a `data-format-token` like the following: +``` html + + + +``` +> Note that you can add words in the token format by surrounding them with single quotes like in the example above. + +**Advanced formatting:** The [Luxon documentation has a full list of formatting tokens](https://moment.github.io/luxon/#/formatting?id=table-of-tokens) so that you can fine-tune your dates and times. + +#### Locale +With this option you can't arrange the parts of the date and time but you can decide how they are formatted. To use the `locale` format include the [special closing and opening time tags](#special-template-tags) with a `data-format-locale` like the following: +``` html + + + +``` + +#### Default +Include the [special closing and opening time tags](#special-template-tags) with no `data-format-locale` or `data-format-token` attributes and it will output the times with the token format of `cccc, LLLL d 'at' h:mm a ZZZZ`: +``` html + + + +``` + +### Banner Template +To define your custom banner template add the following snippet to your page, preferrably in the `` tag. + +``` html + +``` + +### Simple Message Template +If you want to just set a paragraph or two of text to appear during Sabbath then this is the template you'll want to use. + +To define your custom message template add the following snippet to your page, preferrably in the `` tag: +``` html + +``` + +### Full Message Template +If you want to have full control over the appearance and layout of the message then you'll want to use the full message template. Everything inside of this template will be output into the `
`. You will need to supply your own custom styling to add padding and centering of your message. + +To define your custom message template add the following snippet to your page, preferrably in the `` tag: +``` html + +``` + +## Defining the Settings +The settings are defined with an html `template` element. The template must have an `id` of `sts-settings` and the data attribute `data-settings` like below: + +``` html + +``` + +> **N.B.:** the `data-settings` attribute must be valid JSON. Keys need to be quoted, for example `"location":`. The attribute value uses single quotes ', but the JSON entities use double-quotes ". + +## Settings +You can pass an object of configuration options with the `data-settings` attribute in the template above. The allowed values are as follows: + +### `location` +- **Type:** `Object` +- **Default:** `{ "lat": 0, "long": 0 }` +- **Description:** An object defining the latitude and longitude of the location to calculate the sunset times. Both keys `lat` and `long` are expected to be of the `Number` type. +- **Example:** + ``` json + "location": { + "lat": 35.7686615, + "long": -87.4871698 + } + ``` + +### `guardDuration` +- **Type:** `Object` +- **Default:** `{ "minutes": 30 }` +- **Description:** This allows you to set the duration of the guard before and after the Sabbath. Whatever time you set here will determine when your Sabbath message will come up and go down. + - It accepts any object of options that can have any of the following keys: `years`, `quarters` (three months), `months`, `weeks`, `days`, `hours`, `minutes`, `seconds`, and `milliseconds`. It's recommended to the smaller units like `hours`, `minutes`, etc. though because otherwise you'll be calculating guard times that are into the next week. +- **Example:** If the sun set on Friday at 8:00pm and on Saturday at 8:02pm this would calculate the closing guard time at 5:15pm on Friday and the opening time at 10:47pm on Saturday: + ``` json + "guardDuration": { + "hours": 2, + "minutes": 45 + } + ``` + +### `bannerDuration` +- **Type:** `Object` +- **Default:** `{ "hours": 3 }` +- **Description:** This allows you to set the duration that the banner will be visible before the Sabbath message appears. + - It accepts any object of options that can have any of the following keys: `years`, `quarters` (three months), `months`, `weeks`, `days`, `hours`, `minutes`, `seconds`, and `milliseconds`. Generally you will only need to use `hours` and `minutes` though. +- **Example:** This would show the banner 3 hours and 3 minutes before the calculated closing guard time determined by the `guardDuration` option: + ``` json + "bannerDuration": { + "hours": 3, + "minutes": 30 + } + ``` + +### `simulateTime` +- **Type:** `Boolean | String` +- **Default:** `false` +- **Description:** This allows you to simulate the time to see how the plugin works at different times of the week and different times of the day. The accepted values are: + - `preparation-day` + - `banner-up` + - `during-sabbath` + - `after-sabbath` +- **Example:** This would show the Sabbath message as it would appear during the Sabbath hours. + ``` json + "simulateTime": "during-sabbath" + ``` + +### `debug` +- **Type:** `Boolean` +- **Default:** `false` +- **Description:** When this is set to `true` it will output the calculated times to the console. **N.B.:** this will only show the calculated times if the current weekday is equal to the Friday or Saturday or if the `simulateTime` setting is not `false`. This is done so that it doesn't need to calculate the sunset times unnessarily during the week. +- **Example:** This would output the calculated times to the console. + ``` json + "debug": "true" + ``` \ No newline at end of file diff --git a/dist/assets/sunset-to-sunset-legacy.min.js b/dist/assets/sunset-to-sunset-legacy.min.js index 98deab3..2751155 100644 --- a/dist/assets/sunset-to-sunset-legacy.min.js +++ b/dist/assets/sunset-to-sunset-legacy.min.js @@ -1,2 +1,2 @@ -!function(){var t=document.createElement("style");t.innerHTML='.sts-banner{--tw-bg-opacity: 1;background-color:rgba(251,191,36,var(--tw-bg-opacity));position:relative;padding:.75rem;text-align:center;font-family:Inter var,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"}.sts-banner .sts-closing-time,.sts-banner .sts-opening-time{font-weight:600}html.sts-during-sabbath,html.sts-during-sabbath body{overflow:hidden}html.sts-during-sabbath body{max-height:100vh}.sts-full-message__container{top:0px;right:0px;bottom:0px;left:0px;position:absolute;--tw-bg-opacity: 1;background-color:rgba(255,255,255,var(--tw-bg-opacity));pointer-events:auto;overflow-y:scroll;z-index:500}.sts-full-message__heading{margin-bottom:1rem;font-size:3rem;font-weight:600}.sts-layout{display:flex;flex-wrap:wrap;margin-left:-.5rem;margin-right:-.5rem}.sts-layout .sts-layout__item{padding-left:.5rem;padding-right:.5rem}.sts-modal{width:90%;margin-left:auto;margin-right:auto;margin-top:7%;max-width:640px;justify-content:center}.sts-message-area{font-size:1rem;line-height:1.5rem;width:100%;text-align:center;padding-bottom:1rem}.sts-time-area{width:100%;text-align:center;border-top:1px solid lightgrey;padding-top:1rem}\n',document.head.appendChild(t),System.register([],(function(){"use strict";return{execute:function(){const t=(t,e)=>Object.assign(t,e),e=(t,e)=>{const n="cccc, LLLL d 'at' h:mm a ZZZZ";for(let s=0;s{console.log("Intializing Sunset to Sunset...");const n=luxon.DateTime,s=luxon.Duration,o=n.now();let i={};i["Current Time"]={Date:o.toLocaleString(n.DATE_FULL),Time:o.toLocaleString(n.TIME_WITH_SHORT_OFFSET)};const a=5==o.weekday||6==o.weekday,l=document.getElementsByTagName("html")[0],r=document.querySelector("template#sts-settings");let c=null!=r?JSON.parse(r.dataset.settings):{};c=t(t({},{guardDuration:{minutes:30},messageDuration:{minutes:60},location:{lat:0,long:0},simulateTime:!1,debug:!1}),c),(a||c.simulateTime)&&(l.style.display="none"),c.simulateTime&&console.warn("%cThe `simulateTime` option is enabled for the Sunset to Sunset plugin. Remember to disable this option once you are done verifying the settings.","font-size: 16px"),c.debug&&(console.group("Sunset to Sunset intialized with the following options:"),console.dir(c),console.groupEnd());const m=()=>c.location,d=async t=>{const e=t.split("T")[0],s=await fetch("https://api.sunrise-sunset.org/json?&lat="+m().lat+"&lng="+m().long+"&date="+e+"&formatted=0"),o=await s.json();return n.fromISO(o.results.sunset)},u=()=>{let t;t=c.simulateTime?0:5-o.weekday;const e=n.fromISO(o.plus({days:t})).toString();return d(e)},g=()=>{let t;t=c.simulateTime?1:6-o.weekday;const e=n.fromISO(o.plus({days:t})).toString();return d(e)},p=()=>c.guardDuration,b=t=>t.minus(s.fromObject(c.messageDuration)),f=(t,e)=>{let n;return"closing"==e&&(n=t.minus(p())),"opening"==e&&(n=t.plus(p())),n};a||c.simulateTime?(async()=>{const t=Promise.all([u(),g()]);return await t})().then((([t,s])=>{const a=f(t,"closing"),r=f(s,"opening");let m=!1,d=!1,u=!1,g=!1;if(c.simulateTime)switch(c.simulateTime){case"preparation-day":m=!0;break;case"banner-up":d=!0;break;case"during-sabbath":u=!0;break;case"after-sabbath":g=!0}else m=ob(a)&&o=a&&o<=r&&o.weekday>=5,g=o>r&&o>=6;if(m){const t=b(a).diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(d){((t,n)=>{const s=document.querySelector("template#sts-banner-template");let o;if(s)o=s;else{let t=document.createElement("template");t.innerHTML='\n\t\t\t
\n\t\t\t\tBecause of religious beliefs our store will be closed over the Sabbath hours.\n\t\t\t\tClosing on and will re-open on .\n\t\t\t
\n\t\t',o=t}const i=o.content.cloneNode(!0),a=i.querySelectorAll(".sts-closing-time");e(a,t);const l=i.querySelectorAll(".sts-opening-time");e(l,n),document.body.insertBefore(i,document.body.firstChild)})(a,r);const t=a.diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(u){(t=>{const n=document.querySelector("template#sts-full-message-template"),s=document.querySelector("template#sts-message-template"),o=n||s;let i;if(o)i=o.content.cloneNode(!0),i=i.firstElementChild;else{let t=document.createElement("div");t.innerHTML="\n\t\t\t

\n\t\t\t\tIn a world that seems to be spinning faster every day, we choose to stop \n\t\t\t\tand rest every Sabbath (Saturday). It’s a day for us to relax, refresh, \n\t\t\t\trefocus and worship; worship a God who loved us so much that He built a \n\t\t\t\tday of rest into Creation week and then commanded us to keep it \n\t\t\t\t(knowing we probably wouldn’t do it otherwise—even though it is for \n\t\t\t\tour best good).\n\t\t\t

\n\t\t",i=t}let a=document.createElement("template");a.innerHTML='\n\t\t
\n\n\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t

Sabbath

\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t

\n\t\t\t\t\t\tWe will re-open on .\n\t\t\t\t\t

\n\t\t\t\t
\n\t\t\t
\n\t\t\n\t\t
\n\t';const l=a.content.cloneNode(!0);if(n){let t=l.querySelector(".sts-full-message__container");for(;t.firstElementChild;)t.removeChild(t.firstChild);t.insertBefore(i,null)}else s&&l.querySelector(".sts-message-area").insertBefore(i,null);document.getElementsByTagName("html")[0].classList.add("sts-during-sabbath");const r=l.querySelectorAll(".sts-opening-time");e(r,t),document.body.insertBefore(l,document.body.firstChild)})(r);const t=r.diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(l.style.display="block",c.debug){let e={Enabled:{"Preparation day":m,"Banner up":d,"During the Sabbath":u,"After Sabbath":g}};console.group("Sunset to Sunset time checks"),console.table(e),console.groupEnd(),i["Banner up"]={Date:b(a).toLocaleString(n.DATE_FULL),Time:b(a).toLocaleString(n.TIME_WITH_SHORT_OFFSET)},i["Closing guard"]={Date:a.toLocaleString(n.DATE_FULL),Time:a.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},i["Closing sunset"]={Date:t.toLocaleString(n.DATE_FULL),Time:t.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},i["Opening sunset"]={Date:s.toLocaleString(n.DATE_FULL),Time:s.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},i["Opening guard"]={Date:r.toLocaleString(n.DATE_FULL),Time:r.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},console.group("Sunset to Sunset times"),console.table(i),console.groupEnd()}})):console.log("Sunset to Sunset: Exiting because today is not closing day")})()}}}))}(); +!function(){var t=document.createElement("style");t.innerHTML='.sts-banner{--tw-bg-opacity: 1;background-color:rgba(251,191,36,var(--tw-bg-opacity));position:relative;padding:.75rem;text-align:center;font-family:Inter var,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"}.sts-banner .sts-closing-time,.sts-banner .sts-opening-time{font-weight:600}html.sts-during-sabbath,html.sts-during-sabbath body{overflow:hidden}html.sts-during-sabbath body{max-height:100vh}.sts-full-message__container{top:0px;right:0px;bottom:0px;left:0px;position:absolute;--tw-bg-opacity: 1;background-color:rgba(255,255,255,var(--tw-bg-opacity));pointer-events:auto;overflow-y:scroll;z-index:500}.sts-full-message__heading{margin-bottom:1rem;font-size:3rem;font-weight:600}.sts-layout{display:flex;flex-wrap:wrap;margin-left:-.5rem;margin-right:-.5rem}.sts-layout .sts-layout__item{padding-left:.5rem;padding-right:.5rem}.sts-modal{width:90%;margin-left:auto;margin-right:auto;margin-top:7%;max-width:640px;justify-content:center}.sts-message-area{font-size:1rem;line-height:1.5rem;width:100%;text-align:center;padding-bottom:1rem}.sts-time-area{width:100%;text-align:center;border-top:1px solid lightgrey;padding-top:1rem}\n',document.head.appendChild(t),System.register([],(function(){"use strict";return{execute:function(){const t=(t,e)=>Object.assign(t,e),e=(t,e)=>{const n="cccc, LLLL d 'at' h:mm a ZZZZ";for(let s=0;s{console.log("Intializing Sunset to Sunset...");const n=luxon.DateTime,s=luxon.Duration,o=n.now();let a={};a["Current Time"]={Date:o.toLocaleString(n.DATE_FULL),Time:o.toLocaleString(n.TIME_WITH_SHORT_OFFSET)};const i=document.querySelector("template#sts-settings");let l={};i.dataset.days&&(l=JSON.parse(i.dataset.days));l=t(t({},{closing:5,opening:6}),l);const r=()=>l.closing,c=()=>l.opening,m=o.weekday==r()||o.weekday==c();let d={};i.dataset.settings&&(d=JSON.parse(i.dataset.settings)),d=t(t({},{guardDuration:{minutes:30},bannerDuration:{hours:3},location:{lat:0,long:0},simulateTime:!1,debug:!1}),d);const u=document.getElementsByTagName("html")[0];(m||d.simulateTime)&&(u.style.display="none"),d.simulateTime&&console.warn("%cThe `simulateTime` option is enabled for the Sunset to Sunset plugin. Remember to disable this option once you are done verifying the settings.","font-size: 16px"),d.debug&&(console.group("Sunset to Sunset intialized with the following options:"),console.dir(d),console.groupEnd());const g=()=>d.location,p=async t=>{const e=t.split("T")[0],s=await fetch("https://api.sunrise-sunset.org/json?&lat="+g().lat+"&lng="+g().long+"&date="+e+"&formatted=0"),o=await s.json();return n.fromISO(o.results.sunset)},b=()=>{let t=r()-o.weekday;const e=n.fromISO(o.plus({days:t})).toString();return p(e)},f=()=>{let t=c()-o.weekday;const e=n.fromISO(o.plus({days:t})).toString();return p(e)},h=()=>d.guardDuration,y=t=>t.minus(s.fromObject(d.bannerDuration)),S=(t,e)=>{let n;return"closing"==e&&(n=t.minus(h())),"opening"==e&&(n=t.plus(h())),n};if(m||d.simulateTime){let t=!1,s=!1,i=!1,l=!1;if(d.simulateTime)switch(d.simulateTime){case"preparation-day":t=!0;break;case"banner-up":s=!0;break;case"during-sabbath":i=!0;break;case"after-sabbath":l=!0}(async()=>{const t=Promise.all([b(),f()]);return await t})().then((([m,g])=>{const p=S(m,"closing"),b=S(g,"opening");if(d.simulateTime||(t=oy(p)&&o=p&&o<=b&&o.weekday>=r(),l=o>b&&o>=c()),t){const t=y(p).diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(s){((t,n)=>{const s=document.querySelector("template#sts-banner-template");let o;if(s)o=s;else{let t=document.createElement("template");t.innerHTML='\n\t\t\t
\n\t\t\t\tBecause of religious beliefs our store will be closed over the Sabbath hours.\n\t\t\t\tClosing on and will re-open on .\n\t\t\t
\n\t\t',o=t}const a=o.content.cloneNode(!0),i=a.querySelectorAll(".sts-closing-time");e(i,t);const l=a.querySelectorAll(".sts-opening-time");e(l,n),document.body.insertBefore(a,document.body.firstChild)})(p,b);const t=p.diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(i){(t=>{const n=document.querySelector("template#sts-full-message-template"),s=document.querySelector("template#sts-message-template"),o=n||s;let a;if(o)a=o.content.cloneNode(!0),a=a.firstElementChild;else{let t=document.createElement("div");t.innerHTML="\n\t\t\t

\n\t\t\t\tIn a world that seems to be spinning faster every day, we choose to stop \n\t\t\t\tand rest every Sabbath (Saturday). It’s a day for us to relax, refresh, \n\t\t\t\trefocus and worship; worship a God who loved us so much that He built a \n\t\t\t\tday of rest into Creation week and then commanded us to keep it \n\t\t\t\t(knowing we probably wouldn’t do it otherwise—even though it is for \n\t\t\t\tour best good).\n\t\t\t

\n\t\t",a=t}let i=document.createElement("template");i.innerHTML='\n\t\t
\n\n\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t

Sabbath

\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t

\n\t\t\t\t\t\tWe will re-open on .\n\t\t\t\t\t

\n\t\t\t\t
\n\t\t\t
\n\t\t\n\t\t
\n\t';const l=i.content.cloneNode(!0);if(n){let t=l.querySelector(".sts-full-message__container");for(;t.firstElementChild;)t.removeChild(t.firstChild);t.insertBefore(a,null)}else s&&l.querySelector(".sts-message-area").insertBefore(a,null);document.getElementsByTagName("html")[0].classList.add("sts-during-sabbath");const r=l.querySelectorAll(".sts-opening-time");e(r,t),document.body.insertBefore(l,document.body.firstChild)})(b);const t=b.diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(u.style.display="block",d.debug){let e={Enabled:{"Preparation day":t,"Banner up":s,"During the Sabbath":i,"After Sabbath":l}};console.group("Sunset to Sunset time checks"),console.table(e),console.groupEnd(),a["Banner up"]={Date:y(p).toLocaleString(n.DATE_FULL),Time:y(p).toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Closing guard"]={Date:p.toLocaleString(n.DATE_FULL),Time:p.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Closing sunset"]={Date:m.toLocaleString(n.DATE_FULL),Time:m.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Opening sunset"]={Date:g.toLocaleString(n.DATE_FULL),Time:g.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Opening guard"]={Date:b.toLocaleString(n.DATE_FULL),Time:b.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},console.group("Sunset to Sunset times"),console.table(a),console.groupEnd()}}))}else u.style.display="block",console.log("Sunset to Sunset: Exiting because today is not closing day")})()}}}))}(); //# sourceMappingURL=sunset-to-sunset-legacy.min.js.map diff --git a/dist/assets/sunset-to-sunset.min.js b/dist/assets/sunset-to-sunset.min.js index 673f9f8..9626125 100644 --- a/dist/assets/sunset-to-sunset.min.js +++ b/dist/assets/sunset-to-sunset.min.js @@ -1,2 +1,2 @@ -export function __vite_legacy_guard(){import("data:text/javascript,")}const t=(t,e)=>Object.assign(t,e),e=(t,e)=>{const n="cccc, LLLL d 'at' h:mm a ZZZZ";for(let s=0;s{console.log("Intializing Sunset to Sunset...");const n=luxon.DateTime,s=luxon.Duration,o=n.now();let a={};a["Current Time"]={Date:o.toLocaleString(n.DATE_FULL),Time:o.toLocaleString(n.TIME_WITH_SHORT_OFFSET)};const i=5==o.weekday||6==o.weekday,l=document.getElementsByTagName("html")[0],r=document.querySelector("template#sts-settings");let c=null!=r?JSON.parse(r.dataset.settings):{};c=t(t({},{guardDuration:{minutes:30},messageDuration:{minutes:60},location:{lat:0,long:0},simulateTime:!1,debug:!1}),c),(i||c.simulateTime)&&(l.style.display="none"),c.simulateTime&&console.warn("%cThe `simulateTime` option is enabled for the Sunset to Sunset plugin. Remember to disable this option once you are done verifying the settings.","font-size: 16px"),c.debug&&(console.group("Sunset to Sunset intialized with the following options:"),console.dir(c),console.groupEnd());const u=()=>c.location,m=async t=>{const e=t.split("T")[0],s=await fetch("https://api.sunrise-sunset.org/json?&lat="+u().lat+"&lng="+u().long+"&date="+e+"&formatted=0"),o=await s.json();return n.fromISO(o.results.sunset)},d=()=>{let t;t=c.simulateTime?0:5-o.weekday;const e=n.fromISO(o.plus({days:t})).toString();return m(e)},g=()=>{let t;t=c.simulateTime?1:6-o.weekday;const e=n.fromISO(o.plus({days:t})).toString();return m(e)},p=()=>c.guardDuration,S=t=>t.minus(s.fromObject(c.messageDuration)),T=(t,e)=>{let n;return"closing"==e&&(n=t.minus(p())),"opening"==e&&(n=t.plus(p())),n};i||c.simulateTime?(async()=>{const t=Promise.all([d(),g()]);return await t})().then((([t,s])=>{const i=T(t,"closing"),r=T(s,"opening");let u=!1,m=!1,d=!1,g=!1;if(c.simulateTime)switch(c.simulateTime){case"preparation-day":u=!0;break;case"banner-up":m=!0;break;case"during-sabbath":d=!0;break;case"after-sabbath":g=!0}else u=oS(i)&&o=i&&o<=r&&o.weekday>=5,g=o>r&&o>=6;if(u){const t=S(i).diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(m){((t,n)=>{const s=document.querySelector("template#sts-banner-template");let o;if(s)o=s;else{let t=document.createElement("template");t.innerHTML='\n\t\t\t
\n\t\t\t\tBecause of religious beliefs our store will be closed over the Sabbath hours.\n\t\t\t\tClosing on and will re-open on .\n\t\t\t
\n\t\t',o=t}const a=o.content.cloneNode(!0),i=a.querySelectorAll(".sts-closing-time");e(i,t);const l=a.querySelectorAll(".sts-opening-time");e(l,n),document.body.insertBefore(a,document.body.firstChild)})(i,r);const t=i.diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(d){(t=>{const n=document.querySelector("template#sts-full-message-template"),s=document.querySelector("template#sts-message-template"),o=n||s;let a;if(o)a=o.content.cloneNode(!0),a=a.firstElementChild;else{let t=document.createElement("div");t.innerHTML="\n\t\t\t

\n\t\t\t\tIn a world that seems to be spinning faster every day, we choose to stop \n\t\t\t\tand rest every Sabbath (Saturday). It’s a day for us to relax, refresh, \n\t\t\t\trefocus and worship; worship a God who loved us so much that He built a \n\t\t\t\tday of rest into Creation week and then commanded us to keep it \n\t\t\t\t(knowing we probably wouldn’t do it otherwise—even though it is for \n\t\t\t\tour best good).\n\t\t\t

\n\t\t",a=t}let i=document.createElement("template");i.innerHTML='\n\t\t
\n\n\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t

Sabbath

\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t

\n\t\t\t\t\t\tWe will re-open on .\n\t\t\t\t\t

\n\t\t\t\t
\n\t\t\t
\n\t\t\n\t\t
\n\t';const l=i.content.cloneNode(!0);if(n){let t=l.querySelector(".sts-full-message__container");for(;t.firstElementChild;)t.removeChild(t.firstChild);t.insertBefore(a,null)}else s&&l.querySelector(".sts-message-area").insertBefore(a,null);document.getElementsByTagName("html")[0].classList.add("sts-during-sabbath");const r=l.querySelectorAll(".sts-opening-time");e(r,t),document.body.insertBefore(l,document.body.firstChild)})(r);const t=r.diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(l.style.display="block",c.debug){let e={Enabled:{"Preparation day":u,"Banner up":m,"During the Sabbath":d,"After Sabbath":g}};console.group("Sunset to Sunset time checks"),console.table(e),console.groupEnd(),a["Banner up"]={Date:S(i).toLocaleString(n.DATE_FULL),Time:S(i).toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Closing guard"]={Date:i.toLocaleString(n.DATE_FULL),Time:i.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Closing sunset"]={Date:t.toLocaleString(n.DATE_FULL),Time:t.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Opening sunset"]={Date:s.toLocaleString(n.DATE_FULL),Time:s.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Opening guard"]={Date:r.toLocaleString(n.DATE_FULL),Time:r.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},console.group("Sunset to Sunset times"),console.table(a),console.groupEnd()}})):console.log("Sunset to Sunset: Exiting because today is not closing day")})(); +export function __vite_legacy_guard(){import("data:text/javascript,")}const t=(t,e)=>Object.assign(t,e),e=(t,e)=>{const n="cccc, LLLL d 'at' h:mm a ZZZZ";for(let s=0;s{console.log("Intializing Sunset to Sunset...");const n=luxon.DateTime,s=luxon.Duration,o=n.now();let a={};a["Current Time"]={Date:o.toLocaleString(n.DATE_FULL),Time:o.toLocaleString(n.TIME_WITH_SHORT_OFFSET)};const i=document.querySelector("template#sts-settings");let l={};i.dataset.days&&(l=JSON.parse(i.dataset.days));l=t(t({},{closing:5,opening:6}),l);const r=()=>l.closing,c=()=>l.opening,d=o.weekday==r()||o.weekday==c();let u={};i.dataset.settings&&(u=JSON.parse(i.dataset.settings)),u=t(t({},{guardDuration:{minutes:30},bannerDuration:{hours:3},location:{lat:0,long:0},simulateTime:!1,debug:!1}),u);const m=document.getElementsByTagName("html")[0];(d||u.simulateTime)&&(m.style.display="none"),u.simulateTime&&console.warn("%cThe `simulateTime` option is enabled for the Sunset to Sunset plugin. Remember to disable this option once you are done verifying the settings.","font-size: 16px"),u.debug&&(console.group("Sunset to Sunset intialized with the following options:"),console.dir(u),console.groupEnd());const g=()=>u.location,p=async t=>{const e=t.split("T")[0],s=await fetch("https://api.sunrise-sunset.org/json?&lat="+g().lat+"&lng="+g().long+"&date="+e+"&formatted=0"),o=await s.json();return n.fromISO(o.results.sunset)},S=()=>{let t=r()-o.weekday;const e=n.fromISO(o.plus({days:t})).toString();return p(e)},T=()=>{let t=c()-o.weekday;const e=n.fromISO(o.plus({days:t})).toString();return p(e)},f=()=>u.guardDuration,b=t=>t.minus(s.fromObject(u.bannerDuration)),y=(t,e)=>{let n;return"closing"==e&&(n=t.minus(f())),"opening"==e&&(n=t.plus(f())),n};if(d||u.simulateTime){let t=!1,s=!1,i=!1,l=!1;if(u.simulateTime)switch(u.simulateTime){case"preparation-day":t=!0;break;case"banner-up":s=!0;break;case"during-sabbath":i=!0;break;case"after-sabbath":l=!0}(async()=>{const t=Promise.all([S(),T()]);return await t})().then((([d,g])=>{const p=y(d,"closing"),S=y(g,"opening");if(u.simulateTime||(t=ob(p)&&o=p&&o<=S&&o.weekday>=r(),l=o>S&&o>=c()),t){const t=b(p).diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(s){((t,n)=>{const s=document.querySelector("template#sts-banner-template");let o;if(s)o=s;else{let t=document.createElement("template");t.innerHTML='\n\t\t\t
\n\t\t\t\tBecause of religious beliefs our store will be closed over the Sabbath hours.\n\t\t\t\tClosing on and will re-open on .\n\t\t\t
\n\t\t',o=t}const a=o.content.cloneNode(!0),i=a.querySelectorAll(".sts-closing-time");e(i,t);const l=a.querySelectorAll(".sts-opening-time");e(l,n),document.body.insertBefore(a,document.body.firstChild)})(p,S);const t=p.diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(i){(t=>{const n=document.querySelector("template#sts-full-message-template"),s=document.querySelector("template#sts-message-template"),o=n||s;let a;if(o)a=o.content.cloneNode(!0),a=a.firstElementChild;else{let t=document.createElement("div");t.innerHTML="\n\t\t\t

\n\t\t\t\tIn a world that seems to be spinning faster every day, we choose to stop \n\t\t\t\tand rest every Sabbath (Saturday). It’s a day for us to relax, refresh, \n\t\t\t\trefocus and worship; worship a God who loved us so much that He built a \n\t\t\t\tday of rest into Creation week and then commanded us to keep it \n\t\t\t\t(knowing we probably wouldn’t do it otherwise—even though it is for \n\t\t\t\tour best good).\n\t\t\t

\n\t\t",a=t}let i=document.createElement("template");i.innerHTML='\n\t\t
\n\n\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t

Sabbath

\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t

\n\t\t\t\t\t\tWe will re-open on .\n\t\t\t\t\t

\n\t\t\t\t
\n\t\t\t
\n\t\t\n\t\t
\n\t';const l=i.content.cloneNode(!0);if(n){let t=l.querySelector(".sts-full-message__container");for(;t.firstElementChild;)t.removeChild(t.firstChild);t.insertBefore(a,null)}else s&&l.querySelector(".sts-message-area").insertBefore(a,null);document.getElementsByTagName("html")[0].classList.add("sts-during-sabbath");const r=l.querySelectorAll(".sts-opening-time");e(r,t),document.body.insertBefore(l,document.body.firstChild)})(S);const t=S.diff(o,"milliseconds").toObject();t.milliseconds>=0&&setTimeout((()=>{location.reload()}),t.milliseconds)}if(m.style.display="block",u.debug){let e={Enabled:{"Preparation day":t,"Banner up":s,"During the Sabbath":i,"After Sabbath":l}};console.group("Sunset to Sunset time checks"),console.table(e),console.groupEnd(),a["Banner up"]={Date:b(p).toLocaleString(n.DATE_FULL),Time:b(p).toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Closing guard"]={Date:p.toLocaleString(n.DATE_FULL),Time:p.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Closing sunset"]={Date:d.toLocaleString(n.DATE_FULL),Time:d.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Opening sunset"]={Date:g.toLocaleString(n.DATE_FULL),Time:g.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},a["Opening guard"]={Date:S.toLocaleString(n.DATE_FULL),Time:S.toLocaleString(n.TIME_WITH_SHORT_OFFSET)},console.group("Sunset to Sunset times"),console.table(a),console.groupEnd()}}))}else m.style.display="block",console.log("Sunset to Sunset: Exiting because today is not closing day")})(); //# sourceMappingURL=sunset-to-sunset.min.js.map diff --git a/dist/manifest.json b/dist/manifest.json index c47ff1d..28652b5 100644 --- a/dist/manifest.json +++ b/dist/manifest.json @@ -1,7 +1,7 @@ { - "js/main-legacy.js": { + "js/sunset-to-sunset-legacy.js": { "file": "assets/sunset-to-sunset-legacy.min.js", - "src": "js/main-legacy.js", + "src": "js/sunset-to-sunset-legacy.js", "isEntry": true }, "tests/index-legacy.html": { @@ -9,7 +9,7 @@ "src": "tests/index-legacy.html", "isEntry": true, "imports": [ - "js/main-legacy.js" + "js/sunset-to-sunset-legacy.js" ] }, "../vite/legacy-polyfills": { @@ -17,9 +17,9 @@ "src": "../vite/legacy-polyfills", "isEntry": true }, - "js/main.js": { + "js/sunset-to-sunset.js": { "file": "assets/sunset-to-sunset.min.js", - "src": "js/main.js", + "src": "js/sunset-to-sunset.js", "isEntry": true, "css": [ "assets/sunset-to-sunset.css" @@ -30,7 +30,7 @@ "src": "tests/index.html", "isEntry": true, "imports": [ - "js/main.js" + "js/sunset-to-sunset.js" ], "css": [ "assets/test.css" diff --git a/dist/tests/index.html b/dist/tests/index.html index fb759e0..64d3497 100644 --- a/dist/tests/index.html +++ b/dist/tests/index.html @@ -846,17 +846,17 @@

"lat": 35.750413, "long": -87.229406 }, - "messageDuration": { + "bannerDuration": { "hours": 0, "minutes": 30 }, "guardDuration": { - "hours": -1, - "minutes": -5 + "hours": 3, + "minutes": 50 }, "debug": true, - "simulateTime": "during-sabbath" - }'> + "simulateTime": "banner-up" + }' data-days='{ "closing": 1, "opening": 2 }'> -