Skip to content

Commit

Permalink
Prevent animation on page load
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Feb 8, 2023
1 parent 721a8b4 commit ba1bebd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/scripts/tweaks/checkmark_stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { pageModifications } from '../../util/mutations.js';
let styleElementMax = 0;
const styleElement = buildStyle();

const transitionStyleElement = buildStyle(`
${keyToCss('blueCheckmarksContainer')}, ${keyToCss('blueCheckmarkContainer')} {
transition: margin 0.5s ease;
}
`);

const updateStyleElement = count => {
if (count > styleElementMax) {
styleElementMax = count;

styleElement.textContent = `
${keyToCss('blueCheckmarksContainer')}, ${keyToCss('blueCheckmarkContainer')} {
transition: margin 0.5s ease;
}
*:not(:hover) > ${keyToCss('blueCheckmarksContainer')} ${keyToCss('blueCheckmarkContainer')} {
margin-right: -10px;
}
Expand Down Expand Up @@ -41,12 +43,18 @@ const updateStyleElement = count => {
const processBlueCheckmarksContainer = blueCheckmarksContainers =>
updateStyleElement(Math.max(...blueCheckmarksContainers.map(el => el.children.length)));

const waitForRender = () =>
new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));

export const main = async () => {
document.head.append(styleElement);
pageModifications.register(keyToCss('blueCheckmarksContainer'), processBlueCheckmarksContainer);

waitForRender().then(() => document.head.append(transitionStyleElement));
};

export const clean = async () => {
pageModifications.unregister(processBlueCheckmarksContainer);
styleElement.remove();
transitionStyleElement.remove();
};

0 comments on commit ba1bebd

Please sign in to comment.