Skip to content

Commit b13df92

Browse files
committed
fix: 修复部分页面 Google Analytics ID 未更新的问题\n\n- 修复了自动化脚本中的文件路径错误\n- 确保所有页面都使用新的 Google Analytics ID (G-6205QQM2F7)
1 parent 1098247 commit b13df92

13 files changed

+62
-99
lines changed

add_google_analytics.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const gaCode = `
1616

1717
// 查找所有需要处理的 HTML 文件
1818
const htmlFiles = [
19-
// 已经处理过的文件
20-
// 'index.html',
21-
// 'cases/index.html',
19+
// 主页和测试用例列表页
20+
'index.html',
21+
'cases/index.html',
2222

2323
// 测试用例文件
2424
'test-cases/execute-debugger-patterns/{}[\'constructor\'](\'debugger\')();.html',
@@ -37,21 +37,18 @@ const htmlFiles = [
3737
htmlFiles.forEach(filePath => {
3838
try {
3939
// 读取文件内容
40-
const fileContent = fs.readFileSync(filePath, 'utf8');
40+
let fileContent = fs.readFileSync(filePath, 'utf8');
4141

42-
// 检查是否已经包含 Google Analytics 代码
43-
if (fileContent.includes('G-6205QQM2F7')) {
44-
console.log(`文件 ${filePath} 已包含 Google Analytics 代码,跳过`);
45-
return;
46-
}
42+
// 删除旧的 Google Analytics 代码
43+
fileContent = fileContent.replace(/<!-- Google tag \(gtag\.js\) -->\s*<script async src="https:\/\/www\.googletagmanager\.com\/gtag\/js\?id=G-[A-Z0-9]+">\s*<\/script>\s*<script>\s*window\.dataLayer = window\.dataLayer \|\| \[\];\s*function gtag\(\){dataLayer\.push\(arguments\);}\s*gtag\('js', new Date\(\)\);\s*gtag\('config', '[^']+'\);\s*<\/script>/g, '');
4744

48-
// 在 </head> 标签前插入 Google Analytics 代码
49-
const updatedContent = fileContent.replace('<head>', '<head>' + gaCode);
45+
// 在 <head> 标签后插入新的 Google Analytics 代码
46+
fileContent = fileContent.replace('<head>', '<head>' + gaCode);
5047

5148
// 写回文件
52-
fs.writeFileSync(filePath, updatedContent, 'utf8');
49+
fs.writeFileSync(filePath, fileContent, 'utf8');
5350

54-
console.log(`成功添加 Google Analytics 代码到 ${filePath}`);
51+
console.log(`成功更新 Google Analytics 代码到 ${filePath}`);
5552
} catch (error) {
5653
console.error(`处理文件 ${filePath} 时出错:`, error.message);
5754
}

cases/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="zh-CN">
33
<head>
4-
<meta charset="UTF-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>测试用例列表 - JavaScript 调试绕过测试平台</title>
74
<!-- Google tag (gtag.js) -->
85
<script async src="https://www.googletagmanager.com/gtag/js?id=G-6205QQM2F7"></script>
96
<script>
@@ -13,6 +10,13 @@
1310

1411
gtag('config', 'G-6205QQM2F7');
1512
</script>
13+
14+
15+
16+
<meta charset="UTF-8">
17+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
18+
<title>测试用例列表 - JavaScript 调试绕过测试平台</title>
19+
1620
<link rel="stylesheet" href="../styles/main.css">
1721
<link rel="preconnect" href="https://fonts.googleapis.com">
1822
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="zh-CN">
33
<head>
4-
<meta charset="UTF-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>JavaScript 调试绕过测试平台</title>
74
<!-- Google tag (gtag.js) -->
85
<script async src="https://www.googletagmanager.com/gtag/js?id=G-6205QQM2F7"></script>
96
<script>
@@ -13,6 +10,13 @@
1310

1411
gtag('config', 'G-6205QQM2F7');
1512
</script>
13+
14+
15+
16+
<meta charset="UTF-8">
17+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
18+
<title>JavaScript 调试绕过测试平台</title>
19+
1620
<link rel="stylesheet" href="styles/main.css">
1721
<link rel="preconnect" href="https://fonts.googleapis.com">
1822
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

test-cases/execute-debugger-patterns/Function.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
gtag('config', 'G-6205QQM2F7');
1212
</script>
1313

14-
<!-- Google tag (gtag.js) -->
15-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QXG8EZ2W5B"></script>
16-
<script>
17-
window.dataLayer = window.dataLayer || [];
18-
function gtag(){dataLayer.push(arguments);}
19-
gtag('js', new Date());
14+
2015

21-
gtag('config', 'G-QXG8EZ2W5B');
22-
</script>
16+
17+
18+
2319

2420
<meta charset="UTF-8">
2521
<meta name="viewport" content="width=device-width, initial-scale=1.0">

test-cases/execute-debugger-patterns/[].constructor.constructor('debugger')().html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
gtag('config', 'G-6205QQM2F7');
1212
</script>
1313

14-
<!-- Google tag (gtag.js) -->
15-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QXG8EZ2W5B"></script>
16-
<script>
17-
window.dataLayer = window.dataLayer || [];
18-
function gtag(){dataLayer.push(arguments);}
19-
gtag('js', new Date());
14+
2015

21-
gtag('config', 'G-QXG8EZ2W5B');
22-
</script>
16+
17+
18+
2319

2420
<meta charset="UTF-8">
2521
<meta name="viewport" content="width=device-width, initial-scale=1.0">

test-cases/execute-debugger-patterns/eval.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
gtag('config', 'G-6205QQM2F7');
1212
</script>
1313

14-
<!-- Google tag (gtag.js) -->
15-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QXG8EZ2W5B"></script>
16-
<script>
17-
window.dataLayer = window.dataLayer || [];
18-
function gtag(){dataLayer.push(arguments);}
19-
gtag('js', new Date());
14+
2015

21-
gtag('config', 'G-QXG8EZ2W5B');
22-
</script>
16+
17+
18+
2319

2420
<meta charset="UTF-8">
2521
<meta name="viewport" content="width=device-width, initial-scale=1.0">

test-cases/execute-debugger-patterns/misc.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
gtag('config', 'G-6205QQM2F7');
1212
</script>
1313

14-
<!-- Google tag (gtag.js) -->
15-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QXG8EZ2W5B"></script>
16-
<script>
17-
window.dataLayer = window.dataLayer || [];
18-
function gtag(){dataLayer.push(arguments);}
19-
gtag('js', new Date());
14+
2015

21-
gtag('config', 'G-QXG8EZ2W5B');
22-
</script>
16+
17+
18+
2319

2420
<meta charset="UTF-8">
2521
<meta name="viewport" content="width=device-width, initial-scale=1.0">

test-cases/execute-debugger-patterns/setInterval-002.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
gtag('config', 'G-6205QQM2F7');
1212
</script>
1313

14-
<!-- Google tag (gtag.js) -->
15-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QXG8EZ2W5B"></script>
16-
<script>
17-
window.dataLayer = window.dataLayer || [];
18-
function gtag(){dataLayer.push(arguments);}
19-
gtag('js', new Date());
14+
2015

21-
gtag('config', 'G-QXG8EZ2W5B');
22-
</script>
16+
17+
18+
2319

2420
<meta charset="UTF-8">
2521
<meta name="viewport" content="width=device-width, initial-scale=1.0">

test-cases/execute-debugger-patterns/setInterval.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
gtag('config', 'G-6205QQM2F7');
1212
</script>
1313

14-
<!-- Google tag (gtag.js) -->
15-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QXG8EZ2W5B"></script>
16-
<script>
17-
window.dataLayer = window.dataLayer || [];
18-
function gtag(){dataLayer.push(arguments);}
19-
gtag('js', new Date());
14+
2015

21-
gtag('config', 'G-QXG8EZ2W5B');
22-
</script>
16+
17+
18+
2319

2420
<meta charset="UTF-8">
2521
<meta name="viewport" content="width=device-width, initial-scale=1.0">

test-cases/execute-debugger-patterns/{}['constructor']('debugger')());.html

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@
1111
gtag('config', 'G-6205QQM2F7');
1212
</script>
1313

14-
<!-- Google tag (gtag.js) -->
15-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QXG8EZ2W5B"></script>
16-
<script>
17-
window.dataLayer = window.dataLayer || [];
18-
function gtag(){dataLayer.push(arguments);}
19-
gtag('js', new Date());
14+
2015

21-
gtag('config', 'G-QXG8EZ2W5B');
22-
</script>
16+
2317

2418
<meta charset="UTF-8">
2519
<meta name="viewport" content="width=device-width, initial-scale=1.0">

0 commit comments

Comments
 (0)