From 6fa9efcc74a9c36f9e2178ee5427eafb8d470d99 Mon Sep 17 00:00:00 2001 From: Frankie B Date: Mon, 22 Jan 2024 01:16:42 +0000 Subject: Get scheme cookie server-side instead of client-side on page load --- app/Http/Middleware/EncryptCookies.php | 2 +- public/js/schemeSwap.js | 53 +++++++++++++++++++++++ public/js/themeSwap.js | 72 ------------------------------- resources/views/includes/head.blade.php | 7 ++- resources/views/layouts/default.blade.php | 2 +- 5 files changed, 60 insertions(+), 76 deletions(-) create mode 100644 public/js/schemeSwap.js delete mode 100644 public/js/themeSwap.js diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php index 867695b..5ee1433 100644 --- a/app/Http/Middleware/EncryptCookies.php +++ b/app/Http/Middleware/EncryptCookies.php @@ -12,6 +12,6 @@ class EncryptCookies extends Middleware * @var array */ protected $except = [ - // + "colorscheme" ]; } diff --git a/public/js/schemeSwap.js b/public/js/schemeSwap.js new file mode 100644 index 0000000..de5a6b2 --- /dev/null +++ b/public/js/schemeSwap.js @@ -0,0 +1,53 @@ +/** + * Retrieves a cookies value + * @param {string} cname Cookie name + * @returns {string} Cookie value + */ +function getCookie(cname) { + let name = cname + "="; + let decodedCookie = decodeURIComponent(document.cookie); + let ca = decodedCookie.split(';'); + for(let i = 0; i cookie('colorscheme', 'catppuccin-macchiato'); +@endphp - + - + {!! (intval(date('n')) == 12) ? '' : '' !!} diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 144c32b..996d895 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -4,7 +4,7 @@ @include('includes.head') - +