From 58ae4190d6a1cd4957f3fc678a566692ab1b013e Mon Sep 17 00:00:00 2001 From: "wendall.hershberger" Date: Wed, 21 Oct 2020 09:04:39 -0400 Subject: [PATCH 1/3] Add dlp, hkdl, and shdl. Extract css out. --- css/styles.css | 59 ++++++++++++++ dlp.html | 217 +++++++++++++++++++++++++++++++++++++++++++++++++ dlr.html | 62 +------------- hkdl.html | 217 +++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 62 +------------- shdr.html | 217 +++++++++++++++++++++++++++++++++++++++++++++++++ tdr.html | 62 +------------- 7 files changed, 713 insertions(+), 183 deletions(-) create mode 100644 css/styles.css create mode 100644 dlp.html create mode 100644 hkdl.html create mode 100644 shdr.html diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..03a5567 --- /dev/null +++ b/css/styles.css @@ -0,0 +1,59 @@ +body { + background-color: #c4ddfc; + font-family: 'Open Sans', sans-serif; + } + + h2 { + font-family: 'Open Sans Condensed', sans-serif; + font-weight: 700; + } + + .card { + min-height: 508px; + } + + .card ul { + list-style: none; + margin: 0; + padding: 0; + } + + .card li { + float: left; + width: 50%; + } + + .card li .image { + background-position: 50%; + background-size: cover; + border: 1px solid #dcdcdc; + width: 100px; + height: 75px; + float: left; + margin-right: 20px; + } + + .card-header { + background: #1b7cf5; + color: #ffffff; + font-size: 24px; + font-weight: bold; + } + + .container { + margin-top: 20px; + } + + .header { + border-bottom: 1px solid #dcdcdc; + font-weight: bold; + } + + h3 small { + font-size: 12px; + } + + #weather_section { + margin-bottom: 32px; + margin-top: 32px; + } \ No newline at end of file diff --git a/dlp.html b/dlp.html new file mode 100644 index 0000000..796726d --- /dev/null +++ b/dlp.html @@ -0,0 +1,217 @@ + + + + + + + + + + +
+
+
+ Today at Disneyland Paris - + +
+
+
+
+

Park Hours

+
    +
    +
    +

    + Weather + + Powered by Dark Sky + +

    +
    +
    +
    + Presented by wdwnt.jp +
    +
    +
    + + + + + + diff --git a/dlr.html b/dlr.html index b01cd20..65c7b7c 100644 --- a/dlr.html +++ b/dlr.html @@ -16,67 +16,7 @@ integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" /> - +
    diff --git a/hkdl.html b/hkdl.html new file mode 100644 index 0000000..1820473 --- /dev/null +++ b/hkdl.html @@ -0,0 +1,217 @@ + + + + + + + + + + +
    +
    +
    + Today at Hong Kong Disneyland - + +
    +
    +
    +
    +

    Park Hours

    +
      +
      +
      +

      + Weather + + Powered by Dark Sky + +

      +
      +
      +
      + Presented by wdwnt.jp +
      +
      +
      + + + + + + diff --git a/index.html b/index.html index 908eb12..303273c 100644 --- a/index.html +++ b/index.html @@ -16,67 +16,7 @@ integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" /> - +
      diff --git a/shdr.html b/shdr.html new file mode 100644 index 0000000..ce538ae --- /dev/null +++ b/shdr.html @@ -0,0 +1,217 @@ + + + + + + + + + + +
      +
      +
      + Today at Shanghai Disney Resort - + +
      +
      +
      +
      +

      Park Hours

      +
        +
        +
        +

        + Weather + + Powered by Dark Sky + +

        +
        +
        +
        + Presented by wdwnt.jp +
        +
        +
        + + + + + + diff --git a/tdr.html b/tdr.html index 2b81279..c02022b 100644 --- a/tdr.html +++ b/tdr.html @@ -16,67 +16,7 @@ integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" /> - +
        From 846d4a7c8db35d8e77c6cdbbe3f94cf7fc5112dc Mon Sep 17 00:00:00 2001 From: "wendall.hershberger" Date: Wed, 21 Oct 2020 10:45:30 -0400 Subject: [PATCH 2/3] refactor everything --- app.js | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++++ dlr.html | 130 ++---------------------------------------- hkdl.html | 150 +----------------------------------------------- index.html | 161 +++------------------------------------------------- shdr.html | 150 +----------------------------------------------- tdr.html | 150 +----------------------------------------------- 6 files changed, 181 insertions(+), 724 deletions(-) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..eaa7024 --- /dev/null +++ b/app.js @@ -0,0 +1,164 @@ + +let source = document.getElementById('weather-card-template').innerHTML; +const weather_card_template = Handlebars.compile(source); + +const getParameterByName = name => { +let url = window.location.href; +name = name.replace(/[\[\]]/g, '\\$&'); +let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), + results = regex.exec(url); +if (!results) return null; +if (!results[2]) return ''; +return decodeURIComponent(results[2].replace(/\+/g, ' ')); +}; + +const fahrenheitToCelsius = value => { +return ((value - 32) * (5 / 9)).toFixed(); +}; + +const buildWeatherCard = (title, weather) => { +let temperature = ( + weather.temperature || weather.temperatureHigh +).toFixed(); +let summary = weather.summary.replace('.', ''); +let precipProbability = (weather.precipProbability * 100).toFixed(); + +var context = { + card_title: title, + icon: weather.icon, + image_src: `https://darksky.net/images/weather-icons/${weather.icon}.png`, + card_text: `${summary} and ${temperature}°F (${fahrenheitToCelsius( + temperature + )}°C).

        Chance of rain: ${precipProbability}%` +}; + +return weather_card_template(context); +}; + +const buildDestinationInformation = destination => { + let presented_by_url = + 'https://wdwnt.com/wp-content/uploads/2017/11/wdwnt_logo_2017_v2.png'; + let destination_name = 'Walt Disney World'; + let timezone = 'America/New_York'; + let park_number = '0'; + let locale = 'en-US'; + + if (destination === 'dlr') { + presented_by_url = + 'https://dlnewstoday.com/wp-content/uploads/2018/11/dlnt.png'; + destination_name = 'Disneyland'; + timezone = 'America/Los_Angeles'; + park_number = '1'; + locale = 'en-US'; + } else if (destination === 'tdr') { + presented_by_url = 'https://wdwntsirv.sirv.com/wdwnt.com/2020/07/Logo-with-Tagline.png'; + destination_name = 'Tokyo Disney Resort'; + timezone = 'Asia/Tokyo'; + park_number = '2'; + locale = 'jp'; + } else if (destination === 'dlp') { + destination_name = 'Disneyland Paris'; + timezone = 'Europe/Paris'; + park_number = '3'; + locale = 'fr-FR'; + } else if (destination === 'hkdl') { + destination_name = 'Hong Kong Disneyland'; + timezone = 'Asia/Hong_Kong'; + park_number = '4'; + locale = 'zh-Hk'; + } else if (destination === 'shdr') { + destination_name = 'Shanghai Disney Resort'; + timezone = 'Asia/Shanghai'; + park_number = '5'; + locale = 'zh-CN'; + } + + return { + destination_name, + presented_by_url, + timezone, + park_number, + locale + }; +}; + + +const parks_ul = document.getElementById('parks'); +const weather_div = document.getElementById('weather'); + +const getLastItem = thePath => thePath.substring(thePath.lastIndexOf('/') + 1); +const removeExtention = thePath => thePath.slice(0, -5); +const destinationCode = removeExtention(getLastItem(window.location.pathname)); +const destination = getParameterByName('destination') || destinationCode; + +let destination_information = buildDestinationInformation(destination); + +const presented_by_image = document.getElementById('presented-by-image'); +presented_by_image.src = destination_information.presented_by_url; +const destination_name_span = document.getElementById('destination-name'); +destination_name_span.innerHTML = +destination_information.destination_name; + +const background = getParameterByName('background'); + +const PARKS_API_URL = +'https://wdwnt-now-api.herokuapp.com/api/destinations/' + destination_information.park_number + '/parks?sort=true'; +const WEATHER_API_URL = 'https://weather.wdwnt.com/api/' + destination; +const BACKGROUND_IMAGE = ''; + +const date_div = document.getElementById('date'); +date_div.innerHTML = new Date().toLocaleDateString('zh-Hk', { +timeZone: destination_information.timezone +}); + +document.querySelector('body').style.backgroundImage = +`url(${background})` || ''; + +document.addEventListener( + 'DOMContentLoaded', + function() { + fetch(PARKS_API_URL) + .then(res => res.json()) + .then(parks => { + parks.forEach(park => { + const li = document.createElement('li'); + + li.innerHTML = ` +
        +

        ${park.name}

        +
        ${park.todaysHours}
        + `; + + parks_ul.appendChild(li); + }); + }); + + fetch(WEATHER_API_URL) + .then(res => res.json()) + .then(weather => { + var currently = buildWeatherCard('Right now', weather.currently); + + var daily = weather.daily.data; + var today = buildWeatherCard('Today', daily[0]); + var tomorrow = buildWeatherCard('Tomorrow', daily[1]); + + let day = new Date(daily[2].time * 1000).toLocaleDateString( + 'jp', + { + timeZone: destination_information.timezone, + weekday: 'long' + } + ); + var twoDaysFromNow = buildWeatherCard(day, daily[2]); + + weather_div.innerHTML = + '
        ' + + currently + + today + + tomorrow + + twoDaysFromNow + + '
        '; + }); + }, + false +); diff --git a/dlr.html b/dlr.html index 65c7b7c..dfb9264 100644 --- a/dlr.html +++ b/dlr.html @@ -22,7 +22,7 @@
        - Today at Disneyland - + Today at -
        @@ -45,13 +45,12 @@

        id="presented-by-image" class="float-right" width="300" - src="https://wdwnt.com/wp-content/uploads/2017/11/wdwnt_logo_2017_v2.png" - alt="Presented by wdwnt.com" + src="https://wdwntsirv.sirv.com/wdwnt.com/2020/07/Logo-with-Tagline.png" + alt="Presented by wdwnt.jp" />

        - - + diff --git a/hkdl.html b/hkdl.html index 1820473..dfb9264 100644 --- a/hkdl.html +++ b/hkdl.html @@ -22,7 +22,7 @@
        - Today at Hong Kong Disneyland - + Today at -
        @@ -51,7 +51,6 @@

        - - + diff --git a/index.html b/index.html index 303273c..dfb9264 100644 --- a/index.html +++ b/index.html @@ -22,7 +22,7 @@
        - Today at Walt Disney World - + Today at -
        @@ -34,11 +34,9 @@

        Park Hours

        @@ -47,13 +45,12 @@

        id="presented-by-image" class="float-right" width="300" - src="https://wdwnt.com/wp-content/uploads/2017/11/wdwnt_logo_2017_v2.png" - alt="Presented by wdwnt.com" + src="https://wdwntsirv.sirv.com/wdwnt.com/2020/07/Logo-with-Tagline.png" + alt="Presented by wdwnt.jp" />

        - - + diff --git a/shdr.html b/shdr.html index ce538ae..dfb9264 100644 --- a/shdr.html +++ b/shdr.html @@ -22,7 +22,7 @@
        - Today at Shanghai Disney Resort - + Today at -
        @@ -51,7 +51,6 @@

        - - + diff --git a/tdr.html b/tdr.html index c02022b..dfb9264 100644 --- a/tdr.html +++ b/tdr.html @@ -22,7 +22,7 @@
        - Today at Tokyo Disney Resort - + Today at -
        @@ -51,7 +51,6 @@

        - - + From b0d065e0b557e626d230dfec71ae6ae47cbe15ae Mon Sep 17 00:00:00 2001 From: "wendall.hershberger" Date: Wed, 21 Oct 2020 10:48:05 -0400 Subject: [PATCH 3/3] Update dlp --- dlp.html | 150 +------------------------------------------------------ 1 file changed, 2 insertions(+), 148 deletions(-) diff --git a/dlp.html b/dlp.html index 796726d..dfb9264 100644 --- a/dlp.html +++ b/dlp.html @@ -22,7 +22,7 @@
        - Today at Disneyland Paris - + Today at -
        @@ -51,7 +51,6 @@

        - - +