| 22 | |
| 23 | const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => { |
| 24 | function handleCopy() { |
| 25 | try { |
| 26 | const item = anchor.element.closest(".weui-desktop-img-picker__item") |
| 27 | const img = item.querySelector(".weui-desktop-img-picker__img-thumb") |
| 28 | const computedStyle = window.getComputedStyle(img) |
| 29 | const backgroundImage = computedStyle.getPropertyValue("background-image") |
| 30 | const imageUrlMatch = backgroundImage.match(/url\(["']?(.*?)["']?\)/) |
| 31 | |
| 32 | if (imageUrlMatch && imageUrlMatch[1]) { |
| 33 | const imageUrl = imageUrlMatch[1] |
| 34 | |
| 35 | navigator.clipboard.writeText(imageUrl) |
| 36 | alert(i18n("urlCopied")) |
| 37 | } |
| 38 | } catch (error) { |
| 39 | console.error("复制失败:", error) |
| 40 | alert(i18n("copyFailed")) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return <button onClick={handleCopy}>{i18n("copyURL")}</button> |
| 45 | } |