(name, previews, removeBy)
| 26 | const CUSTOM_MODIFIERS_KEY = "customModifiers" |
| 27 | |
| 28 | function createModifierCard(name, previews, removeBy) { |
| 29 | let cardPreviewImageType = previewImageField.value |
| 30 | |
| 31 | const modifierCard = document.createElement("div") |
| 32 | modifierCard.className = "modifier-card" |
| 33 | modifierCard.innerHTML = ` |
| 34 | <div class="modifier-card-overlay"></div> |
| 35 | <div class="modifier-card-image-container"> |
| 36 | <div class="modifier-card-image-overlay">+</div> |
| 37 | <p class="modifier-card-error-label">No Image</p> |
| 38 | <img onerror="this.remove()" alt="Modifier Image" class="modifier-card-image"> |
| 39 | </div> |
| 40 | <div class="modifier-card-container"> |
| 41 | <div class="modifier-card-label"> |
| 42 | <span class="long-label hidden"></span> |
| 43 | <p class="regular-label"></p> |
| 44 | </div> |
| 45 | </div>` |
| 46 | |
| 47 | const image = modifierCard.querySelector(".modifier-card-image") |
| 48 | const longLabel = modifierCard.querySelector(".modifier-card-label span.long-label") |
| 49 | const regularLabel = modifierCard.querySelector(".modifier-card-label p.regular-label") |
| 50 | |
| 51 | if (typeof previews == "object") { |
| 52 | image.src = previews[cardPreviewImageType == "portrait" ? 0 : 1] // 0 index is portrait, 1 landscape |
| 53 | image.setAttribute("preview-type", cardPreviewImageType) |
| 54 | } else { |
| 55 | image.remove() |
| 56 | } |
| 57 | |
| 58 | const maxLabelLength = 30 |
| 59 | const cardLabel = removeBy ? name.replace("by ", "") : name |
| 60 | |
| 61 | function getFormattedLabel(length) { |
| 62 | if (cardLabel?.length <= length) { |
| 63 | return cardLabel |
| 64 | } else { |
| 65 | return cardLabel.substring(0, length) + "..." |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | modifierCard.dataset.fullName = name // preserve the full name |
| 70 | regularLabel.dataset.fullName = name // preserve the full name, legacy support for older plugins |
| 71 | |
| 72 | longLabel.innerText = getFormattedLabel(maxLabelLength * 2) |
| 73 | regularLabel.innerText = getFormattedLabel(maxLabelLength) |
| 74 | |
| 75 | if (cardLabel.length > maxLabelLength) { |
| 76 | modifierCard.classList.add("support-long-label") |
| 77 | |
| 78 | if (cardLabel.length > maxLabelLength * 2) { |
| 79 | modifierCard.title = `"${name}"` |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return modifierCard |
| 84 | } |
| 85 |
no test coverage detected