-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (41 loc) · 1.48 KB
/
index.js
File metadata and controls
52 lines (41 loc) · 1.48 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
var cururl = null;
var css = null;
var port = null;
var reconnected = false;
function connectToBackground() {
port = chrome.runtime.connect({ name: "popup" });
// 监听断开连接事件
port.onDisconnect.addListener(() => {
console.info("Disconnected from background script. Reconnecting...");
// 尝试重新连接
reconnected = true;
setTimeout(connectToBackground, 10); // 等待 0.01 秒后重连
});
}
//Connect port
connectToBackground();
$(document).ready(function () {
$('#readpage').click(function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
curtab = tabs[0];
console.log(curtab);
port.postMessage({ 'type': 'Inject', 'content': curtab});
window.close();
});
});
$('#bookmarktree').click(function () {
const targetUrl = "details.html";
chrome.tabs.query({}, function (tabs) {
// 检查是否已经存在目标页面
const existingTab = tabs.find(tab => tab.url.includes(targetUrl));
if (existingTab) {
// 如果找到已有页面,则切换到该页面
chrome.tabs.update(existingTab.id, { active: true });
} else {
// 否则,创建新页面
chrome.tabs.create({ url: targetUrl });
}
window.close();
});
});
});