feat: add work in progress 7.0 code

Co-authored-by: Alex Sparkes <turbomarshmello@gmail.com>
This commit is contained in:
David Ralph
2022-04-08 14:48:36 +01:00
parent e0820c6b2a
commit 361fae7f25
136 changed files with 8631 additions and 3500 deletions

View File

@@ -59,7 +59,7 @@ export function getGradient() {
export function randomColourStyleBuilder(type) {
// randomColour based on https://stackoverflow.com/a/5092872
const randomColour = () => '#000000'.replace(/0/g, () => {return (~~(Math.random()*16)).toString(16)});
const randomColour = () => '#000000'.replace(/0/g, () => { return (~~(Math.random()*16)).toString(16) });
let style = `background:${randomColour()};`;
if (type === 'random_gradient') {

View File

@@ -1,14 +1,14 @@
import EventBus from './eventbus';
function showReminder() {
document.querySelector('.reminder-info').style.display = 'block';
document.querySelector('.reminder-info').style.display = 'flex';
localStorage.setItem('showReminder', true);
}
// based on https://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links
export function urlParser(input) {
const urlPattern = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_+.~#?&//=]*)/;
return input.replace(urlPattern, '<a href="$&" target="_blank">$&</a>');
return input.replace(urlPattern, '<br/><a href="$&" target="_blank">$&</a>');
}
export function install(type, input, sideload) {
@@ -32,7 +32,11 @@ export function install(type, input, sideload) {
break;
case 'photos':
localStorage.setItem('photo_packs', JSON.stringify(input.photos));
const currentPhotos = JSON.parse(localStorage.getItem('photo_packs')) || [];
input.photos.forEach(photo => {
currentPhotos.push(photo);
});
localStorage.setItem('photo_packs', JSON.stringify(currentPhotos));
localStorage.setItem('oldBackgroundType', localStorage.getItem('backgroundType'));
localStorage.setItem('backgroundType', 'photo_pack');
EventBus.dispatch('refresh', 'background');
@@ -89,7 +93,16 @@ export function uninstall(type, name) {
break;
case 'photos':
localStorage.removeItem('photo_packs');
const installedContents = JSON.parse(localStorage.getItem('photo_packs'));
const packContents = JSON.parse(localStorage.getItem('installed')).find(content => content.name === name);
// todo: make it find in photo_packs all the ones in installed for that pack and remove
console.log(packContents)
installedContents.forEach((item, index) => {
if (packContents.photos.includes(item)) {
installedContents.splice(index, 1);
}
});
localStorage.setItem('photo_packs', JSON.stringify(installedContents));
localStorage.setItem('backgroundType', localStorage.getItem('oldBackgroundType'));
localStorage.removeItem('oldBackgroundType');
EventBus.dispatch('refresh', 'marketplacebackgrounduninstall');

View File

@@ -34,15 +34,18 @@ export function loadSettings(hotreload) {
switch (localStorage.getItem('theme')) {
case 'dark':
document.body.classList.add('dark');
document.body.classList.remove('light');
break;
case 'auto':
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
} else {
document.body.classList.remove('dark');
document.body.classList.add('light');
}
break;
default:
document.body.classList.add('light');
document.body.classList.remove('dark');
}
@@ -66,7 +69,11 @@ export function loadSettings(hotreload) {
document.body.classList.remove('no-animations');
}
if (localStorage.getItem('textBorder') === 'true') {
// technically, this is text SHADOW, and not BORDER
// however it's a mess and we'll just leave it at this for now
const textBorder = localStorage.getItem('textBorder');
// enable/disable old text border from before redesign
if (textBorder === 'true') {
const elements = ['greeting', 'clock', 'quote', 'quoteauthor', 'date'];
elements.forEach((element) => {
try {
@@ -86,6 +93,13 @@ export function loadSettings(hotreload) {
});
}
// remove actual default shadow
if (textBorder === 'none') {
document.getElementById('center').classList.add('no-textBorder');
} else {
document.getElementById('center').classList.remove('no-textBorder');
}
const css = localStorage.getItem('customcss');
if (css) {
document.head.insertAdjacentHTML('beforeend', '<style id="customcss">' + css + '</style>');