-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontent.js
More file actions
53 lines (47 loc) · 1.43 KB
/
Copy pathcontent.js
File metadata and controls
53 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ProxyMaster Content Script
(function() {
'use strict';
// 页面加载完成后执行
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
function init() {
// 监听来自background的消息
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'getPageInfo') {
sendResponse({
url: window.location.href,
title: document.title,
hostname: window.location.hostname
});
}
});
// 检测页面加载性能
if (window.performance && window.performance.timing) {
const timing = window.performance.timing;
const loadTime = timing.loadEventEnd - timing.navigationStart;
// 发送性能数据到background
chrome.runtime.sendMessage({
action: 'reportPerformance',
data: {
url: window.location.href,
loadTime: loadTime,
timestamp: Date.now()
}
});
}
}
// 注入页面脚本(如果需要)
function injectScript() {
const script = document.createElement('script');
script.src = chrome.runtime.getURL('inject.js');
script.onload = function() {
this.remove();
};
(document.head || document.documentElement).appendChild(script);
}
// 如果需要访问页面的JavaScript环境,可以调用injectScript()
// injectScript();
})();