Skip to content

Commit 9da1808

Browse files
committed
Remove all console.log statements from the codebase to clean up the output and adhere to best practices. Added a guideline in agent.mdc to avoid using console.log in the future.
1 parent b7aa028 commit 9da1808

File tree

12 files changed

+9
-131
lines changed

12 files changed

+9
-131
lines changed

.cursor/rules/agent.mdc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ alwaysApply: true
66
- 不要自动书写 README.md 文件
77
- 尽量使用 for 循环, 尽量不实用 forEach
88
- 在 Typescript 中, 不要使用 any, 尽量推导出来类型
9+
- 不要输出任何 console.log 语句

chrome-extension/src/background/index.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
import 'webextension-polyfill';
22
import { startListenTabs } from './tabs';
33
import { ignoreHref } from '@extension/shared';
4-
import { exampleThemeStorage, translationModeStorage, contentUIStateStorage } from '@extension/storage';
5-
import type { AllMessage, QueryResponse, State, ElementPosition } from '@extension/shared';
6-
7-
console.log('Background loaded');
8-
console.log("Edit 'chrome-extension/src/background/index.ts' and save to reload.");
9-
10-
exampleThemeStorage.get().then(theme => {
11-
console.log('theme', theme);
12-
});
13-
14-
translationModeStorage.get().then(mode => {
15-
console.log('mode', mode);
16-
});
4+
import { contentUIStateStorage } from '@extension/storage';
5+
import type { AllMessage, QueryResponse, State } from '@extension/shared';
176

