From 41ebf2e45c308049dd54d07c53620830ab8ebe05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=8A=A8=E7=89=A9?= <15294745236@163.com> Date: Mon, 26 Aug 2024 13:08:44 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=E4=BF=AE=E5=A4=8D=E8=AF=AF=E4=B8=8Ereact?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=80=9A=E4=BF=A1=E4=BA=8B=E6=95=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/content/content.js | 13 ++++++----- dist/contentPage/contentPage.js | 2 +- dist/contentPage/index.html | 3 ++- dist/js/client-B7nMxStY.js | 40 +++++++++++++++++++++++++++++++++ dist/js/postMessage-B4GKDR20.js | 1 + dist/js/postMessage-B_nyYmIz.js | 1 + dist/popup/index.html | 2 +- dist/popup/popup.js | 2 +- src/content/content.ts | 30 ++++++++++++++++--------- src/contentPage/App.tsx | 9 ++++++++ src/contentPage/index.html | 1 + src/popup/App.tsx | 1 + src/utils/diary.md | 5 +++++ src/utils/postMessage.ts | 26 ++++++++++----------- vite.config.ts | 30 ++++++++++++------------- 15 files changed, 116 insertions(+), 50 deletions(-) create mode 100644 dist/js/client-B7nMxStY.js create mode 100644 dist/js/postMessage-B4GKDR20.js create mode 100644 dist/js/postMessage-B_nyYmIz.js create mode 100644 src/utils/diary.md diff --git a/dist/content/content.js b/dist/content/content.js index c06660f..1c1004b 100644 --- a/dist/content/content.js +++ b/dist/content/content.js @@ -1,16 +1,17 @@ -var i=(e=>(e.close="closeMeasureTool",e.open="openMeasureTool",e))(i||{});const a={height:"333px",width:"300px"},h="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAjJJREFUaEPtmd1VAjEQhTN0IFoAPkAdWInyKBShFiE+qpVgHfDgFqBbAvEE3J8smfxMZtA9Z3mE3eR+2eTOnQVUzz/Qc/1KDODqZTffa/16WCAN7+Vq+iixWCIAR/Fq0wjWhRQEO8Cp+ApDBoIVABcvB8EGEBYvA8ECEC+eHyIbIF18AwFaPX2vZm857pQNMF5vP5WCSVvECNSN7UJKgdYLDXC01fqji3I5u/5XAEb81/30Y7ze6bawcjmFy+ftXRfCfP+nAI0oXYwAFka8EeQCMN9j11Mhsuh9k2IAVKHYfQMAtjLDE4jca8Et1Pi8LlJ8m/oE2vPFBEAvgCtVxvo2FcCuK+EAiAJgFTbWt3kADs2EN4o7ATDxVZGK2Z5UAFex80GcAHCI9xWyGPgUCAuAS3wugF2x7ezUPdg1AD1Vxqwp5zW2G9YArlTJOS3vWE2KrQEu1rsNKDXnnUhqNAeA++BICcgbt+2G1iFOOf0hCVQbrcaNNZQTG+WCyAGIFW9gnYUMgzhvFrKfMVZE0SiBQZw3Cx0hfAnAG+ZyeljqFuraeSi+BOM0tYelAqTOFwQIuc3QkVFX6Pe+4Qn0fgthPSx2iKk9tth7IayHdQHk9NhnAmh6WAXqoT2p64Wv+T22xxYDQLNT5421S0CoSMUYFIsLUaI4h3g0zMWQd69JgeASzwpgBouB4BTPDhCC4BYvAoBBSIgXA6gg9gC3oPSk/c8N5Xz57mFxIW5RKeP1HuAHwGT8QByJd+kAAAAASUVORK5CYII=",n="inject-D"+Date.now().toString(),p=` +var i=(t=>(t.close="closeMeasureTool",t.open="openMeasureTool",t))(i||{});const g={height:"333px",width:"300px"},u="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAjJJREFUaEPtmd1VAjEQhTN0IFoAPkAdWInyKBShFiE+qpVgHfDgFqBbAvEE3J8smfxMZtA9Z3mE3eR+2eTOnQVUzz/Qc/1KDODqZTffa/16WCAN7+Vq+iixWCIAR/Fq0wjWhRQEO8Cp+ApDBoIVABcvB8EGEBYvA8ECEC+eHyIbIF18AwFaPX2vZm857pQNMF5vP5WCSVvECNSN7UJKgdYLDXC01fqji3I5u/5XAEb81/30Y7ze6bawcjmFy+ftXRfCfP+nAI0oXYwAFka8EeQCMN9j11Mhsuh9k2IAVKHYfQMAtjLDE4jca8Et1Pi8LlJ8m/oE2vPFBEAvgCtVxvo2FcCuK+EAiAJgFTbWt3kADs2EN4o7ATDxVZGK2Z5UAFex80GcAHCI9xWyGPgUCAuAS3wugF2x7ezUPdg1AD1Vxqwp5zW2G9YArlTJOS3vWE2KrQEu1rsNKDXnnUhqNAeA++BICcgbt+2G1iFOOf0hCVQbrcaNNZQTG+WCyAGIFW9gnYUMgzhvFrKfMVZE0SiBQZw3Cx0hfAnAG+ZyeljqFuraeSi+BOM0tYelAqTOFwQIuc3QkVFX6Pe+4Qn0fgthPSx2iKk9tth7IayHdQHk9NhnAmh6WAXqoT2p64Wv+T22xxYDQLNT5421S0CoSMUYFIsLUaI4h3g0zMWQd69JgeASzwpgBouB4BTPDhCC4BYvAoBBSIgXA6gg9gC3oPSk/c8N5Xz57mFxIW5RKeP1HuAHwGT8QByJd+kAAAAASUVORK5CYII=";class p{constructor(e,a){this.iFrame=null,this.targetOrigin="",this.iFrame=e,this.targetOrigin=a,window.addEventListener("message",this.handle,!1)}send(e){this.targetOrigin?this.iFrame.postMessage(e,this.targetOrigin):this.iFrame.postMessage(e,"*")}handle(e){e.data.source!="react-devtools-content-script"&&console.log(e)}destroy(){window.removeEventListener("message",this.handle,!1)}}const n="inject-D"+Date.now().toString(),f=` .${n}{ outline: 1px solid red; } -`;let c=null,d=!1,s=null,A=null,r=!1;const m=e=>{if(d&&s&&(s.style.top=e.clientY+"px",s.style.left=e.clientX+"px"),r)return;let t=document.elementFromPoint(e.clientX,e.clientY);t&&(t.tagName==="IFRAME"||t.id===n||t.id===n+"-")||t!==c&&(c&&c.classList.remove(n),c=t,t&&t.classList.add(n),A=t)},u=e=>{(window.event?e.keyCode:e.which)===81&&(r=!r,r||(A=null),console.log(A))},E=e=>{i.open?window.addEventListener("mousemove",m):i.close&&window.removeEventListener("mousemove",m)},f=e=>{if(e==i.open){window.document.body.addEventListener("keydown",u);const t=document.querySelector(n)||window.document.createElement("style");t.className=n,t.innerHTML=p,window.document.head.appendChild(t)}else if(e==i.close){window.document.body.removeEventListener("keydown",u);const t=document.querySelector("."+n);t&&t.remove()}},w=e=>{if(e==i.open){const t=document.querySelector("#"+n)||document.createElement("iframe");t.id=n,t.style.cssText=`width: ${a.width}; - height: ${a.height}; +`;let A,l=null,r=!1,d=null,c=!1;const m=t=>{if(r&&d&&(d.style.top=t.clientY+"px",d.style.left=t.clientX+"px"),c)return;let e=document.elementFromPoint(t.clientX,t.clientY);e&&(e.tagName==="IFRAME"||e.id===n||e.id===n+"-")||e!==l&&(l&&l.classList.remove(n),l=e,e&&e.classList.add(n))},h=t=>{(window.event?t.keyCode:t.which)===81&&(c=!c,c&&A.send("hello"))},E=t=>{i.open?window.addEventListener("mousemove",m):i.close&&window.removeEventListener("mousemove",m)},w=t=>{if(t==i.open){window.document.body.addEventListener("keydown",h);const e=document.querySelector(n)||window.document.createElement("style");e.className=n,e.innerHTML=f,window.document.head.appendChild(e)}else if(t==i.close){window.document.body.removeEventListener("keydown",h);const e=document.querySelector("."+n);e&&e.remove()}},C=t=>{if(t==i.open){const e=document.querySelector("#"+n)||document.createElement("iframe");e.id=n,e.style.cssText=`width: ${g.width}; + height: ${g.height}; border: none; - `;const g=chrome.runtime.getURL("contentPage/index.html");t.src=g;let l=document.createElement("div");l.id=n,l.style.cssText=`position: fixed; + `;const a=chrome.runtime.getURL("contentPage/index.html");e.src=a;let s=document.createElement("div");s.id=n,s.style.cssText=`position: fixed; z-index: 1000000; top: 10px; left: 10px; - padding: 10px;`;let o=document.createElement("img");o.src=h,o.id=n+"-",o.style.cssText=`width: 20px; + padding: 10px;`;let o=document.createElement("img");o.src=u,o.id=n+"-",o.style.cssText=`width: 20px; height: 20px; position: absolute; top: 0px; - left: 0px;`,l.appendChild(o),l.appendChild(t),document.body.appendChild(l),s=l,o.onclick=()=>{d=!d,d?o.style.cursor="grabbing":o.style.cursor="grab"}}else e==i.close&&document.querySelector(`#${n}`)&&document.querySelector(`#${n}`).remove()};chrome.runtime.onMessage.addListener(e=>{f(e.info),E(e.info),w(e.info)}); + left: 0px; + cursor: grab;`,s.appendChild(o),s.appendChild(e),document.body.appendChild(s),d=s,o.onclick=()=>{r=!r,r?o.style.cursor="grabbing":o.style.cursor="grab"},A=new p(e.contentWindow),A.send("hello")}else t==i.close&&document.querySelector(`#${n}`)&&document.querySelector(`#${n}`).remove()};chrome.runtime.onMessage.addListener(t=>{w(t.info),E(t.info),C(t.info)}); diff --git a/dist/contentPage/contentPage.js b/dist/contentPage/contentPage.js index 845fa68..4ff8ac0 100644 --- a/dist/contentPage/contentPage.js +++ b/dist/contentPage/contentPage.js @@ -1 +1 @@ -import{j as e,c as r}from"../js/client-Gw-UosAD.js";function n(){return e.jsx(e.Fragment,{children:e.jsx("div",{children:e.jsx("div",{id:"app",children:e.jsx("div",{children:"当前元素信息"})})})})}r.createRoot(document.getElementById("root")).render(e.jsx(n,{})); +import{r as t,j as e,c as r}from"../js/client-B7nMxStY.js";function n(){return t.useEffect(()=>{window.addEventListener("message",s=>{console.log(s),top==null||top.postMessage("ok","*")},!1)}),e.jsx(e.Fragment,{children:e.jsx("div",{children:e.jsx("div",{id:"app",children:e.jsx("div",{children:"当前元素信息"})})})})}r.createRoot(document.getElementById("root")).render(e.jsx(n,{})); diff --git a/dist/contentPage/index.html b/dist/contentPage/index.html index 09b78d6..aa033aa 100644 --- a/dist/contentPage/index.html +++ b/dist/contentPage/index.html @@ -6,10 +6,11 @@