🍱 Scripts refactor
This commit is contained in:
parent
cf8c74eb9d
commit
024396bf30
@ -59,7 +59,7 @@ You can use different Add-ons/Extensions for it
|
|||||||
|
|
||||||
## 🎨 Customization
|
## 🎨 Customization
|
||||||
|
|
||||||
Almost all customization can be managed in the `config.js` file:
|
All customization can be managed in the `config.js` file:
|
||||||
|
|
||||||
### 👋 General: Name, Image Background and Greetings
|
### 👋 General: Name, Image Background and Greetings
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// ┌─┐┌─┐┬─┐┌┬┐┌─┐
|
// ┌┐ ┬ ┬┌┬┐┌┬┐┌─┐┌┐┌┌─┐
|
||||||
// │ ├─┤├┬┘ ││└─┐
|
// ├┴┐│ │ │ │ │ ││││└─┐
|
||||||
// └─┘┴ ┴┴└──┴┘└─┘
|
// └─┘└─┘ ┴ ┴ └─┘┘└┘└─┘
|
||||||
// Function to print Button Cards.
|
// Function to print Button Cards.
|
||||||
|
|
||||||
const generateFirstButtonsContainer = () => {
|
const generateFirstButtonsContainer = () => {
|
||||||
@ -19,7 +19,7 @@ const generateFirstButtonsContainer = () => {
|
|||||||
|
|
||||||
buttons_1.insertAdjacentHTML(position, item);
|
buttons_1.insertAdjacentHTML(position, item);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const generateSecondButtonsContainer = () => {
|
const generateSecondButtonsContainer = () => {
|
||||||
for (const button of CONFIG.secondButtonsContainer) {
|
for (const button of CONFIG.secondButtonsContainer) {
|
||||||
@ -37,7 +37,7 @@ const generateSecondButtonsContainer = () => {
|
|||||||
|
|
||||||
buttons_2.insertAdjacentHTML(position, item);
|
buttons_2.insertAdjacentHTML(position, item);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const generateButtons = () => {
|
const generateButtons = () => {
|
||||||
switch (CONFIG.bentoLayout) {
|
switch (CONFIG.bentoLayout) {
|
||||||
|
@ -1,21 +1,17 @@
|
|||||||
// ┌─┐┬─┐┌─┐┌─┐┌┬┐┬┌┐┌┌─┐┌─┐
|
// ┌─┐┬─┐┌─┐┌─┐┌┬┐┬┌┐┌┌─┐┌─┐
|
||||||
// │ ┬├┬┘├┤ ├┤ │ │││││ ┬└─┐
|
// │ ┬├┬┘├┤ ├┤ │ │││││ ┬└─┐
|
||||||
// └─┘┴└─└─┘└─┘ ┴ ┴┘└┘└─┘└─┘
|
// └─┘┴└─└─┘└─┘ ┴ ┴┘└┘└─┘└─┘
|
||||||
|
// Function to set Greetings
|
||||||
|
|
||||||
// Get the hour
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const hour = today.getHours();
|
const hour = today.getHours();
|
||||||
|
|
||||||
// Here you can change your name
|
|
||||||
const name = CONFIG.name;
|
const name = CONFIG.name;
|
||||||
|
|
||||||
// Here you can change your greetings
|
|
||||||
const gree1 = `${CONFIG.greetingNight}\xa0`;
|
const gree1 = `${CONFIG.greetingNight}\xa0`;
|
||||||
const gree2 = `${CONFIG.greetingMorning}\xa0`;
|
const gree2 = `${CONFIG.greetingMorning}\xa0`;
|
||||||
const gree3 = `${CONFIG.greetingAfternoon}\xa0`;
|
const gree3 = `${CONFIG.greetingAfternoon}\xa0`;
|
||||||
const gree4 = `${CONFIG.greetingEvening}\xa0`;
|
const gree4 = `${CONFIG.greetingEvening}\xa0`;
|
||||||
|
|
||||||
// Define the hours of the greetings
|
|
||||||
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) {
|
||||||
|
@ -24,24 +24,22 @@ const generateLayout = () => {
|
|||||||
case 'bento':
|
case 'bento':
|
||||||
linksBlockLeft.insertAdjacentHTML(position, firstButtonsContainer);
|
linksBlockLeft.insertAdjacentHTML(position, firstButtonsContainer);
|
||||||
linksBlockRight.insertAdjacentHTML(position, firstListsContainer);
|
linksBlockRight.insertAdjacentHTML(position, firstListsContainer);
|
||||||
linksBlock.classList.remove("reduceGap");
|
linksBlock.classList.remove('reduceGap');
|
||||||
linksBlock.classList.remove("removeGap");
|
linksBlock.classList.remove('removeGap');
|
||||||
break;
|
break;
|
||||||
case 'lists':
|
case 'lists':
|
||||||
linksBlockLeft.insertAdjacentHTML(position, firstListsContainer);
|
linksBlockLeft.insertAdjacentHTML(position, firstListsContainer);
|
||||||
linksBlockRight.insertAdjacentHTML(position, secondListsContainer);
|
linksBlockRight.insertAdjacentHTML(position, secondListsContainer);
|
||||||
linksBlock.classList.add("reduceGap");
|
linksBlock.classList.add('reduceGap');
|
||||||
break;
|
break;
|
||||||
case 'buttons':
|
case 'buttons':
|
||||||
linksBlockLeft.insertAdjacentHTML(position, firstButtonsContainer);
|
linksBlockLeft.insertAdjacentHTML(position, firstButtonsContainer);
|
||||||
linksBlockRight.insertAdjacentHTML(position, secondButtonsContainer);
|
linksBlockRight.insertAdjacentHTML(position, secondButtonsContainer);
|
||||||
linksBlock.classList.add("removeGap");
|
linksBlock.classList.add('removeGap');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Layout Generated');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
generateLayout();
|
generateLayout();
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// Functions for printing both lists
|
// Functions for printing both lists
|
||||||
|
|
||||||
const generateFirstListsContainer = () => {
|
const generateFirstListsContainer = () => {
|
||||||
console.log('Running firstlistscontainer');
|
|
||||||
for (const list of CONFIG.firstlistsContainer) {
|
for (const list of CONFIG.firstlistsContainer) {
|
||||||
let item = `
|
let item = `
|
||||||
<div class="card list list__${list.id}" id="list_${list.id}">
|
<div class="card list list__${list.id}" id="list_${list.id}">
|
||||||
@ -37,7 +36,6 @@ const generateFirstListsContainer = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const generateSecondListsContainer = () => {
|
const generateSecondListsContainer = () => {
|
||||||
console.log('Running second');
|
|
||||||
for (const list of CONFIG.secondListsContainer) {
|
for (const list of CONFIG.secondListsContainer) {
|
||||||
let item = `
|
let item = `
|
||||||
<div class="card list list__${list.id}" id="list_${list.id}">
|
<div class="card list list__${list.id}" id="list_${list.id}">
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
// ┌┬┐┬ ┬┌─┐┌┬┐┌─┐
|
// ┌┬┐┬ ┬┌─┐┌┬┐┌─┐
|
||||||
// │ ├─┤├┤ │││├┤
|
// │ ├─┤├┤ │││├┤
|
||||||
// ┴ ┴ ┴└─┘┴ ┴└─┘
|
// ┴ ┴ ┴└─┘┴ ┴└─┘
|
||||||
|
// Set theme based on Configurations and Preferences
|
||||||
|
|
||||||
// Store the theme
|
|
||||||
let darkTheme = localStorage.getItem('darkTheme');
|
let darkTheme = localStorage.getItem('darkTheme');
|
||||||
const themeToggle = document.querySelector('#themeButton');
|
const themeToggle = document.querySelector('#themeButton');
|
||||||
const bodyBackground = document.getElementById('#body');
|
const bodyBackground = document.getElementById('#body');
|
||||||
|
|
||||||
// Apply Dark theme
|
|
||||||
const enableDark = () => {
|
const enableDark = () => {
|
||||||
document.body.classList.add('darktheme');
|
document.body.classList.add('darktheme');
|
||||||
localStorage.setItem('darkTheme', 'enabled');
|
localStorage.setItem('darkTheme', 'enabled');
|
||||||
@ -15,7 +14,6 @@ const enableDark = () => {
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove Dark theme
|
|
||||||
const disableDark = () => {
|
const disableDark = () => {
|
||||||
document.body.classList.remove('darktheme');
|
document.body.classList.remove('darktheme');
|
||||||
localStorage.setItem('darkTheme', null);
|
localStorage.setItem('darkTheme', null);
|
||||||
@ -23,18 +21,14 @@ const disableDark = () => {
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
};
|
};
|
||||||
|
|
||||||
//Toggle theme
|
|
||||||
if (darkTheme === 'enabled') {
|
if (darkTheme === 'enabled') {
|
||||||
// Temporarily disable transitions when changing theme on startup
|
|
||||||
document.body.classList.add('notransition');
|
document.body.classList.add('notransition');
|
||||||
enableDark();
|
enableDark();
|
||||||
document.body.offsetHeight; // Trigger reflow to flush CSS changes
|
|
||||||
document.body.classList.remove('notransition');
|
document.body.classList.remove('notransition');
|
||||||
} else {
|
} else {
|
||||||
disableDark();
|
disableDark();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle Theme Listener
|
|
||||||
themeToggle.addEventListener('click', () => {
|
themeToggle.addEventListener('click', () => {
|
||||||
darkTheme = localStorage.getItem('darkTheme');
|
darkTheme = localStorage.getItem('darkTheme');
|
||||||
if (darkTheme !== 'enabled') {
|
if (darkTheme !== 'enabled') {
|
||||||
@ -59,8 +53,11 @@ if (CONFIG.changeThemeByOS && CONFIG.autoChangeTheme) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Theme Autochanger
|
if (
|
||||||
if (CONFIG.changeThemeByHour && CONFIG.autoChangeTheme && !CONFIG.changeThemeByOS) {
|
CONFIG.changeThemeByHour &&
|
||||||
|
CONFIG.autoChangeTheme &&
|
||||||
|
!CONFIG.changeThemeByOS
|
||||||
|
) {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const hours =
|
const hours =
|
||||||
date.getHours() < 10
|
date.getHours() < 10
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
// ┌┬┐┬┌┬┐┌─┐
|
// ┌┬┐┬┌┬┐┌─┐
|
||||||
// │ ││││├┤
|
// │ ││││├┤
|
||||||
// ┴ ┴┴ ┴└─┘
|
// ┴ ┴┴ ┴└─┘
|
||||||
|
// Set time and Date
|
||||||
|
|
||||||
window.onload = displayClock();
|
window.onload = displayClock();
|
||||||
// Clock function
|
|
||||||
function displayClock() {
|
function displayClock() {
|
||||||
const monthNames = [
|
const monthNames = [
|
||||||
'Jan',
|
'Jan',
|
||||||
@ -20,7 +20,6 @@ function displayClock() {
|
|||||||
'Dec',
|
'Dec',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Get clock elements
|
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
var mm = monthNames[d.getMonth()];
|
var mm = monthNames[d.getMonth()];
|
||||||
var dd = d.getDate();
|
var dd = d.getDate();
|
||||||
@ -28,14 +27,12 @@ function displayClock() {
|
|||||||
var hh = d.getHours();
|
var hh = d.getHours();
|
||||||
var ampm = '';
|
var ampm = '';
|
||||||
|
|
||||||
// Hour format
|
|
||||||
if (CONFIG.twelveHourFormat) {
|
if (CONFIG.twelveHourFormat) {
|
||||||
ampm = hh >= 12 ? ' pm' : ' am';
|
ampm = hh >= 12 ? ' pm' : ' am';
|
||||||
hh = hh % 12;
|
hh = hh % 12;
|
||||||
hh = hh ? hh : 12;
|
hh = hh ? hh : 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display clock elements
|
|
||||||
document.getElementById('hour').innerText = hh;
|
document.getElementById('hour').innerText = hh;
|
||||||
document.getElementById('separator').innerHTML = ' : ';
|
document.getElementById('separator').innerHTML = ' : ';
|
||||||
document.getElementById('minutes').innerText = min + ampm;
|
document.getElementById('minutes').innerText = min + ampm;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
// ┬ ┬┌─┐┌─┐┌┬┐┬ ┬┌─┐┬─┐
|
// ┬ ┬┌─┐┌─┐┌┬┐┬ ┬┌─┐┬─┐
|
||||||
// │││├┤ ├─┤ │ ├─┤├┤ ├┬┘
|
// │││├┤ ├─┤ │ ├─┤├┤ ├┬┘
|
||||||
// └┴┘└─┘┴ ┴ ┴ ┴ ┴└─┘┴└─
|
// └┴┘└─┘┴ ┴ ┴ ┴ ┴└─┘┴└─
|
||||||
|
// Functions to setup Weather windget.
|
||||||
|
|
||||||
const iconElement = document.querySelector('.weatherIcon');
|
const iconElement = document.querySelector('.weatherIcon');
|
||||||
const tempElement = document.querySelector('.weatherValue p');
|
const tempElement = document.querySelector('.weatherValue p');
|
||||||
const descElement = document.querySelector('.weatherDescription p');
|
const descElement = document.querySelector('.weatherDescription p');
|
||||||
|
|
||||||
// App data
|
|
||||||
const weather = {};
|
const weather = {};
|
||||||
weather.temperature = {
|
weather.temperature = {
|
||||||
unit: 'celsius',
|
unit: 'celsius',
|
||||||
@ -15,10 +15,7 @@ weather.temperature = {
|
|||||||
var tempUnit = CONFIG.weatherUnit;
|
var tempUnit = CONFIG.weatherUnit;
|
||||||
|
|
||||||
const KELVIN = 273.15;
|
const KELVIN = 273.15;
|
||||||
// Use your own key for the Weather, Get it here: https://openweathermap.org/
|
|
||||||
const key = `${CONFIG.weatherKey}`;
|
const key = `${CONFIG.weatherKey}`;
|
||||||
|
|
||||||
// Set Position function
|
|
||||||
setPosition();
|
setPosition();
|
||||||
|
|
||||||
function setPosition(position) {
|
function setPosition(position) {
|
||||||
@ -43,7 +40,6 @@ function setPosition(position) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Weather data
|
|
||||||
function getWeather(latitude, longitude) {
|
function getWeather(latitude, longitude) {
|
||||||
let api = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&lang=${CONFIG.language}&appid=${key}`;
|
let api = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&lang=${CONFIG.language}&appid=${key}`;
|
||||||
fetch(api)
|
fetch(api)
|
||||||
@ -63,7 +59,6 @@ function getWeather(latitude, longitude) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(
|
tempElement.innerHTML = `${weather.temperature.value.toFixed(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user