MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / addLoadingAnimation

Function addLoadingAnimation

scripts/magnify_image.js:1211–1253  ·  view source on GitHub ↗
(
  element,
  size = Math.min(element?.clientWidth, element?.clientHeight) || 0,
  customStyle = ""
)

Source from the content-addressed store, hash-verified

1209 return () => ele.remove();
1210}
1211function addLoadingAnimation(
1212 element,
1213 size = Math.min(element?.clientWidth, element?.clientHeight) || 0,
1214 customStyle = ""
1215) {
1216 let id = Math.random().toString(36).substr(2, 9);
1217 element.classList.add("ufs-loading-" + id);
1218
1219 let borderSize = 4;
1220
1221 // inject css code
1222 let style = document.createElement("style");
1223 style.id = "ufs-loading-style-" + id;
1224 style.textContent = `
1225 .ufs-loading-${id}::after {
1226 content: "";
1227 display: block;
1228 position: absolute;
1229 top: 50%;
1230 left: 50%;
1231 width: ${size}px;
1232 height: ${size}px;
1233 margin-top: -${size / 2}px;
1234 margin-left: -${size / 2}px;
1235 border-radius: 50%;
1236 border: ${borderSize}px solid #555 !important;
1237 border-top-color: #eee !important;
1238 animation: ufs-spin 1s ease-in-out infinite;
1239 box-sizing: border-box !important;
1240 ${customStyle}
1241 }
1242 @keyframes ufs-spin {
1243 to {
1244 transform: rotate(360deg);
1245 }
1246 }
1247 `;
1248 (document.head || document.documentElement).appendChild(style);
1249
1250 return () => {
1251 if (element) element.classList.remove("ufs-loading-" + id);
1252 };
1253}
1254function addEventListener(target, event, callback, options) {
1255 target.addEventListener(event, callback, options);
1256 return () => target.removeEventListener(event, callback, options);

Callers 2

createPreviewFunction · 0.85
addLoadingAnimationAtPosFunction · 0.85

Calls 2

addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected