PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.14k stars 350 forks source link

[How to fetch anchor innerText] #843

Open yangcancai opened 9 months ago

yangcancai commented 9 months ago

What is the example you wish to see?

export const getInlineAnchorList: PlasmoGetInlineAnchorList = async () => {
  return document.querySelectorAll("div[id^='message-content']")
}

export const getShadowHostId = (anchor: PlasmoCSUIAnchor) => 
anchor.element.innerText + "plasmo-inline-example-unique-id"

const TranslateComponent = () => {
 // how to fetch anchor innerText
 const orgMsgText = anchor.element.innerText
 const newMsgText = (orgMsgText) => {}
  const [fontColor, _setColor] = useStorage("pickColor", "blue")
  return (
    <div style={{
        color: fontColor
    }}>
      <span> {newMsgText} </span>
    </div>
  )
}
export default TranslateComponent

Is there any context that might help us understand?

I want to fetch anchor innerText in TranslateComponent , I didn't find the corresponding solution in the documents and examples, Is there any way to solve it?

Code of Conduct

dielect commented 3 months ago

It's 2024, and I'm also looking for a solution to this

LyceumHewun commented 1 month ago

You can try this

...
const TranslateComponent = ({ anchor: { element } }) => {
...
dielect commented 1 month ago

You can try this

...
const TranslateComponent = ({ anchor: { element } }) => {
...

Thank you, I discovered this usage after some time by reviewing some reference code, but it was not mentioned in the official documentation. In fact, I do not know how much more advanced usage I am unaware of.