소스 검색

Merge branch 'master' of http://787255.xyz:4003/ydm/chrome-plugin

杨东明 9 달 전
부모
커밋
b0790b226f
3개의 변경된 파일67개의 추가작업 그리고 1개의 파일을 삭제
  1. BIN
      111.png
  2. 40 0
      cdp.js
  3. 27 1
      lib/ast/astparser.js

BIN
111.png


+ 40 - 0
cdp.js

@@ -0,0 +1,40 @@
+const CDP = require('chrome-remote-interface');
+
+(async function () {
+    const client = await CDP();
+
+    const { Page, DOM, CSS } = client;
+
+    try {
+        await Page.enable();
+        await DOM.enable();
+        await CSS.enable();
+
+        await Page.navigate({ url: 'http://127.0.0.1:8889/test/testPage.html' });
+        await Page.loadEventFired();
+
+        const { root: { nodeId } } = await DOM.getDocument();
+
+        const { nodeId: elementId } = await DOM.querySelector({
+            nodeId,
+            selector: '#register'
+        });
+
+        if (!elementId) {
+            console.log('未找到匹配的元素');
+            return;
+        }
+
+        const { computedStyle } = await CSS.getComputedStyleForNode({ nodeId: elementId });
+        console.log('计算样式:', computedStyle);
+
+        computedStyle.forEach(style => {
+            console.log(`属性: ${style.name}, 值: ${style.value}`);
+        });
+
+    } catch (err) {
+        console.error('出现错误:', err);
+    } finally {
+        await client.close();
+    }
+})();

+ 27 - 1
lib/ast/astparser.js

@@ -1198,7 +1198,8 @@ $(a().b.c() + b);
         let arrowNode = curNode;
 
         let aryParent = arrowNode.parent;
-        if (ArrayisArray(aryParent)) aryParent = aryParent.parent;
+        //如果是数组,则继续取上级节点
+        if (Array.isArray(aryParent)) aryParent = aryParent.parent;
 
         if (aryParent?.type == AstNode.VariableDeclarator) {
             //let xx = ()=>{...}
@@ -2283,6 +2284,15 @@ class AstParserPlugin_Selector extends AstParserPlugin {
                         if (selectorParent.parent.arguments?.length == 1) {
                             if (selectorParent.parent.arguments[0].type == AstNode.ObjectExpression) {
                                 ret.kind = "修改样式";
+
+                                let props = [];
+                                for (let prop of selectorParent.parent.arguments[0].properties) {
+                                    props.push({
+                                        name: (prop.key.type == AstNode.Identifier) ? prop.key.name : prop.key.value,
+                                        defineNode: prop,
+                                    });
+                                }
+                                ret.kindDes = props;
                             }
                             else {
                                 ret.kind = "获取属性/元素";
@@ -2290,6 +2300,22 @@ class AstParserPlugin_Selector extends AstParserPlugin {
                         }
                         else {
                             ret.kind = "修改样式";
+
+                            let propName = "";
+
+                            if (selectorParent.parent.arguments[0].type == AstNode.Identifier) {
+                                propName = selectorParent.parent.arguments[0].name;
+                            }
+                            else {
+                                propName = selectorParent.parent.arguments[0].value;
+                            }
+
+                            ret.kindDes = [
+                                {
+                                    name: propName,
+                                    defineNode: selectorParent.parent.arguments[0],
+                                }
+                            ]
                         }
 
                         return ret;