MCPcopy Create free account
hub / github.com/027xiguapi/code-box / handleCopy

Function handleCopy

contents/mp.tsx:24–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23const 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}

Callers

nothing calls this directly

Calls 1

i18nFunction · 0.85

Tested by

no test coverage detected