Merge pull request #61 from migueravila/dev

️ Add new autochange feature
This commit is contained in:
Miguel Ávila 2022-01-23 18:33:06 -06:00 committed by GitHub
commit 83b8866ab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 31 deletions

View File

@ -14,17 +14,18 @@
<br /> <br />
## 👇 Índice ## 👇 Índice
- [👇 Índice](#-indice) - [👇 Índice](#-índice)
- [✨ Características](#-caracteistícas) - [✨ Características](#-características)
- [🚀 Usos](#-usos) - [🚀 Usos](#-usos)
- [Como página de inicio](#como-página-de-inicio) - [Como página de inicio](#como-página-de-inicio)
- [Como una nueva pestaña](#como-una-nueva-pestaña) - [Como una nueva pestaña](#como-una-nueva-pestaña)
- [🎨 Personalización](#-personalización) - [🎨 Personalización](#-personalización)
- [👋 General: Nombre, Imagen De Fondo y Saludos](#-nombre-imagen-de-fondo-y-saludos) - [👋 General: Nombre, Imagen De Fondo y Saludos](#-general-nombre-imagen-de-fondo-y-saludos)
- [🏷️ Botones de enlace](#-enlaces-de-botones) - [🏷️ Botones de Enlace****](#-botones-de-enlace)
- [📑 Lista de enlaces](#-lista-de-enlaces) - [📑 Lista de enlaces](#-lista-de-enlaces)
- [⛈️ Clima: Clave De La Api, Iconos y Grupos](#-Clima-clave-de-la-api-iconos-y-grupos) - [⛈️ Clima: Clave De La Api, Iconos y Grupos](#-clima-clave-de-la-api-iconos-y-grupos)
- [💛 Colores](#-colores) - [💛 Colores](#-colores)
- [🌑 Cambio automatico de tema](#-cambio-automatico-de-tema)
## ✨ Características ## ✨ Características
@ -226,4 +227,22 @@ En el archivo `app.css` puedes cambiar las variables para cualquiera de los tema
} }
``` ```
### 🌑 Cambio automatico de tema
The theme can be automatically changed by the OS' current theme or personalized hours
that you can change in the `config.js` file:
```js
// Autochange
autoChangeTheme: true,
// Autochabge by OS
changeThemeByOS: false,
// Autochange by hour options (24hrs format, string must be in: hh:mm)
changeThemeByHour: true, // If it's true, it will use the values below:
hourDarkThemeActive: '18:30', // Turn on the dark theme after this hour
hourDarkThemeInactive: '07:00', // Turn off the dark theme after this hour and before the above hour
```
![](assets/img/subheader.png) ![](assets/img/subheader.png)

View File

@ -237,11 +237,15 @@ The theme can be automatically changed by the OS' current theme or personalized
that you can change in the `config.js` file: that you can change in the `config.js` file:
```js ```js
// Autochange dark-theme (24hrs format, string must be in format: hh:mm) // Autochange
autoChangeTheme: true, autoChangeTheme: true,
// Autochabge by OS
changeThemeByOS: false, changeThemeByOS: false,
// Autochange by hour options (24hrs format, string must be in: hh:mm)
changeThemeByHour: true, // If it's true, it will use the values below: changeThemeByHour: true, // If it's true, it will use the values below:
hourDarkThemeActive: '19:00', // Turn on the dark theme after this hour hourDarkThemeActive: '18:30', // Turn on the dark theme after this hour
hourDarkThemeInactive: '07:00', // Turn off the dark theme after this hour and before the above hour hourDarkThemeInactive: '07:00', // Turn off the dark theme after this hour and before the above hour
``` ```

View File

@ -5,7 +5,6 @@
// Print cards // Print cards
const printCards = () => { const printCards = () => {
for (const card of CONFIG.cards) { for (const card of CONFIG.cards) {
// Card Item // Card Item
let item = ` let item = `
<a <a

View File

@ -19,12 +19,9 @@ const gree4 = `${CONFIG.greetingEvening}\xa0`;
if (hour >= 23 || hour < 5) { if (hour >= 23 || hour < 5) {
document.getElementById('greetings').innerText = gree1 + name; document.getElementById('greetings').innerText = gree1 + name;
} else if (hour >= 6 && hour < 12) { } else if (hour >= 6 && hour < 12) {
document.getElementById('greetings').innerText = document.getElementById('greetings').innerText = gree2 + name;
gree2 + name;
} else if (hour >= 12 && hour < 17) { } else if (hour >= 12 && hour < 17) {
document.getElementById('greetings').innerText = document.getElementById('greetings').innerText = gree3 + name;
gree3 + name;
} else { } else {
document.getElementById('greetings').innerText = document.getElementById('greetings').innerText = gree4 + name;
gree4 + name;
} }

View File

@ -48,17 +48,26 @@ if (CONFIG.imageBackground) {
} }
if (CONFIG.changeThemeByOS && CONFIG.autoChangeTheme) { if (CONFIG.changeThemeByOS && CONFIG.autoChangeTheme) {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { if (
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches
) {
enableDark(); enableDark();
} else { } else {
disableDark(); disableDark();
} }
} }
if(CONFIG.changeThemeByHour && CONFIG.autoChangeTheme) { if (CONFIG.changeThemeByHour && CONFIG.autoChangeTheme && !CONFIG.changeThemeByOS) {
const date = new Date(); const date = new Date();
const hours = date.getHours() < 10 ? '0' + date.getHours().toString() : date.getHours().toString(); const hours =
const minutes = date.getMinutes() < 10 ? '0' + date.getMinutes().toString() : date.getMinutes().toString(); date.getHours() < 10
? '0' + date.getHours().toString()
: date.getHours().toString();
const minutes =
date.getMinutes() < 10
? '0' + date.getMinutes().toString()
: date.getMinutes().toString();
const currentTime = hours + ':' + minutes; const currentTime = hours + ':' + minutes;
if (currentTime >= CONFIG.hourDarkThemeActive) { if (currentTime >= CONFIG.hourDarkThemeActive) {
enableDark(); enableDark();

View File

@ -3,12 +3,8 @@
// └┴┘└─┘┴ ┴ ┴ ┴ ┴└─┘┴└─ // └┴┘└─┘┴ ┴ ┴ ┴ ┴└─┘┴└─
const iconElement = document.querySelector('.weatherIcon'); const iconElement = document.querySelector('.weatherIcon');
const tempElement = document.querySelector( const tempElement = document.querySelector('.weatherValue p');
'.weatherValue p' const descElement = document.querySelector('.weatherDescription p');
);
const descElement = document.querySelector(
'.weatherDescription p'
);
// App data // App data
const weather = {}; const weather = {};
@ -73,6 +69,8 @@ function getWeather(latitude, longitude) {
// Display Weather info // Display Weather info
function displayWeather() { function displayWeather() {
iconElement.innerHTML = `<img src="assets/icons/${CONFIG.weatherIcons}/${weather.iconId}.png"/>`; iconElement.innerHTML = `<img src="assets/icons/${CONFIG.weatherIcons}/${weather.iconId}.png"/>`;
tempElement.innerHTML = `${weather.temperature.value.toFixed(0)}°<span class="darkfg">${tempUnit}</span>`; tempElement.innerHTML = `${weather.temperature.value.toFixed(
0
)}°<span class="darkfg">${tempUnit}</span>`;
descElement.innerHTML = weather.description; descElement.innerHTML = weather.description;
} }

View File

@ -32,11 +32,15 @@ const CONFIG = {
defaultLatitude: '37.775', defaultLatitude: '37.775',
defaultLongitude: '-122.419', defaultLongitude: '-122.419',
// Autochange dark-theme (24hrs format, string must be in: hh:mm) // Autochange
autoChangeTheme: true, autoChangeTheme: true,
// Autochabge by OS
changeThemeByOS: false, changeThemeByOS: false,
// Autochange by hour options (24hrs format, string must be in: hh:mm)
changeThemeByHour: true, changeThemeByHour: true,
hourDarkThemeActive: '19:00', hourDarkThemeActive: '18:30',
hourDarkThemeInactive: '07:00', hourDarkThemeInactive: '07:00',
// ┌─┐┌─┐┬─┐┌┬┐┌─┐ // ┌─┐┌─┐┬─┐┌┬┐┌─┐