2023-03-10 11:10:43 +00:00
|
|
|
// fade in images
|
|
|
|
function imgFade(obj, time = 250) {
|
|
|
|
$(obj).animate({ opacity: 1 }, time);
|
2023-01-26 14:43:08 +00:00
|
|
|
}
|
2023-03-10 11:10:43 +00:00
|
|
|
// https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color
|
|
|
|
function colourContrast(bgColor, lightColor, darkColor, threshold = 0.179) {
|
2023-03-10 17:38:24 +00:00
|
|
|
// if color is in hex format then convert to rgb else parese rgb
|
2023-03-23 12:54:00 +00:00
|
|
|
let r = 0
|
|
|
|
let g = 0
|
|
|
|
let b = 0
|
2023-03-10 17:38:24 +00:00
|
|
|
if (bgColor.charAt(0) === '#') {
|
2023-03-23 12:54:00 +00:00
|
|
|
const color = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
|
|
|
|
r = parseInt(color.substring(0, 2), 16); // hexToR
|
|
|
|
g = parseInt(color.substring(2, 4), 16); // hexToG
|
|
|
|
b = parseInt(color.substring(4, 6), 16); // hexToB
|
2023-03-10 17:38:24 +00:00
|
|
|
} else {
|
2023-03-23 12:54:00 +00:00
|
|
|
const color = bgColor.replace('rgb(', '').replace(')', '').split(',');
|
|
|
|
r = color[0];
|
|
|
|
g = color[1];
|
|
|
|
b = color[2];
|
2023-03-10 17:38:24 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 12:54:00 +00:00
|
|
|
const uicolors = [r / 255, g / 255, b / 255];
|
|
|
|
const c = uicolors.map((col) => {
|
2023-03-10 11:10:43 +00:00
|
|
|
if (col <= 0.03928) {
|
|
|
|
return col / 12.92;
|
|
|
|
}
|
|
|
|
return Math.pow((col + 0.055) / 1.055, 2.4);
|
|
|
|
});
|
2023-03-23 12:54:00 +00:00
|
|
|
const L = (0.2126 * c[0]) + (0.7152 * c[1]) + (0.0722 * c[2]);
|
2023-03-10 11:10:43 +00:00
|
|
|
return (L > threshold) ? darkColor : lightColor;
|
2023-01-26 16:55:42 +00:00
|
|
|
}
|
2023-03-10 11:10:43 +00:00
|
|
|
// Lazy load images when they are in view
|
2023-03-09 23:31:58 +00:00
|
|
|
function loadOnView() {
|
2023-03-10 11:10:43 +00:00
|
|
|
let lazyLoad = document.querySelectorAll('#lazy-load');
|
|
|
|
|
|
|
|
for (let i = 0; i < lazyLoad.length; i++) {
|
|
|
|
let image = lazyLoad[i];
|
2023-03-09 23:31:58 +00:00
|
|
|
if (image.getBoundingClientRect().top < window.innerHeight && image.getBoundingClientRect().bottom > 0) {
|
|
|
|
if (!image.src) {
|
2023-03-20 17:04:05 +00:00
|
|
|
image.src = `/api/file/${image.getAttribute('data-src')}?r=thumb`
|
2023-03-09 23:31:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-10 11:10:43 +00:00
|
|
|
|
|
|
|
window.onload = function () {
|
|
|
|
loadOnView();
|
|
|
|
|
2023-03-26 01:04:13 +00:00
|
|
|
const darkColor = 'rgb(var(--black))';
|
|
|
|
const lightColor = 'rgb(var(--white))';
|
2023-03-10 11:10:43 +00:00
|
|
|
let contrastCheck = document.querySelectorAll('#contrast-check');
|
|
|
|
for (let i = 0; i < contrastCheck.length; i++) {
|
2023-03-23 12:54:00 +00:00
|
|
|
let bgColor = contrastCheck[i].getAttribute('data-color');
|
2023-03-10 17:38:24 +00:00
|
|
|
contrastCheck[i].style.color = colourContrast(bgColor, lightColor, darkColor);
|
2023-03-10 11:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let times = document.querySelectorAll('.time');
|
|
|
|
for (let i = 0; i < times.length; i++) {
|
|
|
|
// Remove milliseconds
|
|
|
|
const raw = times[i].innerHTML.split('.')[0];
|
|
|
|
|
|
|
|
// Parse YYYY-MM-DD HH:MM:SS to Date object
|
|
|
|
const time = raw.split(' ')[1]
|
|
|
|
const date = raw.split(' ')[0].split('-');
|
|
|
|
|
|
|
|
// Format to YYYY/MM/DD HH:MM:SS
|
|
|
|
let formatted = date[0] + '/' + date[1] + '/' + date[2] + ' ' + time + ' UTC';
|
|
|
|
|
|
|
|
// Convert to UTC Date object
|
|
|
|
let dateTime = new Date(formatted);
|
|
|
|
|
|
|
|
// Convert to local time
|
|
|
|
times[i].innerHTML = dateTime.toLocaleDateString() + ' ' + dateTime.toLocaleTimeString();
|
|
|
|
}
|
2023-03-23 15:47:35 +00:00
|
|
|
|
|
|
|
// Top Of Page button
|
|
|
|
let topOfPage = document.querySelector('.top-of-page');
|
|
|
|
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
|
|
|
|
topOfPage.classList.add('show');
|
|
|
|
} else {
|
|
|
|
topOfPage.classList.remove('show');
|
|
|
|
}
|
|
|
|
topOfPage.onclick = function () {
|
|
|
|
document.body.scrollTop = 0;
|
|
|
|
document.documentElement.scrollTop = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Info button
|
|
|
|
let infoButton = document.querySelector('.info-button');
|
2023-03-27 07:15:18 +00:00
|
|
|
|
|
|
|
if (infoButton) {
|
|
|
|
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
|
|
|
|
infoButton.classList.remove('show');
|
|
|
|
} else {
|
|
|
|
infoButton.classList.add('show');
|
|
|
|
}
|
|
|
|
infoButton.onclick = function () {
|
|
|
|
popUpShow('OnlyLegs on Flask',
|
|
|
|
'Using <a href="https://phosphoricons.com/">Phosphoricons</a> and <a href="https://www.gent.media/manrope">Manrope</a> <br>' +
|
|
|
|
'Made by Fluffy and others with ❤️ <br>' +
|
|
|
|
'<a href="https://github.com/Fluffy-Bean/onlylegs">V23.03.26</a>');
|
|
|
|
}
|
2023-03-23 15:47:35 +00:00
|
|
|
}
|
2023-03-10 11:10:43 +00:00
|
|
|
};
|
|
|
|
window.onscroll = function () {
|
|
|
|
loadOnView();
|
|
|
|
|
2023-03-23 15:47:35 +00:00
|
|
|
// Top Of Page button
|
2023-03-12 18:19:43 +00:00
|
|
|
let topOfPage = document.querySelector('.top-of-page');
|
2023-03-10 11:10:43 +00:00
|
|
|
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
|
2023-03-12 18:19:43 +00:00
|
|
|
topOfPage.classList.add('show');
|
2023-03-10 11:10:43 +00:00
|
|
|
} else {
|
2023-03-12 18:19:43 +00:00
|
|
|
topOfPage.classList.remove('show');
|
2023-03-10 11:10:43 +00:00
|
|
|
}
|
2023-03-23 15:47:35 +00:00
|
|
|
|
|
|
|
// Info button
|
|
|
|
let infoButton = document.querySelector('.info-button');
|
2023-03-27 07:15:18 +00:00
|
|
|
|
|
|
|
if (infoButton) {
|
|
|
|
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
|
|
|
|
infoButton.classList.remove('show');
|
|
|
|
} else {
|
|
|
|
infoButton.classList.add('show');
|
|
|
|
}
|
2023-03-23 15:47:35 +00:00
|
|
|
}
|
2023-03-10 11:10:43 +00:00
|
|
|
};
|
|
|
|
window.onresize = function () {
|
|
|
|
loadOnView();
|
2023-03-23 12:54:00 +00:00
|
|
|
};
|