-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
81 lines (75 loc) · 4.22 KB
/
Copy pathpopup.js
File metadata and controls
81 lines (75 loc) · 4.22 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 弹出窗口的脚本
document.addEventListener('DOMContentLoaded', function() {
// 获取当前标签页信息
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const currentTab = tabs[0];
// 检查当前页面是否是bilibili网站
if (currentTab.url && currentTab.url.includes('bilibili.com')) {
document.querySelector('.status').innerHTML = '插件已启用<br>当前页面: bilibili';
document.querySelector('.status').style.backgroundColor = '#e8f5e9';
document.querySelector('.status').style.color = '#2e7d32';
// 向content脚本发送消息,请求检查点赞按钮
chrome.tabs.sendMessage(currentTab.id, {action: "checkLikeButton"}, function(response) {
// 检查是否有错误发生
if (chrome.runtime.lastError) {
console.log('通信错误:', chrome.runtime.lastError.message);
// 创建状态显示区域
let buttonStatus = document.querySelector('.button-status');
if (!buttonStatus) {
buttonStatus = document.createElement('div');
buttonStatus.className = 'button-status';
buttonStatus.style.margin = '10px 0';
buttonStatus.style.padding = '8px';
buttonStatus.style.borderRadius = '4px';
buttonStatus.style.backgroundColor = '#ffebee';
buttonStatus.style.color = '#c62828';
document.querySelector('.container').insertBefore(buttonStatus, document.querySelector('.footer'));
}
// 显示错误信息
buttonStatus.innerHTML = '无法与页面通信<br>可能原因: 页面刚刚加载或刷新<br>请重新打开弹窗或刷新页面';
return;
}
// 创建按钮状态显示区域(如果尚不存在)
let buttonStatus = document.querySelector('.button-status');
if (!buttonStatus) {
buttonStatus = document.createElement('div');
buttonStatus.className = 'button-status';
buttonStatus.style.margin = '10px 0';
buttonStatus.style.padding = '8px';
buttonStatus.style.borderRadius = '4px';
buttonStatus.style.backgroundColor = '#e3f2fd';
buttonStatus.style.color = '#1565c0';
document.querySelector('.container').insertBefore(buttonStatus, document.querySelector('.footer'));
}
// 根据响应显示点赞按钮状态
if (response && response.found) {
// 检查是否有点赞失败的情况
if (response.likeFailure && response.likeFailure.failed) {
buttonStatus.innerHTML = '发现点赞按钮 [' + response.buttonType + ']<br>颜色: ' + response.hexColor +
'<br>状态: <span style="color:#e53935;font-weight:bold;">点赞操作失败</span>' +
'<br>原因: ' + response.likeFailure.reason +
'<br>建议: 请尝试手动点赞';
buttonStatus.style.backgroundColor = '#ffebee';
buttonStatus.style.color = '#c62828';
} else if (response.needsLike) {
buttonStatus.innerHTML = '发现点赞按钮 [' + response.buttonType + ']<br>颜色: ' + response.hexColor + '<br>状态: 未点赞,插件将自动点赞';
buttonStatus.style.backgroundColor = '#fff8e1';
buttonStatus.style.color = '#ff8f00';
} else {
buttonStatus.innerHTML = '发现点赞按钮 [' + response.buttonType + ']<br>颜色: ' + response.hexColor + '<br>状态: 已点赞或无需点赞';
buttonStatus.style.backgroundColor = '#e8f5e9';
buttonStatus.style.color = '#2e7d32';
}
} else {
buttonStatus.innerHTML = '未发现点赞按钮<br>可能原因: 页面尚未完全加载或非视频页面';
buttonStatus.style.backgroundColor = '#ffebee';
buttonStatus.style.color = '#c62828';
}
});
} else {
document.querySelector('.status').innerHTML = '当前页面不是bilibili<br>插件仅在bilibili.com生效';
document.querySelector('.status').style.backgroundColor = '#ffebee';
document.querySelector('.status').style.color = '#c62828';
}
});
});