Jarvis-Brain 0.1.13.7__tar.gz → 0.1.13.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Jarvis_Brain
3
- Version: 0.1.13.7
3
+ Version: 0.1.13.8
4
4
  Summary: Jarvis brain mcp
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: beautifulsoup4
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "Jarvis_Brain" # 别人下载时用的名字,必须在 PyPI 上唯一
3
- version = "0.1.13.7"
3
+ version = "0.1.13.8"
4
4
  description = "Jarvis brain mcp"
5
5
  dependencies = [
6
6
  "fastmcp",
@@ -105,6 +105,9 @@ return getSimplifiedDOM(document.body);
105
105
  # 我自己优化后的版本,逻辑为:删除不可见元素、标签的任何属性value的长度大于20时直接删除这个属性、id和class采用简写方式:id=>#,class=>.
106
106
  compress_html_js="""
107
107
  function getSimplifiedDOM(node) {
108
+ // 全局配置:最大属性值长度
109
+ const MAX_ATTR_LEN = 40;
110
+
108
111
  // 1. 处理文本节点
109
112
  if (node.nodeType === Node.TEXT_NODE) {
110
113
  const text = node.textContent.trim();
@@ -112,7 +115,6 @@ function getSimplifiedDOM(node) {
112
115
  }
113
116
 
114
117
  // 2. 过滤无用标签
115
- // 注意:保留了 SVG 标签以便进入内部处理 path
116
118
  const ignoreTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'IFRAME', 'LINK', 'META', 'AUDIO', 'VIDEO', 'CANVAS'];
117
119
  if (ignoreTags.includes(node.tagName)) return null;
118
120
  if (node.nodeType !== Node.ELEMENT_NODE) return null;
@@ -128,20 +130,18 @@ function getSimplifiedDOM(node) {
128
130
  const tagName = node.tagName.toLowerCase();
129
131
  let tagStr = tagName;
130
132
 
131
- // 获取 ID 和 Class,用于简写逻辑
132
133
  const id = node.id;
133
- // SVG 元素的 className 是对象,需用 getAttribute 安全获取
134
134
  const className = node.getAttribute('class');
135
135
 
136
136
  // A. 处理 ID 简写 (#id)
137
- // 规则应用:如果 ID 值长度 > 20,也视为过长属性,直接丢弃,不显示在简写中
138
- if (id && id.length <= 20) {
137
+ // 限制提高到 40
138
+ if (id && id.length <= MAX_ATTR_LEN) {
139
139
  tagStr += `#${id}`;
140
140
  }
141
141
 
142
142
  // B. 处理 Class 简写 (.class)
143
- // 规则应用:如果 Class 值长度 > 20,直接丢弃
144
- if (className && typeof className === 'string' && className.length <= 20) {
143
+ // 限制提高到 40
144
+ if (className && typeof className === 'string' && className.length <= MAX_ATTR_LEN) {
145
145
  const classes = className.trim().split(/\s+/);
146
146
  if (classes.length > 0) {
147
147
  tagStr += `.${classes.join('.')}`;
@@ -150,28 +150,30 @@ function getSimplifiedDOM(node) {
150
150
 
151
151
  let propsStr = '';
152
152
 
153
- // C. 处理常规属性
153
+ // C. 处理属性
154
154
  if (node.hasAttributes()) {
155
155
  for (const attr of node.attributes) {
156
156
  const name = attr.name;
157
157
  const value = attr.value;
158
158
 
159
- // 1. 跳过 ID 和 Class(因为已经在上面 tagStr 处理过了)
160
- // 注意:即使因为过长在上面没显示,这里也不应该重复显示,遵循“过长即删除”原则
159
+ // 1. 跳过 ID 和 Class (已在 tagStr 处理,或因过长被丢弃)
161
160
  if (name === 'id' || name === 'class') continue;
162
161
 
163
- // 2. 黑名单过滤:直接删除 style 和 aria-label
162
+ // 2. 黑名单:直接删除 style 和 aria-label
164
163
  if (name === 'style' || name === 'aria-label') continue;
165
164
 
166
- // 3. 特殊标签处理:如果是 path 标签,删除所有属性
167
- // (continue 意味着直接跳过该属性的拼接,即 key 和 value 都不显示)
165
+ // 3. 特殊标签:path 标签删除所有属性
168
166
  if (tagName === 'path') continue;
169
167
 
170
- // 4. 【核心需求】通用长度限制
171
- // 如果属性值长度超过 20,直接删除该属性
172
- if (value.length > 20) continue;
168
+ // 4. 【长度与白名单逻辑】
169
+ // 如果不是 src 且不是 href,同时长度又超过了 40,则删除
170
+ const isLinkAttr = (name === 'src' || name === 'href');
171
+
172
+ if (!isLinkAttr && value.length > MAX_ATTR_LEN) {
173
+ continue;
174
+ }
173
175
 
174
- // 5. 保留属性
176
+ // 5. 拼接保留的属性
175
177
  propsStr += ` ${name}="${value.replace(/"/g, '&quot;')}"`;
176
178
  }
177
179
  }
File without changes