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

Function getBg

scripts/magnify_image.js:395–416  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

393 }
394}
395function getBg(node) {
396 if (
397 !node ||
398 node.nodeName?.toUpperCase?.() == "HTML" ||
399 node.nodeName == "#document"
400 ) {
401 return false;
402 }
403 return ["", "::before", "::after"]
404 .map((s) => {
405 let nodeStyle = window.getComputedStyle(node, s);
406 let bg = nodeStyle.backgroundImage;
407 if (bg) {
408 let bgUrls = bg.split(",");
409 let urls = bgUrls.map((url) => url.match(/url\((['"]?)(.*?)\1\)/)?.[2]);
410 return urls.filter((url) => url !== null);
411 }
412 return null;
413 })
414 .flat()
415 .filter((_) => _);
416}
417const lazyImgAttr = [
418 "src",
419 "_src",

Callers 1

getImgSrcsFromElementFunction · 0.85

Calls 1

filterMethod · 0.80

Tested by

no test coverage detected