Files
Kelx/optimize_sidebar2.js
2026-06-10 17:04:11 +00:00

203 lines
5.7 KiB
JavaScript

const fs = require('fs');
let ejsContent = fs.readFileSync('views/bot.ejs', 'utf8');
const oldEjsStr = ` .sidebar-shell {
transition:
width 0.42s cubic-bezier(0.22, 1, 0.36, 1),
opacity 0.2s ease,
background-color 0.42s cubic-bezier(0.22, 1, 0.36, 1),
box-shadow 0.42s cubic-bezier(0.22, 1, 0.36, 1) !important;
will-change: width, background-color, box-shadow;
}`;
const newEjsStr = ` .sidebar-shell {
transition:
width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
opacity 0.2s ease,
background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
will-change: width, transform, opacity;
transform: translateZ(0);
backface-visibility: hidden;
perspective: 1000px;
}`;
const oldEjsStr2 = ` .sidebar-shell.open .sidebar-item .label,
.sidebar-shell.open .profile-meta {
transition:
max-width 0.36s cubic-bezier(0.22, 1, 0.36, 1),
opacity 0.26s ease,
transform 0.36s cubic-bezier(0.22, 1, 0.36, 1);
transition-delay: 0s;
}`;
const newEjsStr2 = ` .sidebar-shell.open .sidebar-item .label,
.sidebar-shell.open .profile-meta {
transition:
opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1),
transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
transition-delay: 0s;
transform: translateZ(0);
backface-visibility: hidden;
}`;
if (ejsContent.includes(oldEjsStr)) {
ejsContent = ejsContent.replace(oldEjsStr, newEjsStr);
console.log('Replaced sidebar-shell transitions');
} else {
console.log('Could not find old sidebar-shell transitions');
}
if (ejsContent.includes(oldEjsStr2)) {
ejsContent = ejsContent.replace(oldEjsStr2, newEjsStr2);
console.log('Replaced sidebar-item label transitions');
} else {
console.log('Could not find old sidebar-item label transitions');
}
fs.writeFileSync('views/bot.ejs', ejsContent);
let cssContent = fs.readFileSync('public/css/bot.css', 'utf8');
const oldCssStr = `.sidebar-shell.open .sidebar-item .label {
display: inline-block;
max-width: 0;
opacity: 0;
overflow: hidden;
transition: max-width .25s ease, opacity .25s ease, transform .25s ease;
}`;
const newCssStr = `.sidebar-shell.open .sidebar-item .label {
display: inline-block;
width: 0;
opacity: 0;
overflow: hidden;
transition: opacity .2s ease, transform .25s ease;
will-change: opacity, transform;
transform: translateZ(0);
}`;
const oldCssStr2 = `.sidebar-shell.open:hover .sidebar-item .label {
max-width: 150px;
opacity: 1;
transform: translateX(0);
}`;
const newCssStr2 = `.sidebar-shell.open:hover .sidebar-item .label {
width: 150px;
opacity: 1;
transform: translateX(0);
}`;
const oldCssStr3 = `.sidebar-shell.open .profile-meta {
display: flex;
flex-direction: column;
max-width: 0;
opacity: 0;
overflow: hidden;
transition: max-width .25s ease, opacity .25s ease;
white-space: nowrap;
}`;
const newCssStr3 = `.sidebar-shell.open .profile-meta {
display: flex;
flex-direction: column;
width: 0;
opacity: 0;
overflow: hidden;
transition: opacity .2s ease, transform .25s ease;
white-space: nowrap;
will-change: opacity, transform;
transform: translateZ(0);
}`;
const oldCssStr4 = `.sidebar-shell.open:hover .profile-meta {
max-width: 200px;
opacity: 1;
}`;
const newCssStr4 = `.sidebar-shell.open:hover .profile-meta {
width: 200px;
opacity: 1;
}`;
const oldCssStr5 = `.sidebar-shell {
position: fixed;
--sidebar-top: 75px;
--sidebar-height: 480px;
top: var(--sidebar-top);
left: 12px;
transform: none;
transform: none;
width: 68px !important;
height: var(--sidebar-height);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
background-color: rgba(255, 255, 255, 0.047);
border-radius: 18px;
isolation: isolate;
box-shadow: 0px 6px var(--outer-shadow-blur) rgba(0, 0, 0, 0.2);
padding: 14px 0;
display: flex;
flex-direction: column;
gap: 10px;
opacity: 0;
pointer-events: none;
transition: width .22s ease, opacity .18s ease, transform .22s ease;
z-index: 2200;
}`;
const newCssStr5 = `.sidebar-shell {
position: fixed;
--sidebar-top: 75px;
--sidebar-height: 480px;
top: var(--sidebar-top);
left: 12px;
transform: translateZ(0);
width: 68px !important;
height: var(--sidebar-height);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
background-color: rgba(255, 255, 255, 0.047);
border-radius: 18px;
isolation: isolate;
box-shadow: 0px 6px var(--outer-shadow-blur) rgba(0, 0, 0, 0.2);
padding: 14px 0;
display: flex;
flex-direction: column;
gap: 10px;
opacity: 0;
pointer-events: none;
transition: width .3s cubic-bezier(0.4, 0, 0.2, 1), opacity .2s ease, transform .3s cubic-bezier(0.4, 0, 0.2, 1);
z-index: 2200;
will-change: width, transform, opacity;
backface-visibility: hidden;
perspective: 1000px;
}`;
if (cssContent.includes(oldCssStr)) {
cssContent = cssContent.replace(oldCssStr, newCssStr);
console.log('Replaced bot.css label initial state');
}
if (cssContent.includes(oldCssStr2)) {
cssContent = cssContent.replace(oldCssStr2, newCssStr2);
console.log('Replaced bot.css label hover state');
}
if (cssContent.includes(oldCssStr3)) {
cssContent = cssContent.replace(oldCssStr3, newCssStr3);
console.log('Replaced bot.css profile initial state');
}
if (cssContent.includes(oldCssStr4)) {
cssContent = cssContent.replace(oldCssStr4, newCssStr4);
console.log('Replaced bot.css profile hover state');
}
if (cssContent.includes(oldCssStr5)) {
cssContent = cssContent.replace(oldCssStr5, newCssStr5);
console.log('Replaced bot.css sidebar main shell');
}
fs.writeFileSync('public/css/bot.css', cssContent);