Add new autochange feature & quickfixes

This commit is contained in:
Miguel Avila 2022-01-23 18:26:43 -06:00
parent 802aec898a
commit 0c56923c2a
5 changed files with 30 additions and 23 deletions

View File

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

View File

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

View File

@ -47,20 +47,29 @@ if (CONFIG.imageBackground) {
document.body.classList.add('withImageBackground');
}
if(CONFIG.changeThemeByOS && CONFIG.autoChangeTheme) {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
if (CONFIG.changeThemeByOS && CONFIG.autoChangeTheme) {
if (
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches
) {
enableDark();
} else {
disableDark();
}
}
if(CONFIG.changeThemeByHour && CONFIG.autoChangeTheme) {
if (CONFIG.changeThemeByHour && CONFIG.autoChangeTheme && !CONFIG.changeThemeByOS) {
const date = new Date();
const hours = date.getHours() < 10 ? '0' + date.getHours().toString() : date.getHours().toString();
const minutes = date.getMinutes() < 10 ? '0' + date.getMinutes().toString() : date.getMinutes().toString();
const hours =
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;
if(currentTime >= CONFIG.hourDarkThemeActive) {
if (currentTime >= CONFIG.hourDarkThemeActive) {
enableDark();
} else if (currentTime >= CONFIG.hourDarkThemeInactive) {
disableDark();

View File

@ -3,12 +3,8 @@
// └┴┘└─┘┴ ┴ ┴ ┴ ┴└─┘┴└─
const iconElement = document.querySelector('.weatherIcon');
const tempElement = document.querySelector(
'.weatherValue p'
);
const descElement = document.querySelector(
'.weatherDescription p'
);
const tempElement = document.querySelector('.weatherValue p');
const descElement = document.querySelector('.weatherDescription p');
// App data
const weather = {};
@ -73,6 +69,8 @@ function getWeather(latitude, longitude) {
// Display Weather info
function displayWeather() {
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;
}

View File

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