187
const WS_PORT = 52346;
198
const WS_URL = `ws://localhost:${WS_PORT}/ws`;
@@ -38,9 +27,7 @@ const state: State = {
3827
// 从 storage 中恢复状态
3928
const initializeStateFromStorage = async () => {
4029
try {
41-
console.log('background: 从 storage 中恢复状态');
4230
const storedState = await contentUIStateStorage.get();
43-
console.log('background: 恢复的状态', storedState);
4431

4532
// 更新状态,但保持 running 状态为 false(需要 WebSocket 连接)
4633
state.interactionMode = storedState.interactionMode;
@@ -49,10 +36,8 @@ const initializeStateFromStorage = async () => {
4936
state.showBBox = storedState.showBBox;
5037
state.ignored = storedState.ignored;
5138
state.running = false; // 初始时设为 false,等 WebSocket 连接成功后再设为 true
52-
53-
console.log('background: 状态已恢复', state);
54-
} catch (error) {
55-
console.error('background: 恢复状态失败', error);
39+
} catch (e) {
40+
console.error(e);
5641
}
5742
};
5843

@@ -99,7 +84,6 @@ const listenMessageForUI = (
9984
return true;
10085
}
10186
case 'GetState': {
102-
console.log('Background.Send: GetStateResponse', state);
10387
sendResponse({
10488
func: 'GetStateResponse',
10589
...state,
@@ -109,7 +93,6 @@ const listenMessageForUI = (
10993
}
11094
case 'SetState': {
11195
const { interactionMode, demoMode, inspecting, showBBox } = message;
112-
console.log('background: 收到 SetState', { interactionMode, demoMode, inspecting, showBBox });
11396

11497
state.interactionMode = interactionMode;
11598
state.demoMode = demoMode;
@@ -150,7 +133,7 @@ const listenMessageForUI = (
150133
body: { positions, tabId: actualTabId },
151134
});
152135
} catch (e) {
153-
console.warn('background: 转发位置同步消息失败', e);
136+
console.error(e);
154137
}
155138
}
156139

@@ -186,15 +169,13 @@ const connectWebSocket = () => {
186169
return;
187170
}
188171

189-
console.log('🔌 尝试连接 WebSocket...');
190172
isConnecting = true;
191173
let success = false;
192174

193175
try {
194176
ws = new WebSocket(WS_URL);
195177

196178
ws.onopen = () => {
197-
console.log('✅ WebSocket 已连接');
198179
isConnecting = false;
199180
ws?.send(JSON.stringify({ type: 'ping' }));
200181
state.running = true;

packages/storage/lib/impl/content-ui-state-storage.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ export const contentUIStateStorage: ContentUIStorageType = {
3939
const nextIndex = (currentIndex + 1) % modes.length;
4040
const newMode = modes[nextIndex];
4141

42-
console.log('storage: 切换交互模式', { from: currentState.interactionMode, to: newMode });
43-
4442
// Update local state
4543
await storage.set(prev => ({
4644
...prev,
@@ -67,8 +65,6 @@ export const contentUIStateStorage: ContentUIStorageType = {
6765
const currentState = await storage.get();
6866
const newDemoMode = !currentState.demoMode;
6967

70-
console.log('storage: 切换演示模式', { from: currentState.demoMode, to: newDemoMode });
71-
7268
// Update local state
7369
await storage.set(prev => ({
7470
...prev,
@@ -95,8 +91,6 @@ export const contentUIStateStorage: ContentUIStorageType = {
9591
const currentState = await storage.get();
9692
const newInspecting = !currentState.inspecting;
9793

98-
console.log('storage: 切换诊断模式', { from: currentState.inspecting, to: newInspecting });
99-
10094
// Update local state
10195
await storage.set(prev => ({
10296
...prev,
@@ -122,8 +116,6 @@ export const contentUIStateStorage: ContentUIStorageType = {
122116
const currentState = await storage.get();
123117
const newShowBBox = !currentState.showBBox;
124118

125-
console.log('storage: 切换HUD诊断模式', { from: currentState.showBBox, to: newShowBBox });
126-
127119
// Update local state
128120
await storage.set(prev => ({
129121
...prev,
@@ -146,7 +138,6 @@ export const contentUIStateStorage: ContentUIStorageType = {
146138

147139
updateGlobalState: async globalState => {
148140
try {
149-
console.log('storage: 更新全局状态', globalState);
150141
await storage.set(prev => ({
151142
...prev,
152143
...globalState,

pages/content-ui/src/components/BBox.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ import type { FC } from 'react';
66
export const BBox: FC<{
77
style?: React.CSSProperties;
88
}> = ({ style }) => {
9-
const { showBBox, toggleBBox, debug } = useContentUIState();
10-
11-
// 调试信息
12-
console.log('BBox: 状态', { showBBox, debug });
9+
const { showBBox, toggleBBox } = useContentUIState();
1310

1411
const handleClick = () => {
15-
console.log('BBox: 点击事件触发', { currentState: showBBox });
1612
toggleBBox();
1713
};
1814

pages/content-ui/src/components/BBoxRenderer.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,9 @@ export const BBoxRenderer: React.FC<BBoxRendererProps> = ({ enabled }) => {
5959
(event: CustomEvent) => {
6060
const { positions: newPositions } = event.detail;
6161

62-
// 调试信息
63-
console.log('BBoxRenderer: 收到位置同步', {
64-
enabled,
65-
count: newPositions.length,
66-
positions: newPositions.slice(0, 3), // 只显示前3个
67-
});
68-
6962
// 性能优化:只在位置真正变化时更新状态
7063
setPositions(prevPositions => {
7164
if (prevPositions.length !== newPositions.length) {
72-
console.log('BBoxRenderer: 位置数量变化', { from: prevPositions.length, to: newPositions.length });
7365
return newPositions;
7466
}
7567

@@ -86,7 +78,6 @@ export const BBoxRenderer: React.FC<BBoxRendererProps> = ({ enabled }) => {
8678
newPos.rect.width !== prevPos.rect.width ||
8779
newPos.rect.height !== prevPos.rect.height
8880
) {
89-
console.log('BBoxRenderer: 位置内容变化', { index: i, newPos, prevPos });
9081
return newPositions;
9182
}
9283
}
@@ -98,8 +89,6 @@ export const BBoxRenderer: React.FC<BBoxRendererProps> = ({ enabled }) => {
9889
);
9990

10091
useEffect(() => {
101-
console.log('BBoxRenderer: useEffect', { enabled, positionsCount: positions.length });
102-
10392
if (!enabled) {
10493
setPositions([]);
10594
return;
@@ -114,13 +103,7 @@ export const BBoxRenderer: React.FC<BBoxRendererProps> = ({ enabled }) => {
114103
};
115104
}, [enabled, handlePositionSync]);
116105

117-
// 调试信息
118-
console.log('BBoxRenderer: 渲染状态', { enabled, positionsCount: positions.length, positions });
119-
120-
if (!enabled || positions.length === 0) {
121-
console.log('BBoxRenderer: 不渲染', { enabled, positionsCount: positions.length });
122-
return null;
123-
}
106+
if (!enabled || positions.length === 0) return null;
124107

125108
return (
126109
<>

pages/content-ui/src/hooks/useContentUIState.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export const useContentUIState = () => {
1515
const handleStateChanged = (event: CustomEvent) => {
1616
try {
1717
const { running, interactionMode, demoMode, inspecting, showBBox } = event.detail;
18-
console.log('content-ui: 收到状态更新', { running, interactionMode, demoMode, inspecting, showBBox });
1918

2019
// 只更新从 background 传来的状态,保持本地状态不变
2120
contentUIStateStorage.updateGlobalState({
@@ -42,7 +41,6 @@ export const useContentUIState = () => {
4241
useEffect(() => {
4342
const initializeState = async () => {
4443
try {
45-
console.log('content-ui: 初始化状态');
4644
chrome.runtime.sendMessage({ func: 'GetState' });
4745
} catch (error) {
4846
console.error('Error sending GetState message:', error);
@@ -76,31 +74,27 @@ export const useContentUIState = () => {
7674
// 全局操作方法
7775
toggleInteractionMode: () => {
7876
try {
79-
console.log('content-ui: 切换交互模式');
8077
contentUIStateStorage.toggleInteractionMode();
8178
} catch (error) {
8279
console.error('Error toggling interaction mode:', error);
8380
}
8481
},
8582
toggleDemoMode: () => {
8683
try {
87-
console.log('content-ui: 切换演示模式');
8884
contentUIStateStorage.toggleDemoMode();
8985
} catch (error) {
9086
console.error('Error toggling demo mode:', error);
9187
}
9288
},
9389
toggleDiagnoseMode: () => {
9490
try {
95-
console.log('content-ui: 切换诊断模式');
9691
contentUIStateStorage.toggleDiagnoseMode();
9792
} catch (error) {
9893
console.error('Error toggling diagnose mode:', error);
9994
}
10095
},
10196
toggleBBox: () => {
10297
try {
103-
console.log('content-ui: 切换HUD诊断模式', { currentState: globalState.showBBox });
10498
contentUIStateStorage.toggleBBox();
10599
} catch (error) {
106100
console.error('Error toggling HUD diagnose mode:', error);

pages/content-ui/src/matches/all/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default function App() {
1717
const { showBBox } = useStorage(contentUIStateStorage);
1818

1919
// 调试信息
20-
console.log('App: showBBox状态', { showBBox });
2120

2221
const [highlighterStyle, setHighlighterStyle] = useState<HighlighterStyle>({
2322
display: 'none',

pages/content-ui/src/startListen.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ const onMessage = (
66
sender: chrome.runtime.MessageSender,
77
sendResponse: (response?: any) => void,
88
) => {
9-
console.log('content-ui: 收到消息', message.func);
10-
119
const { func } = message;
1210
switch (func) {
1311
case 'GetStateResponse':
1412
case 'OnStateChanged': {
15-
console.log('content-ui: 状态变化', message);
1613
document.dispatchEvent(new CustomEvent(rwkvEvent.stateChanged, { detail: message }));
1714
break;
1815
}
@@ -29,7 +26,6 @@ const onMessage = (
2926
break;
3027
}
3128
case 'PositionSync': {
32-
console.log('content-ui: 收到位置同步消息', message.body);
3329
// 触发自定义事件,让UI组件处理
3430
document.dispatchEvent(new CustomEvent('ceb-position-sync', { detail: message.body }));
3531
break;
@@ -41,18 +37,15 @@ const onMessage = (
4137
};
4238

4339
const stopListen = () => {
44-
console.log('content-ui: 停止监听消息');
4540
chrome.runtime.onMessage.removeListener(onMessage);
4641
};
4742

4843
export const startListen = () => {
4944
stopListen();
50-
console.log('content-ui: 开始监听消息');
5145
chrome.runtime.onMessage.addListener(onMessage);
5246

5347
// 延迟发送 GetState 消息,确保 background script 已准备就绪
5448
setTimeout(() => {
55-
console.log('content-ui: 发送 GetState 消息');
5649
try {
5750
chrome.runtime.sendMessage({ func: 'GetState' });
5851
} catch (error) {

pages/content/src/contentStart.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ export const contentStart = () => {
1919
state.inspecting = inspecting;
2020
const showBBoxChanged = state.showBBox !== showBBox;
2121
state.showBBox = showBBox;
22-
console.log(`${rwkvEvent.stateChanged}: content`, state);
2322

2423
if (inspectingChanged) {
25-
console.log('inspectingChanged', inspecting);
2624
document.body.querySelectorAll(`.${rwkvClass.target}`).forEach(node => {
2725
if (inspecting && !node.classList.contains(rwkvClass.inspect)) {
2826
node.classList.add(rwkvClass.inspect);
@@ -67,7 +65,6 @@ export const contentStart = () => {
6765

6866
// 测试:3秒后发送一个测试位置
6967
setTimeout(() => {
70-
console.log('发送测试位置...');
7168
createTestPosition();
7269
}, 3000);
7370
}
@@ -76,13 +73,11 @@ export const contentStart = () => {
7673
// 处理 HUD 诊断模式状态变化
7774
if (showBBoxChanged) {
7875
if (showBBox) {
79-
console.log('HUD 诊断模式已开启');
8076
// 如果 WebSocket 已连接,启动位置监听
8177
if (state.running) {
8278
startPositionMonitoring();
8379
}
8480
} else {
85-
console.log('HUD 诊断模式已关闭');
8681
// 停止位置监听
8782
stopPositionMonitoring();
8883
}
@@ -95,13 +90,10 @@ export const contentStart = () => {
9590
sender: chrome.runtime.MessageSender,
9691
sendResponse: (response?: any) => void,
9792
) => {
98-
console.log('content: 收到消息', message.func);
99-
10093
const { func } = message;
10194
switch (func) {
10295
case 'GetStateResponse':
10396
case 'OnStateChanged': {
104-
console.log('content: 收到状态更新', message);
10597
// 触发自定义事件,让现有的监听器处理
10698
document.dispatchEvent(new CustomEvent(rwkvEvent.stateChanged, { detail: message }));
10799
break;
@@ -125,7 +117,6 @@ export const contentStart = () => {
125117

126118
// 初始化时请求状态
127119
setTimeout(() => {
128-
console.log('content: 请求初始状态');
129120
try {
130121
chrome.runtime.sendMessage({ func: 'GetState' });
131122
} catch (error) {
@@ -173,7 +164,6 @@ export const contentStart = () => {
173164

174165
const initializeHoverListener = () => {
175166
document.addEventListener('mouseover', handleMouseOver);
176-
console.log('Hover listener initialized (event dispatch only).');
177167
};
178168

179169
// Initialize the hover listener
@@ -198,7 +188,6 @@ export const contentStart = () => {
198188
const initializeKeyListeners = () => {
199189
document.addEventListener('keydown', handleKeyDown);
200190
document.addEventListener('keyup', handleKeyUp);
201-
console.log('Key listeners initialized.');
202191
};
203192

204193
// Initialize the key listener

0 commit comments

Comments
 (0)