mirror of
https://github.com/SickleSec/SnowEyes.git
synced 2026-10-28 19:30:50 +00:00
91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
// 更新扩展图标的badge
|
|
function updateBadge(results) {
|
|
// 计算有内容的类别数量
|
|
const categories = [
|
|
results.domains,
|
|
results.absoluteApis,
|
|
results.apis,
|
|
results.moduleFiles,
|
|
results.docFiles,
|
|
results.ips,
|
|
results.phones,
|
|
results.emails,
|
|
results.idcards,
|
|
results.jwts,
|
|
results.awsKeys,
|
|
results.imageFiles,
|
|
results.jsFiles,
|
|
results.vueFiles,
|
|
results.urls,
|
|
results.githubUrls,
|
|
results.companies,
|
|
];
|
|
|
|
const nonEmptyCategories = categories.filter(category =>
|
|
Array.isArray(category) && category.length > 0
|
|
).length;
|
|
|
|
// 更新badge
|
|
chrome.action.setBadgeText({
|
|
text: nonEmptyCategories > 0 ? nonEmptyCategories.toString() : ''
|
|
});
|
|
|
|
// 根据是否有内容设置不同的颜色
|
|
chrome.action.setBadgeBackgroundColor({
|
|
color: nonEmptyCategories > 0 ? '#4dabf7' : '#666666'
|
|
});
|
|
}
|
|
|
|
// 处理跨域请求
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
if (request.type === 'FETCH_JS') {
|
|
// 使用 fetch API 获取文件内容
|
|
fetch(request.url, {
|
|
headers: {
|
|
'Accept': '*/*',
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
|
},
|
|
credentials: 'omit' // 不发送 cookies
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
return response.text();
|
|
})
|
|
.then(content => {
|
|
sendResponse({ content });
|
|
})
|
|
.catch(error => {
|
|
// 如果 fetch 失败,尝试使用 chrome.scripting.executeScript
|
|
if (sender.tab) {
|
|
chrome.scripting.executeScript({
|
|
target: { tabId: sender.tab.id },
|
|
function: (url) => {
|
|
return fetch(url, {
|
|
credentials: 'omit'
|
|
}).then(r => r.text());
|
|
},
|
|
args: [request.url]
|
|
})
|
|
.then(results => {
|
|
if (results[0]?.result) {
|
|
sendResponse({ content: results[0].result });
|
|
} else {
|
|
sendResponse({ content: null });
|
|
}
|
|
})
|
|
.catch(() => {
|
|
sendResponse({ content: null });
|
|
});
|
|
} else {
|
|
sendResponse({ content: null });
|
|
}
|
|
});
|
|
|
|
return true; // 保持消息通道打开
|
|
} else if (request.type === 'UPDATE_BADGE') {
|
|
// 处理badge更新请求
|
|
updateBadge(request.results);
|
|
}
|
|
});
|