Add animation to copy button

Closes https://github.com/ajayyy/SponsorBlock/issues/796
This commit is contained in:
Ajay Ramachandran
2021-07-13 18:22:56 -04:00
parent 76b78ef132
commit b8cbedbc4d
3 changed files with 34 additions and 32 deletions

View File

@@ -158,6 +158,31 @@ export default class Utils {
});
}
/**
* Starts a spinning animation and returns a function to be called when it should be stopped
* The callback will be called when the animation is finished
* It waits until a full rotation is complete
*/
applyLoadingAnimation(element: HTMLElement, time: number, callback?: () => void): () => void {
element.style.animation = `rotate ${time}s 0s infinite`;
return () => {
// Make the animation finite
element.style.animation = `rotate ${time}s`;
// When the animation is over, hide the button
const animationEndListener = () => {
if (callback) callback();
element.style.animation = "none";
element.removeEventListener("animationend", animationEndListener);
};
element.addEventListener("animationend", animationEndListener);
}
}
/**
* Merges any overlapping timestamp ranges into single segments and returns them as a new array.
*/